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

PropertyFormatter   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 50
ccs 0
cts 15
cp 0
rs 10
c 1
b 0
f 0

2 Methods

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