Completed
Push — 1.x ( d468cb...112be9 )
by Akihito
02:57
created

OptionalParam   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 22
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 9 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