Completed
Push — master ( 301f3c...656cd4 )
by James
03:43
created

PropertyFormatter::formatPropertyValue()   C

Complexity

Conditions 7
Paths 5

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 22
ccs 0
cts 12
cp 0
rs 6.9811
c 1
b 0
f 0
cc 7
eloc 14
nc 5
nop 2
crap 56
1
<?php
2
declare(strict_types = 1);
3
4
namespace BrowscapPHP\Data;
5
6
final class PropertyFormatter
7
{
8
    /**
9
     * @var PropertyHolder
10
     */
11
    private $propertyHolder;
12
13
    /**
14
     * class constructor
15
     *
16
     * @param PropertyHolder $propertyHolder
17
     */
18
    public function __construct(PropertyHolder $propertyHolder)
19
    {
20
        $this->propertyHolder = $propertyHolder;
21
    }
22
23
    /**
24
     * formats the name of a property
25
     *
26
     * @param bool|string $value
27
     * @param string $property
28
     *
29
     * @throws \Exception
30
     *
31
     * @return bool|string
32
     */
33
    public function formatPropertyValue($value, string $property)
34
    {
35
        switch ($this->propertyHolder->getPropertyType($property)) {
36
            case PropertyHolder::TYPE_BOOLEAN:
37
                if (true === $value || 'true' === $value || '1' === $value) {
38
                    return true;
39
                }
40
41
                return false;
42
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
43
            case PropertyHolder::TYPE_IN_ARRAY:
44
                try {
45
                    return $this->propertyHolder->checkValueInArray($property, (string) $value);
46
                } catch (\InvalidArgumentException $ex) {
47
                    return '';
48
                }
49
50
                break;
0 ignored issues
show
Unused Code introduced by
break; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
51
        }
52
53
        return $value;
54
    }
55
}
56