Passed
Push — master ( 6f7d84...935746 )
by compolom
02:06
created

Param::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
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