Completed
Pull Request — master (#40)
by Tim
05:10
created

BooleanCallback   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 1
dl 0
loc 30
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 4 1
1
<?php
2
3
/**
4
 * TechDivision\Import\Callbacks\BooleanCallback
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2016 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/techdivision/import-category
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Callbacks;
22
23
/**
24
 * A callback implementation that converts the passed boolean value.
25
 *
26
 * @author    Tim Wagner <[email protected]>
27
 * @copyright 2016 TechDivision GmbH <[email protected]>
28
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
 * @link      https://github.com/techdivision/import-category
30
 * @link      http://www.techdivision.com
31
 */
32
class BooleanCallback extends AbstractCallback
33
{
34
35
    /**
36
     * Array with the string => boolean mapping.
37
     *
38
     * @var array
39
     */
40
    protected $booleanValues = array(
41
        'true'  => 1,
42
        'yes'   => 1,
43
        '1'     => 1,
44
        'false' => 0,
45
        'no'    => 0,
46
        '0'     => 0
47
    );
48
49
    /**
50
     * Will be invoked by a observer it has been registered for.
51
     *
52
     * @param mixed $value The value to handle
53
     *
54
     * @return mixed The modified value
55
     * @see \TechDivision\Import\Product\Callbacks\ProductImportCallbackInterface::handle()
56
     */
57
    public function handle($value)
58
    {
59
        return (boolean) $this->booleanValues[strtolower($value)];
60
    }
61
}
62