WordpressApi   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 8

Test Coverage

Coverage 57.14%

Importance

Changes 0
Metric Value
wmc 9
lcom 2
cbo 8
dl 0
loc 87
ccs 12
cts 21
cp 0.5714
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A secret() 0 4 1
A stats() 0 4 1
A theme() 0 4 1
A translation() 0 4 1
A get() 0 9 2
A core() 0 4 1
A plugin() 0 4 1
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
     * Base URI.
18
     *
19
     * The base URI for the API.
20
     *
21
     * @var string
22
     */
23
    protected $base_uri = 'https://api.wordpress.org/';
24
25
    /**
26
     * @var Client
27
     */
28
    private $client;
29
30 7
    public function __construct()
31
    {
32 7
        $this->client = new Client([
33 7
            'base_uri' => $this->base_uri,
34
        ]);
35 7
    }
36
37
    /**
38
     * @return Core
39
     */
40 3
    public static function core(): Core
41
    {
42 3
        return new Core();
43
    }
44
45
    /**
46
     * @return Plugin
47
     */
48 1
    public static function plugin(): Plugin
49
    {
50 1
        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 5
    protected function get($endpoint = null, $json_decode = true)
92
    {
93 5
        $response = $this->client->get($endpoint);
94 5
        if ($json_decode) {
95 5
            return json_decode($response->getBody()->getContents(), true);
96
        } else {
97
            return $response->getBody()->getContents();
98
        }
99
    }
100
}
101