Completed
Push — master ( 72206a...a05009 )
by Michael
11:12
created

PatchStatus::__construct()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 7
nc 6
nop 1
dl 0
loc 12
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
class PatchStatus
4
{
5
    /** @var string $patchClass class name of patch */
6
    public $patchClass;
7
8
    /** @var bool $applied true if this patch is applied, false if it is needed */
9
    public $applied = true;
10
11
    /** @var string[] $tasks tasks that need to be run */
12
    public $tasks = array();
13
14
    /** @var string[] $files files that need to be writable */
15
    public $files = array();
16
17
    /**
18
     * PatchStatus constructor.
19
     * @param XoopsUpgrade $patch
20
     */
21
    public function __construct(XoopsUpgrade $patch)
22
    {
23
        $this->patchClass = get_class($patch);
24
        foreach ($patch->tasks as $task) {
25
            if (!$patch->{"check_{$task}"}()) {
26
                $this->addTask($task);
27
            }
28
        }
29
        if (!empty($patch->usedFiles) && !$this->applied) {
30
            $this->files = $patch->usedFiles;
31
        }
32
    }
33
34
    /**
35
     * Add a task that needs to be run to the tasks property
36
     *
37
     * @param string $task task name
38
     */
39
    protected function addTask($task)
40
    {
41
        $this->tasks[] = $task;
42
        $this->applied = false;
43
    }
44
}
45