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

Client::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
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
}