Completed
Push — master ( 312fc5...9a0c85 )
by Stephen
02:13
created

Organisations::find()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 22
Code Lines 16

Duplication

Lines 5
Ratio 22.73 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 5
loc 22
rs 8.9197
cc 4
eloc 16
nc 6
nop 4
1
<?php
2
3
namespace StarCitizen\Organisations;
4
use StarCitizen\Base\StarCitizenAbstract;
5
use StarCitizen\Models\Organisation;
6
7
/**
8
 * Class Organisations
9
 *
10
 * @package StarCitizen\Orginisations;
11
 */
12
class Organisations extends StarCitizenAbstract
13
{
14
15
    const ORG = 'single_organization';
16
    const MEMBERS = 'members';
17
18
    /**
19
     * Model map
20
     */
21
    const MODELS = [
22
        Organisations::ORG => '\Organisation',
23
        Organisations::MEMBERS => '\Members'
24
    ];
25
26
    /**
27
     * @var string
28
     */
29
    protected static $system = "organizations";
30
31
    /**
32
     * @param $id
33
     * @param string $action
34
     * @param bool $cache
35
     * @param bool $raw
36
     *
37
     * @return bool|mixed
38
     */
39
    protected static function find($id, $action = Organisations::ORG, $cache = false, $raw = false)
40
    {
41
        $cache = ($cache === true)? "cache" : "live";
42
43
        $params = [
44
            'api_source' => $cache,
45
            'system' => self::$system,
46
            'action' => $action,
47
            'target_id' => $id,
48
            'expedite' => '0',
49
            'format' => 'json'
50
        ];
51
52
        $response = json_decode(self::$client->getResult($params)->getBody()->getContents(), true);
53 View Code Duplication
        if ($response['request_stats']['query_status'] == "success")
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54
            if ($raw === true)
55
                return $response;
56
            else
57
                return self::fillModel($action, $response['data']);
58
59
        return false;
60
    }
61
62
    /**
63
     * @param $id
64
     * @param bool $cache
65
     * @param bool $raw
66
     *
67
     * @return bool|Organisation
68
     */
69
    protected static function findOrg($id, $cache = false, $raw = false)
70
    {
71
        return static::find($id, Organisations::ORG, $cache, $raw);
72
    }
73
}