Coordinator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 4
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Valid resources coordinator
4
 * User: moyo
5
 * Date: 2018/6/4
6
 * Time: 2:25 PM
7
 */
8
9
namespace Carno\Validator;
10
11
use Carno\Validator\Chips\VWaits;
12
use Carno\Validator\Exception\IncompleteCoordinationException;
13
use Carno\Validator\Valid\Cloning;
14
use Carno\Validator\Valid\Group;
15
use Carno\Validator\Valid\Inherit;
16
use Carno\Validator\Valid\Named;
17
18
class Coordinator
19
{
20
    /**
21
     * @var Group
22
     */
23
    private $group = null;
24
25
    /**
26
     * @var Inherit
27
     */
28
    private $inherit = null;
29
30
    /**
31
     * @var Named
32
     */
33
    private $named = null;
34
35
    /**
36
     * @var Cloning
37
     */
38
    private $clone = null;
39
40
    /**
41
     * Coordinator constructor.
42
     * @param Group $group
43
     * @param Inherit $inherit
44
     * @param Named $named
45
     * @param Cloning $clone
46
     */
47
    public function __construct(
48
        Group $group,
49
        Inherit $inherit,
50
        Named $named,
51
        Cloning $clone
52
    ) {
53
        $this->group = $group;
54
        $this->inherit = $inherit;
55
        $this->named = $named;
56
        $this->clone = $clone;
57
    }
58
59
    /**
60
     * @return Group
61
     */
62
    public function group() : Group
63
    {
64
        return $this->group;
65
    }
66
67
    /**
68
     * @return Inherit
69
     */
70
    public function inherit() : Inherit
71
    {
72
        return $this->inherit;
73
    }
74
75
    /**
76
     * @return Named
77
     */
78
    public function named() : Named
79
    {
80
        return $this->named;
81
    }
82
83
    /**
84
     * @return Cloning
85
     */
86
    public function clone() : Cloning
87
    {
88
        return $this->clone;
89
    }
90
91
    /**
92
     */
93
    public function checking() : void
94
    {
95
        $waits = [
96
            'v-named' => $this->named(),
97
            'v-group' => $this->group(),
98
        ];
99
100
        /**
101
         * @var VWaits $wait
102
         */
103
104
        foreach ($waits as $type => $wait) {
105
            if (!$wait->resolved()) {
106
                throw new IncompleteCoordinationException(
107
                    sprintf('%s -> %s', $type, implode(',', $wait->incomplete()))
108
                );
109
            }
110
        }
111
    }
112
}
113