StructureDiffInfo   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 0
Metric Value
wmc 9
lcom 2
cbo 0
dl 0
loc 53
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A createDiff() 0 6 1
A createEqual() 0 4 1
A isEqual() 0 3 1
A addPath() 0 4 1
A getMessage() 0 4 1
A getPath() 0 4 1
A __toString() 0 4 2
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
}