GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Factory::getNamespace()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php namespace Rossedman\Teamwork;
2
3
use Rossedman\Teamwork\Contracts\RequestableInterface;
4
use Rossedman\Teamwork\Exceptions\ClassNotCreatedException;
5
6
class Factory {
7
8
    protected $client;
9
10
    /**
11
     * @param RequestableInterface $client
12
     */
13
    public function __construct(RequestableInterface $client)
14
    {
15
        $this->client = $client;
16
    }
17
18
    /**
19
     * @param $method
20
     * @param $parameters
21
     *
22
     * @return mixed
23
     * @throws ClassNotCreatedException
24
     */
25
    public function __call($method, $parameters)
26
    {
27
        $class = $this->getQualifiedName($method);
28
29
        $this->doesClassExist($class);
30
31
        if($this->paramIsId($parameters) == true)
32
        {
33
            return new $class($this->client, $parameters[0]);
34
        }
35
36
        return new $class($this->client);
37
    }
38
39
    /**
40
     * Get Namespace
41
     *
42
     * @return mixed
43
     */
44
    private function getNamespace()
45
    {
46
        $reflection = new \ReflectionClass($this);
47
48
        return $reflection->getNamespaceName();
49
    }
50
51
    /**
52
     * Get Fully Qualified Name
53
     *
54
     * build and return fully qualified name
55
     * for class to instantiate
56
     *
57
     * @param $method
58
     *
59
     * @return string
60
     */
61
    protected function getQualifiedName($method)
62
    {
63
        return $this->getNamespace().'\\'.ucfirst($method);
64
    }
65
66
    /**
67
     * Parameter Has ID
68
     *
69
     * is there a parameter being passed in, and is it
70
     * an integer?
71
     *
72
     * @param $parameters
73
     *
74
     * @return bool
75
     */
76
    protected function paramIsId($parameters)
77
    {
78
        if($parameters == null) return null;
79
80
        if ( ! is_int($parameters[0]))
81
        {
82
            throw new \InvalidArgumentException("This is not a valid ID");
83
        }
84
85
        return true;
86
    }
87
88
    /**
89
     * @param $class
90
     *
91
     * @throws ClassNotCreatedException
92
     */
93
    protected function doesClassExist($class)
94
    {
95
        if ( ! class_exists($class))
96
        {
97
            throw new ClassNotCreatedException("Class $class could not be created.");
98
        }
99
    }
100
}
101