StructureDiffInfo::isEqual()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace ReenExe\CompareDataStructure;
4
/**
5
 * TODO: Возможно стоит лучше определить интерфейс и возвращать только его
6
 *          Чтобы убрать из ответа метод `addPath`
7
 */
8
class StructureDiffInfo
9
{
10
    const KEY    = 'Отсутствует ключ';
11
    const TYPE   = 'Разность типов';
12
    const CONFIG = 'Разность структуры';
13
14
    private $message;
15
16
    private $path = [];
17
18
    private $equal = false;
19
20
    private function __construct($equal)
21
    {
22
        $this->equal = $equal;
23
    }
24
25
    public static function createDiff($message)
26
    {
27
        $self =  new self(false);
28
        $self->message = $message;
29
        return $self;
30
    }
31
32
    public static function createEqual()
33
    {
34
        return new self(true);
35
    }
36
37
    public function isEqual() {
38
        return $this->equal;
39
    }
40
41
    public function addPath($key)
42
    {
43
        array_unshift($this->path, $key);
44
    }
45
46
    public function getMessage()
47
    {
48
        return $this->message;
49
    }
50
51
    public function getPath()
52
    {
53
        return join('.', $this->path);
54
    }
55
56
    public  function __toString()
57
    {
58
        return $this->isEqual() ? '' : "{$this->getMessage()} {$this->getPath()}";
59
    }
60
}