Passed
Branch master (935746)
by compolom
02:34 queued 29s
created

Param   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A escape() 0 4 2
A getName() 0 4 1
A getValue() 0 4 1
A __toString() 0 14 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Compolomus\IniObject;
6
7
class Param
8
{
9
    private $name;
10
11
    private $value;
12
13
    /**
14
     * Param constructor.
15
     *
16
     * @param string $name
17
     * @param mixed $value
18
     */
19 10
    public function __construct(string $name, $value)
20
    {
21 10
        $this->name = $name;
22 10
        $this->value = $this->escape($value);
23 10
    }
24
25
    /**
26
     * @return string
27
     */
28 1
    public function getName(): string
29
    {
30 1
        return $this->name;
31
    }
32
33
    /**
34
     * @param string $value
35
     * @return mixed
36
     */
37 10
    private function escape($value = '')
38
    {
39 10
        return empty($value) ? false : $value;
40
    }
41
42
//    /**
43
//     * @param $value
44
//     * @return mixed
45
//     */
46
//    private function bool($value)
47
//    {
48
//        $values = [
49
//            'true',
50
//            'false',
51
//            'null',
52
//            'on',
53
//            'off',
54
//            'yes',
55
//            'no'
56
//        ];
57
//
58
//        return (in_array($value, $values, true) || is_numeric($value) || is_array($value) ? $value : '"' . $value . '"');
59
//    }
60
61
    /**
62
     * @return mixed
63
     */
64 4
    public function getValue()
65
    {
66 4
        return $this->value ?? null;
67
    }
68
69 1
    public function __toString(): string
70
    {
71 1
        $return = '';
72
73 1
        if (is_array($this->getValue())) {
74 1
            foreach ($this->getValue() as $key => $value) {
75 1
                $return .= $this->getName() . '[' . $key . '] = ' . $this->escape($value) . PHP_EOL;
76
            }
77
        } else {
78 1
            $return = $this->getName() . ' = ' . $this->value . PHP_EOL;
79
        }
80
81 1
        return $return;
82
    }
83
}
84