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   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 1
dl 0
loc 95
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __call() 0 13 2
A getNamespace() 0 6 1
A getQualifiedName() 0 4 1
A paramIsId() 0 11 3
A doesClassExist() 0 7 2
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