Completed
Branch 1.x (112be9)
by Akihito
06:58 queued 04:37
created

OptionalParam::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 3
crap 2
1
<?php
2
/**
3
 * This file is part of the BEAR.Resource package.
4
 *
5
 * @license http://opensource.org/licenses/MIT MIT
6
 */
7
namespace BEAR\Resource;
8
9
use Ray\Di\InjectorInterface;
10
11
final class OptionalParam implements ParamInterface
12
{
13
    private $defaultValue;
14
15 19
    public function __construct($defaultValue)
16
    {
17 19
        $this->defaultValue = $defaultValue;
18 19
    }
19
20
    /**
21
     * {@inheritdoc}
22
     */
23 18
    public function __invoke($varName, array $query, InjectorInterface $injector)
24
    {
25 18
        unset($injector);
26 18
        if (isset($query[$varName])) {
27 9
            return $query[$varName];
28
        }
29
30 9
        return $this->defaultValue;
31
    }
32
}
33