Completed
Push — master ( 073cc1...713384 )
by Gareth
13:53
created

Client   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 41
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setPagesUrl() 0 4 1
A getPagesUrl() 0 4 1
A lookupPage() 0 15 2
1
<?php
2
namespace GarethEllis\Tldr;
3
4
5
class Client
6
{
7
    protected $http;
8
9
    protected $pagesUrl = "https://api.github.com/repos/tldr-pages/tldr/contents/pages/index.json?ref=master";
10
11
    /**
12
     * Client constructor.
13
     * @param \GuzzleHttp\Client $http
14
     */
15
    public function __construct($http)
16
    {
17
        $this->http = $http;
18
    }
19
20
    public function setPagesUrl(string $url)
21
    {
22
        $this->pagesUrl = $url;
23
    }
24
25
    public function getPagesUrl()
26
    {
27
        return $this->pagesUrl;
28
    }
29
30
    public function lookupPage(string $page)
31
    {
32
        $response = $this->http->get($this->getPagesUrl());
33
        $contents = json_decode($response->getBody()->getContents(), true);
34
        $pages = base64_decode($contents["content"]);
35
        $json = json_decode($pages, true);
36
        $pages = $json["commands"];
37
        $pages = array_filter($pages, function ($foundPage) use ($page) {
38
            return $foundPage["name"] === $page;
39
        });
40
41
        foreach ($pages as $page) {
0 ignored issues
show
Unused Code introduced by
This foreach statement is empty and can be removed.

This check looks for foreach loops that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

Consider removing the loop.

Loading history...
42
43
        }
44
    }
45
}