Completed
Push — master ( 12a557...496eb3 )
by François
02:35
created

TestProfile::initCache()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 9
rs 9.6666
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
        self::initCache($instance);
22
23
        parent::load($instance);
24
25
        $exit = function() {
26
            // error_log('Test profile. Not exiting.');
27
        };
28
29
        $instance->setOptions(array('exit' => $exit));
30
31
        $responseCodeSetter = function($code, $message) {
0 ignored issues
show
Unused Code introduced by
The parameter $message is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
32
            static $codeSet;
33
            if ($code) {
34
                $codeSet = $code;
35
            }
36
            return $codeSet;
37
        };
38
39
        $instance->setOptions(array('responseCodeSetter' => $responseCodeSetter));
40
    }
41
42
    public function initCache(Bouncer $instance)
43
    {
44
        // If no cache available, try to set up Void cache
45
        $cache = $instance->getCache();
46
        if (empty($cache)) {
47
            $cache = new \Bouncer\Cache\Void();
48
            $instance->setOptions(array('cache' => $cache));
49
        }
50
    }
51
52
}
53