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 — 2.2 ( 8999d4...f4c653 )
by Vermeulen
02:34
created

Visiteur   A

Complexity

Total Complexity 25

Size/Duplication

Total Lines 317
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 25
c 3
b 0
f 2
lcom 1
cbo 1
dl 0
loc 317
rs 10

25 Methods

Rating   Name   Duplication   Size   Complexity  
A beforeTestMethod() 0 18 1
A testGetIdSession() 0 4 1
A testGetIp() 0 4 1
A testGetHost() 0 4 1
A testGetProxy() 0 4 1
A testGetProxyIp() 0 4 1
A testGetProxyHost() 0 4 1
A testGetOs() 0 4 1
A testGetNav() 0 4 1
A testGetLangue() 0 4 1
A testGetLangueInitiale() 0 4 1
A testGetProviens() 0 4 1
A testGetUrl() 0 4 1
A testGetBot() 0 4 1
A testVisiteur() 0 10 1
A testProxyHostDetect() 0 4 1
A testRealIpDetect() 0 8 1
B testSystemDetect() 0 29 1
B testBrowserDetect() 0 30 1
A testLanguageDetect() 0 10 1
A testLanguageConvert() 0 5 1
A testRefererDetect() 0 9 1
A testUriDetect() 0 13 1
A testProxyDetect() 0 4 1
A testProxyIpDetect() 0 4 1
1
<?php
2
/**
3
 * Fichier de test pour une class
4
 */
5
6
namespace BFW\test\unit;
7
use \atoum;
8
9
require_once(__DIR__.'/../common.php');
10
11
/**
12
 * Test de la class Visiteur
13
 */
