JsonFileServiceAuth::loadFile()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is a part of nekland youtube api package
5
 *
6
 * (c) Nekland <[email protected]>
7
 *
8
 * For the full license, take a look to the LICENSE file
9
 * on the root directory of this project
10
 */
11
12
namespace Nekland\YoutubeApi\Http\Auth;
13
14
/**
15
 * Class JsonfileServiceAuth
16
 *
17
 * Options:
18
 *      json_file: the path to the json file given by Google
19
 */
20
final class JsonFileServiceAuth extends ServiceAuth
21
{
22
    /**
23
     * @var array
24
     */
25
    private $json;
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    protected function getIss()
31
    {
32
        $this->loadFile();
33
34
        return $this->json['client_email'];
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    protected function getPrivateKey()
41
    {
42
        $this->loadFile();
43
44
        return $this->json['private_key'];
45
46
    }
47
48
    /**
49
     * @return array
50
     * @throws \Nekland\YoutubeApi\Exception\MissingOptionException if the required option is not set.
51
     */
52
    private function loadFile()
53
    {
54
        if ($this->json) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->json of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
55
            return $this->json;
56
        }
57
58
        $json = file_get_contents($this->getOption('json_file'));
59
60
        return $this->json = json_decode($json, true);
0 ignored issues
show
Documentation Bug introduced by
It seems like json_decode($json, true) of type * is incompatible with the declared type array of property $json.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
61
    }
62
}
63