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
Pull Request — master (#68)
by Vermeulen
02:15
created

Kernel::detachOther()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 9
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 9
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
/**
3
 * Classes en rapport avec le Kernel
4
 * @author Vermeulen Maxime <[email protected]>
5
 * @version 1.0
6
 */
7
8
namespace BFW;
9
10
use \SplObserver;
11
use \SplSubject;
12
13
/**
14
 * Classe Noyau.
15
 * @package bfw
16
 */
17
class Kernel implements SplSubject
18
{
19
    /**
20
     * @var array $observers Liste des observateurs instanciés
21
     */
22
    protected $observers = array();
23
    
24
    /**
25
     * @var bool $debug Si mode débug ou non.
26
     */
27
    protected $debug = false;
28
    
29
    /**
30
     * L'action à déclancher par les observers.
31
     */
32
    protected $notify_action = null;
33
    
34
    //******* Observateurs *******
35
    /**
36
     * Ajouter un nouvel observateur
37
     * 
38
     * @param SplObserver $observer L'observateur à ajouter
39
     */
40
    public function attach(SplObserver $observer)
41
    {
42 1
        $this->observers[] = $observer;
43 1
    }
44
    
45
    /**
46
     * Ajouter un nouvel observateur de type autre SplObserver
47
     * 
48
     * @param object $observer L'observateur à ajouter
49
     */
50
    public function attachOther($observer)
51
    {
52 1
        $this->observers[] = $observer;
53 1
    }
54
    
55
    /**
56
     * Enlever un observateur
57
     * 
58
     * @param SplObserver $observer L'observateur à enlever
59
     */
60 View Code Duplication
    public function detach(SplObserver $observer)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
61
    {
62 1
        $key = array_search($observer, $this->observers, true);
63
        
64 1
        if($key !== false)
65 1
        {
66 1
            unset($this->observers[$key]);
67 1
        }
68 1
    }
69
    
70
    /**
71
     * Enlever un observateur de type autre SplObserver
72
     * 
73
     * @param object $observer L'observateur à enlever
74
     */
75 View Code Duplication
    public function detachOther($observer)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
76
    {
77 1
        $key = array_search($observer, $this->observers, true);
78
        
79
        if($key)
80 1
        {
81 1
            unset($this->observers[$key]);
82 1
        }
83 1
    }
84
    
85
    /**
86
     * Déclanche la notification vers les observers.
87
     * 
88
     * @param string $action L'action à faire par l'observateur.
89
     */
90
    public function notifyObserver($action)
91
    {
92 1
        foreach($this->observers as $observer)
93
        {
94
            //Appel la méthode update de l'observateur
95 1
            $observer->updateWithAction($this, $action);
96 1
        }
97
        
98 1
        $this->notify_action = null;
99 1
    }
100
    
101
    /**
102
     * Définie l'action à faire pour les observers.
103
     * 
104
     * @param string $action L'action à faire par l'observateur.
105
     * 
106
     * @return Kernel L'instance actuelle de la classe.
107
     */
108
    public function notifyAction($action)
109
    {
110 1
        $this->notify_action = $action;
111 1
        return $this;
112
    }
113
    
114
    /**
115
     * Déclanche la notification vers les observers.
116
     */
117
    public function notify()
118
    {
119 1
        if(!is_null($this->notify_action))
120 1
        {
121 1
            $this->notifyObserver($this->notify_action);
122 1
        }
123
        else
124
        {
125 1
            foreach($this->observers as $observer)
126
            {
127
                //Appel la méthode update de l'observateur
128 1
                $observer->update($this);
129 1
            }
130
        }
131 1
    }
132
    //******* Observateurs *******
133
    
134
    /**
135
     * Set de l'attribut debug. Gestion de l'affichage des erreurs en plus.
136
     * 
137
     * @param bool $debug True si on est en mode débug, False sinon.
138
     */
139
    public function setDebug($debug)
140
    {
141 1
        $this->debug = $debug;
142
        
143
        if($debug) //Affiche toutes les erreurs de php
144 1
        {
145 1
            error_reporting(E_ALL);
146 1
            ini_set('display_errors', 'On');
147 1
            ini_set('html_errors', true);
148 1
        }
149
        else //Affiche aucune erreur (prod)
150
        {
151 1
            error_reporting(0);
152
        }
153 1
    }
154
    
155
    /**
156
     * Accesseur vers l'attribut debug
157
     * 
158
     * @return bool
159
     */
160
    public function getDebug()
161
    {
162 1
        return $this->debug;
163
    }
164
}
165