14
class Visiteur extends atoum
15
{
16
    /**
17
     * @var $class : Instance de la class Visiteur
18
     */
19
    protected $class;
20
21
    /**
22
     * @var $mock : Instance du mock pour la class Visiteur
23
     */
24
    protected $mock;
25
26
    /**
27
     * Instanciation de la class avant chaque méthode de test
28
     */
29
    public function beforeTestMethod($testMethod)
30
    {
31
        $_SERVER = array(
32
            'HTTP_HOST'       => 'bfw.bulton.fr',
33
            'HTTP_CONNECTION' => 'keep-alive',
34
            'HTTP_ACCEPT'     => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
35
            'HTTP_USER_AGENT' => 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36',
36
            'HTTP_ACCEPT_ENCODING' => 'gzip,deflate,sdch',
37
            'HTTP_ACCEPT_LANGUAGE' => 'fr,fr-FR;q=0.8,en-US;q=0.6,en;q=0.4',
38
            'SERVER_NAME' => 'bfw.bulton.fr',
39
            'SERVER_ADDR' => '46.105.37.1',
40
            'REMOTE_ADDR' => '46.105.37.1',
41
            'REQUEST_URI' => '/test.php',
42
        );
43
        
44
        //$this->class = new \BFW\Visiteur();
45
        $this->mock  = new MockVisiteur();
46
    }
47
    
48
    /**
49
     * Test de la méthode getIdSession()
50
     */
51
    public function testGetIdSession()
52
    {
53
        $this->variable($this->mock->getIdSession())->isNull();
54
    }
55
    
56
    /**
57
     * Test de la méthode getIp()
58
     */
59
    public function testGetIp()
60
    {
61
        $this->string($this->mock->getIp())->isEqualTo('46.105.37.1');
62
    }
63
    
64
    /**
65
     * Test de la méthode getHost()
66
     */
67
    public function testGetHost()
68
    {
69
        $this->string($this->mock->getHost())->isEqualTo('');
70
    }
71
    
72
    /**
73
     * Test de la méthode getProxy()
74
     */
75
    public function testGetProxy()
76
    {
77
        $this->variable($this->mock->getProxy())->isNull();
78
    }
79
    
80
    /**
81
     * Test de la méthode getProxyIp()
82
     */
83
    public function testGetProxyIp()
84
    {
85
        $this->string($this->mock->getProxyIp())->isEqualTo('');
86
    }
87
    
88
    /**
89
     * Test de la méthode getProxyHost()
90
     */
91
    public function testGetProxyHost()
92
    {
93
        $this->string($this->mock->getProxyHost())->isEqualTo('');
94
    }
95
    
96
    /**
97
     * Test de la méthode getOs()
98
     */
99
    public function testGetOs()
100
    {
101
        $this->string($this->mock->getOs())->isEqualTo('Windows 7');
102
    }
103
    
104
    /**
105
     * Test de la méthode getNav()
106
     */
107
    public function testGetNav()
108
    {
109
        $this->string($this->mock->getNav())->isEqualTo('Chrome');
110
    }
111
    
112
    /**
113
     * Test de la méthode getLangue()
114
     */
115
    public function testGetLangue()
116
    {
117
        $this->string($this->mock->getLangue())->isEqualTo('Français');
118
    }
119
    
120
    /**
121
     * Test de la méthode getLangueInitiale()
122
     */
123
    public function testGetLangueInitiale()
124
    {
125
        $this->string($this->mock->getLangueInitiale())->isEqualTo('fr');
126
    }
127
    
128
    /**
129
     * Test de la méthode getProviens()
130
     */
131
    public function testGetProviens()
132
    {
133
        $this->string($this->mock->getProviens())->isEqualTo('Inconnu');
134
    }
135
    
136
    /**
137
     * Test de la méthode getUrl()
138
     */
139
    public function testGetUrl()
140
    {
141
        $this->string($this->mock->getUrl())->isEqualTo('http://bfw.bulton.fr/test.php');
142
    }
143
    
144
    /**
145
     * Test de la méthode getBot()
146
     */
147
    public function testGetBot()
148
    {
149
        $this->string($this->mock->getBot())->isEqualTo('');
150
    }
151
152
    /**
153
     * Test du constructeur : Visiteur()
154
     */
155
    public function testVisiteur()
156
    {
157
        $this->mock = new MockVisiteur();
158
        $this->variable($this->mock->idSession)->isNull();
159
        $this->object($this->mock->_kernel)->isInstanceOf('\BFW\Kernel');
160
        
161
        $_SESSION['idSess'] = 'monId';
162
        $this->mock = new MockVisiteur();
163
        $this->string($this->mock->idSession)->isEqualTo('monId');
164
    }
165
166
    /**
167
     * Test de la méthode proxyDetect()
168
     * 
169
     * @TODO : Validate proxy detector before
170
     */
171
    public function testProxyDetect()
172
    {
173
        
174
    }
175
176
    /**
177
     * Test de la méthode proxyIpDetect()
178
     * 
179
     * @TODO : Validate proxy detector before
180
     */
181
    public function testProxyIpDetect()
182
    {
183
        
184
    }
185
186
    /**
187
     * Test de la méthode proxyHostDetect()
188
     * 
189
     * @TODO : Validate proxy detector before
190
     */
191
    public function testProxyHostDetect()
192
    {
193
        
194
    }
195
196
    /**
197
     * Test de la méthode realIpDetect()
198
     * 
199
     * @TODO : Validate proxy detector before
200
     */
201
    public function testRealIpDetect()
202
    {
203
        //Without proxy
204
        $this->mock->realIpDetect();
205
        $this->string($this->mock->ip)->isEqualTo('46.105.37.1');
206
        
207
        //With proxy : Todo
208
    }
209
210
    /**
211
     * Test de la méthode systemDetect()
212
     */
213
    public function testSystemDetect()
214
    {
215
        $this->mock->systemDetect();
216
        $this->string($this->mock->os)->isEqualTo('Windows 7');
217
        
218
        $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6';
219
        $this->mock->systemDetect();
220
        $this->string($this->mock->os)->isEqualTo('Windows XP');
221
        
222
        $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120724 Debian Iceweasel/15.0';
223
        $this->mock->systemDetect();
224
        $this->string($this->mock->os)->isEqualTo('Linux');
225
        
226
        $_SERVER['HTTP_USER_AGENT'] = 'Opera/9.80 (Android; Opera Mini/7.5.33361/31.1350; U; en) Presto/2.8.119 Version/11.10';
227
        $this->mock->systemDetect();
228
        $this->string($this->mock->os)->isEqualTo('Android');
229
        
230
        $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1944.0 Safari/537.36';
231
        $this->mock->systemDetect();
232
        $this->string($this->mock->os)->isEqualTo('Macintosh');
233
        
234
        $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25';
235
        $this->mock->systemDetect();
236
        $this->string($this->mock->os)->isEqualTo('Macintosh');
237
        
238
        $_SERVER['HTTP_USER_AGENT'] = '';
239
        $this->mock->systemDetect();
240
        $this->string($this->mock->os)->isEqualTo('Inconnu');
241
    }
242
243
    /**
244
     * Test de la méthode browserDetect()
245
     */
246
    public function testBrowserDetect()
247
    {
248
        $this->mock->browserDetect();
249
        $this->string($this->mock->nav)->isEqualTo('Chrome');
250
        
251
        $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6';
252
        $this->mock->browserDetect();
253
        $this->string($this->mock->nav)->isEqualTo('Mozilla Firefox');
254
        
255
        $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120724 Debian Iceweasel/15.0';
256
        $this->mock->browserDetect();
257
        $this->string($this->mock->nav)->isEqualTo('Mozilla');
258
        
259
        $_SERVER['HTTP_USER_AGENT'] = 'Opera/9.80 (Android; Opera Mini/7.5.33361/31.1350; U; en) Presto/2.8.119 Version/11.10';
260
        $this->mock->browserDetect();
261
        $this->string($this->mock->nav)->isEqualTo('Opera');
262
        
263
        $_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25';
264
        $this->mock->browserDetect();
265
        $this->string($this->mock->nav)->isEqualTo('Safari');
266
        
267
        $_SERVER['HTTP_USER_AGENT'] = 'Googlebot/2.1 ( http://www.googlebot.com/bot.html) ';
268
        $this->mock->browserDetect();
269
        $this->string($this->mock->nav)->isEqualTo('Search engine');
270
        $this->string($this->mock->bot)->isEqualTo('Google');
271
        
272
        $_SERVER['HTTP_USER_AGENT'] = '';
273
        $this->mock->browserDetect();
274
        $this->string($this->mock->nav)->isEqualTo('Inconnu');
275
    }
276
277
    /**
278
     * Test de la méthode languageDetect()
279
     */
280
    public function testLanguageDetect()
281
    {
282
        $this->string($this->mock->languageDetect())->isEqualTo('fr');
283
        
284
        $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'es,en-us;q=0.3,de;q=0.1';
285
        $this->string($this->mock->languageDetect())->isEqualTo('es');
286
        
287
        $_SERVER['HTTP_ACCEPT_LANGUAGE'] = 'en-us;q=0.3,de;q=0.1';
288
        $this->string($this->mock->languageDetect())->isEqualTo('en');
289
    }
290
291
    /**
292
     * Test de la méthode languageConvert($lang='')
293
     */
294
    public function testLanguageConvert()
295
    {
296
        $this->string($this->mock->languageConvert('fr'))->isEqualTo('Français');
297
        $this->string($this->mock->languageConvert('frr'))->isEqualTo('Inconnue');
298
    }
299
300
    /**
301
     * Test de la méthode refererDetect()
302
     */
303
    public function testRefererDetect()
304
    {
305
        $this->mock->refererDetect();
306
        $this->string($this->mock->proviens)->isEqualTo('Inconnu');
307
        
308
        $_SERVER['HTTP_REFERER'] = 'http://www.google.fr';
309
        $this->mock->refererDetect();
310
        $this->string($this->mock->proviens)->isEqualTo('http://www.google.fr');
311
    }
312
313
    /**
314
     * Test de la méthode uriDetect()
315
     */
316
    public function testUriDetect()
317
    {
318
        $this->mock->uriDetect();
319
        $this->string($this->mock->url)->isEqualTo('http://bfw.bulton.fr/test.php');
320
        
321
        $_SERVER['REQUEST_URI'] = '';
322
        $this->mock->uriDetect();
323
        $this->string($this->mock->url)->isEqualTo('Inconnu');
324
        
325
        unset($_SERVER['REQUEST_URI']);
326
        $this->mock->uriDetect();
327
        $this->string($this->mock->url)->isEqualTo('Inconnu');
328
    }
329
330
}
331
332
/**
333
 * Mock pour la classe Visiteur
334
 */
