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.
Completed
Push — 3.0 ( 06e746...c52ac9 )
by Vermeulen
04:55
created

SubjectList::removeSubject()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 2
eloc 8
nc 2
nop 1
1
<?php
2
3
namespace BFW;
4
5
use \Exception;
6
7
class SubjectList
8
{
9
    /**
10
     * @const ERR_SUBJECT_NAME_NOT_EXIST Exception code if a subject name is
11
     * not found.
12
     */
13
    const ERR_SUBJECT_NAME_NOT_EXIST = 1317001;
14
    
15
    /**
16
     * @const ERR_SUBJECT_NOT_FOUND Exception code if a subject is not found.
17
     */
18
    const ERR_SUBJECT_NOT_FOUND = 1317002;
19
    
20
    /**
21
     * @var \SplSubject[] $subjectList List of all subjects declared
22
     */
23
    protected $subjectList = [];
24
    
25
    /**
26
     * Getter accessor to property subjectList
27
     * 
28
     * @return \SplSubject[]
29
     */
30
    public function getSubjectList()
31
    {
32
        return $this->subjectList;
33
    }
34
    
35
    /**
36
     * Obtain a subject object with this name
37
     * 
38
     * @param string $subjectName The name of the subject object
39
     * 
40
     * @return \SplSubject
41
     * 
42
     * @throws Exception If the subject name not exist
43
     */
44
    public function getSubjectForName($subjectName)
45
    {
46
        if (!array_key_exists($subjectName, $this->subjectList)) {
47
            throw new Exception(
48
                'The subject '.$subjectName.' is not in the list.',
49
                self::ERR_SUBJECT_NAME_NOT_EXIST
50
            );
51
        }
52
        
53
        return $this->subjectList[$subjectName];
54
    }
55
56
        
57
    /**
58
     * Add a new subject to the list
59
     * 
60
     * @param \SplSubject $subject The new subject to add
61
     * @param string|null $subjectName (default null) The subject name, if null,
62
     * the name of the class will be used
63
     * 
64
     * @return $this
65
     */
66
    public function addSubject(\SplSubject $subject, $subjectName = null)
67
    {
68
        if ($subjectName === null) {
69
            $subjectName = get_class($subject);
70
        }
71
        
72
        $this->subjectList[$subjectName] = $subject;
73
        
74
        return $this;
75
    }
76
    
77
    /**
78
     * Remove a subject from the list
79
     * 
80
     * @param \SplSubject $subject The subject to remove from the list
81
     * 
82
     * @return $this
83
     * 
84
     * @throws Exception If the subject has not been found into the list
85
     */
86
    public function removeSubject(\SplSubject $subject)
87
    {
88
        $key = array_search($subject, $this->subjectList, true);
89
        
90
        if ($key === false) {
91
            throw new Exception(
92
                'The subject has not been found.',
93
                self::ERR_SUBJECT_NOT_FOUND
94
            );
95
        }
96
        
97
        unset($this->subjectList[$key]);
98
99
        return $this;
100
    }
101
}
102