Completed
Push — master ( b133bf...737a42 )
by Rick
04:48
created

Defaults   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 1
cbo 0
dl 0
loc 33
ccs 5
cts 5
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A filter() 0 4 2
1
<?php
2
/**
3
 * Particle.
4
 *
5
 * @link      http://github.com/particle-php for the canonical source repository
6
 * @copyright Copyright (c) 2005-2015 Particle (http://particle-php.com)
7
 * @license   https://github.com/particle-php/Filter/blob/master/LICENSE New BSD License
8
 */
9
namespace Particle\Filter\FilterRule;
10
11
use Particle\Filter\FilterRule;
12
13
/**
14
 * Class Defaults
15
 *
16
 * @package Particle\Filter\FilterRule
17
 */
18
class Defaults extends FilterRule
19
{
20
    /**
21
     * Allows a default value to be set if no data key was provided
22
     *
23
     * @var bool
24
     */
25
    protected $allowNotSet = true;
26
27
    /**
28
     * @var mixed
29
     */
30
    protected $defaultValue;
31
32
    /**
33
     * @param mixed $defaultValue
34
     */
35 13
    public function __construct($defaultValue)
36
    {
37 13
        $this->defaultValue = $defaultValue;
38 13
    }
39
40
    /**
41
     * Return a default value if no value was provided
42
     *
43
     * @param mixed $value
44
     * @return string
45
     */
46 13
    public function filter($value)
47
    {
48 13
        return $value === null ? $this->defaultValue : $value;
49
    }
50
}
51