335
class MockVisiteur extends \BFW\Visiteur
336
{
337
    /**
338
     * Accesseur get
339
     */
340
    public function __get($name) {return $this->$name;}
341
342
    /**
343
     * Test de la méthode recupInfos()
344
     */
345
    public function recupInfos()
346
    {
347
        return parent::recupInfos();
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class BFW\Visiteur as the method recupInfos() does only exist in the following sub-classes of BFW\Visiteur: BFW\test\unit\MockVisiteur. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
348
    }
349
350
    /**
351
     * Test de la méthode proxyDetect()
352
     */
353
    public function proxyDetect()
354
    {
355
        return parent::proxyDetect();
356
    }
357
358
    /**
359
     * Test de la méthode proxyIpDetect()
360
     */
361
    public function proxyIpDetect()
362
    {
363
        return parent::proxyIpDetect();
364
    }
365
366
    /**
367
     * Test de la méthode proxyHostDetect()
368
     */
369
    public function proxyHostDetect()
370
    {
371
        return parent::proxyHostDetect();
372
    }
373
374
    /**
375
     * Test de la méthode realIpDetect()
376
     */
377
    public function realIpDetect()
378
    {
379
        return parent::realIpDetect();
380
    }
381
382
    /**
383
     * Test de la méthode realHostDetect()
384
     */
385
    public function realHostDetect()
386
    {
387
        return parent::realHostDetect();
388
    }
389
390
    /**
391
     * Test de la méthode systemDetect()
392
     */
393
    public function systemDetect()
394
    {
395
        return parent::systemDetect();
396
    }
397
398
    /**
399
     * Test de la méthode browserDetect()
400
     */
401
    public function browserDetect()
402
    {
403
        return parent::browserDetect();
404
    }
405
406
    /**
407
     * Test de la méthode languageDetect()
408
     */
409
    public function languageDetect()
410
    {
411
        return parent::languageDetect();
412
    }
413
414
    /**
415
     * Test de la méthode languageConvert($lang='')
416
     */
417
    public function languageConvert($lang='')
418
    {
419
        return parent::languageConvert($lang);
420
    }
421
422
    /**
423
     * Test de la méthode refererDetect()
424
     */
425
    public function refererDetect()
426
    {
427
        return parent::refererDetect();
428
    }
429
430
    /**
431
     * Test de la méthode uriDetect()
432
     */
433
    public function uriDetect()
434
    {
435
        return parent::uriDetect();
436
    }
437
438
}
439