Completed
Pull Request — master (#13)
by Łukasz
03:23
created

DataRowsBuilder::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Tworzenieweb\SqlProvisioner\Table;
4
5
use Tworzenieweb\SqlProvisioner\Model\Candidate;
6
7
/**
8
 * Class DataRowsBuilder
9
 * @package Tworzenieweb\SqlProvisioner\Table
10
 */
11
class DataRowsBuilder
12
{
13
    const TABLE_HEADERS = ['FILENAME', 'STATUS'];
14
15
    /**
16
     * @param Candidate $candidate
17
     * @param boolean $skipAlreadyDeployed
18
     * @return array|null
19
     */
20 1
    public static function buildCandidateRow(Candidate $candidate, $skipAlreadyDeployed)
21
    {
22 1
        $status = $candidate->getStatus();
23
24 1
        if ($skipAlreadyDeployed && $status === Candidate::STATUS_ALREADY_DEPLOYED) {
25
            return null;
26
        }
27
28
        switch ($status) {
29 1
            case Candidate::STATUS_QUEUED:
30 1
                $status = sprintf('<comment>%s</comment>', $status);
31 1
                break;
32 1
            case Candidate::STATUS_HAS_SYNTAX_ERROR:
33 1
                $status = sprintf('<error>%s</error>', $status);
34 1
                break;
35
        }
36
37 1
        return [$candidate->getName(), $status];
38
    }
39
40
    /**
41
     * @param Candidate[] $candidates
42
     * @param boolean $skipAlreadyDeployed
43
     * @return array
44
     */
45 1
    public function build(array $candidates, $skipAlreadyDeployed)
46
    {
47 1
        return array_filter(array_map(
48 1
            function (Candidate $candidate) use ($skipAlreadyDeployed) {
49 1
                return DataRowsBuilder::buildCandidateRow($candidate, $skipAlreadyDeployed);
50 1
            },
51
            $candidates
52 1
        ));
53
    }
54
}
55