Passed
Push — master ( 1faa52...d67625 )
by Dispositif
05:49 queued 11s
created

generateSetterMethodList()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 8
ccs 0
cts 6
cp 0
crap 6
rs 10
c 1
b 0
f 0
1
<?php
2
/**
3
 * This file is part of dispositif/wikibot application
4
 * 2019 : Philippe M. <[email protected]>
5
 * For the full copyright and MIT license information, please view the LICENSE file.
6
 */
7
8
declare(strict_types=1);
9
10
namespace App\Domain\Models\Wiki;
11
12
use App\Domain\Utils\ArrayProcessTrait;
13
14
/**
15
 * @notused todo inutile ?
16
 * Class AbstractParametersObject
17
 */
18
abstract class AbstractParametersObject
19
{
20
    use ArrayProcessTrait;
21
22
    protected $parametersValues;
23
24
    //    public function generateSetterMethodList()
25
    //    {
26
    //        $list = '';
27
    //        foreach ($this->parametersByOrder as $name) {
28
    //            $method = $this->setterMethodName($name);
29
    //            $list .= 'private function '.$method."() { }\n";
30
    //        }
31
    //        echo "<pre>$list</pre>";
32
    //    }
33
34
    /**
35
     * Magic param setter.
36
     *
37
     * @param $name
38
     *
39
     * @return string
40 88
     */
41
    protected function setterMethodName(string $name): string
42 88
    {
43 88
        $sanitizedName = str_replace([' ', 'à', 'é'], ['', 'a', 'e'], $name);
44
        $sanitizedName = preg_replace('#[^A-Za-z0-9]#', '', $sanitizedName);
45 88
46
        return 'set'.ucfirst($sanitizedName);
47
    }
48
49
    /**
50
     *
51
     * @return array
52
     */
53
    public function toArray(): array
54
    {
55
        return $this->deleteEmptyValueArray($this->parametersValues);
56
    }
57
58
    /**
59
     * Compare param/value datas. Empty value ignored. Params order ignored.
60
     *
61
     * @param AbstractParametersObject $object
62
     *
63
     * @return bool
64
     */
65
    public function isParamValueEquals(self $object): bool
66
    {
67
        $dat1 = $this->deleteEmptyValueArray($this->toArray());
68
        $dat2 = $this->deleteEmptyValueArray($object->toArray());
69
        if (count($dat1) !== count($dat2)) {
70
            return false;
71
        }
72
        foreach ($dat1 as $param => $value) {
73
            if (!isset($dat2[$param]) || $dat2[$param] !== $value) {
74
                return false;
75
            }
76
        }
77
78
        return true;
79
    }
80
}
81