Component::ordered()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Console component
4
 * User: moyo
5
 * Date: 26/03/2018
6
 * Time: 11:19 AM
7
 */
8
9
namespace Carno\Console;
10
11
use Carno\Console\Contracts\Bootable;
12
use Carno\Container\DI;
13
14
abstract class Component implements Bootable
15
{
16
    /**
17
     * @var float
18
     */
19
    private $ordered = .0;
20
21
    /**
22
     * @var int
23
     */
24
    protected $priority = 50;
25
26
    /**
27
     * @var array
28
     */
29
    protected $prerequisites = [];
30
31
    /**
32
     * @var array
33
     */
34
    protected $dependencies = [];
35
36
    /**
37
     * @param float $position
38
     */
39
    public function ordered(float $position) : void
40
    {
41
        $this->ordered = $position / 1000;
42
    }
43
44
    /**
45
     * @return float
46
     */
47
    public function priority() : float
48
    {
49
        return $this->priority + $this->ordered;
50
    }
51
52
    /**
53
     * @return bool
54
     */
55
    public function runnable() : bool
56
    {
57
        foreach ($this->prerequisites as $class) {
58
            if (!class_exists($class) && !interface_exists($class)) {
59
                return false;
60
            }
61
        }
62
63
        foreach ($this->dependencies as $class) {
64
            if (!DI::has($class)) {
65
                return false;
66
            }
67
        }
68
69
        return true;
70
    }
71
}
72