TestProfile::initCache()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 9
rs 9.6666
c 1
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Bouncer package.
5
 *
6
 * (c) François Hodierne <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Bouncer\Profile;
13
14
use Bouncer\Bouncer;
15
16
class TestProfile extends DefaultProfile
17
{
18
19
    public function load(Bouncer $instance)
20
    {
21
        parent::load($instance);
22
23
        $exitHandler = function() {
24
            // error_log('Test profile. Not exiting.');
25
        };
26
27
        $instance->setOptions(array('exitHandler' => $exitHandler));
28
29
        $responseCodeHandler = function($code = null) {
30
            static $currentCode = 200;
31
            if ($code) {
32
                $currentCode = $code;
33
            }
34
            return $currentCode;
35
        };
36
37
        $instance->setOptions(array('responseCodeHandler' => $responseCodeHandler));
38
    }
39
40
    public function initCache(Bouncer $instance)
41
    {
42
        // If no cache available, set up Void cache
43
        $cache = $instance->getCache();
44
        if (empty($cache)) {
45
            $cache = new \Bouncer\Cache\VoidCache();
46
            $instance->setOptions(array('cache' => $cache));
47
        }
48
    }
49
50
}
51