Completed
Push — master ( d401ab...1f0fb6 )
by Łukasz
02:47
created

DataRowsBuilder   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 94.74%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 1
dl 0
loc 57
ccs 18
cts 19
cp 0.9474
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A buildCandidateRow() 0 10 3
A normalizeStatus() 0 13 3
A build() 0 9 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 1
        return [$candidate->getName(), self::normalizeStatus($status)];
29
    }
30
31
32
33
    /**
34
     * @param $status
35
     * @return string
36
     */
37 1
    private static function normalizeStatus($status)
38
    {
39
        switch ($status) {
40 1
            case Candidate::STATUS_QUEUED:
41 1
                $status = sprintf('<comment>%s</comment>', $status);
42 1
                break;
43 1
            case Candidate::STATUS_HAS_SYNTAX_ERROR:
44 1
                $status = sprintf('<error>%s</error>', $status);
45 1
                break;
46
        }
47
48 1
        return $status;
49
    }
50
51
52
53
    /**
54
     * @param Candidate[] $candidates
55
     * @param boolean $skipAlreadyDeployed
56
     * @return array
57
     */
58 1
    public function build(array $candidates, $skipAlreadyDeployed)
59
    {
60 1
        return array_filter(array_map(
61 1
            function(Candidate $candidate) use ($skipAlreadyDeployed) {
62 1
                return DataRowsBuilder::buildCandidateRow($candidate, $skipAlreadyDeployed);
63 1
            },
64
            $candidates
65 1
        ));
66
    }
67
}
68