Completed
Push — master ( aea3df...abf6c4 )
by Brian
01:17
created

WordpressApi::stats()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Darkgoldblade01\Wordpress;
4
5
use Darkgoldblade01\Wordpress\Api\Core;
6
use Darkgoldblade01\Wordpress\Api\Plugin;
7
use Darkgoldblade01\Wordpress\Api\Secret;
8
use Darkgoldblade01\Wordpress\Api\Stats;
9
use Darkgoldblade01\Wordpress\Api\Theme;
10
use Darkgoldblade01\Wordpress\Api\Translation;
11
use GuzzleHttp\Client;
12
use GuzzleHttp\Exception\GuzzleException;
13
14
class WordpressApi
15
{
16
17
    /**
18
     * Base URI
19
     *
20
     * The base URI for the API.
21
     *
22
     * @var string
23
     */
24
    protected $base_uri = 'https://api.wordpress.org/';
25
26
    /**
27
     * @var Client
28
     */
29
    private $client;
30
31
    public function __construct() {
32
        $this->client = new Client([
33
            "base_uri" => $this->base_uri,
34
        ]);
35
    }
36
37
    /**
38
     * @return Core
39
     */
40
    public static function core(): Core
41
    {
42
        return new Core();
43
    }
44
45
    /**
46
     * @return Plugin
47
     */
48
    public static function plugin(): Plugin
49
    {
50
        return new Plugin();
51
    }
52
53
    /**
54
     * @return Secret
55
     */
56
    public static function secret(): Secret
57
    {
58
        return new Secret();
59
    }
60
61
    /**
62
     * @return Stats
63
     */
64
    public static function stats(): Stats
65
    {
66
        return new Stats();
67
    }
68
69
    /**
70
     * @return Theme
71
     */
72
    public static function theme(): Theme
73
    {
74
        return new Theme();
75
    }
76
77
    /**
78
     * @return Translation
79
     */
80
    public static function translation(): Translation
81
    {
82
        return new Translation();
83
    }
84
85
    /**
86
     * @param null $endpoint
87
     * @param bool $json_decode
88
     * @return mixed
89
     * @throws GuzzleException
90
     */
91
    protected function get($endpoint = null, $json_decode = true) {
92
        $response = $this->client->get($endpoint);
93
        if($json_decode) {
94
            return json_decode($response->getBody()->getContents(), true);
95
        } else {
96
            return $response->getBody()->getContents();
97
        }
98
    }
99
}
100