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

DataRowsBuilder   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 94.12%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 44
ccs 16
cts 17
cp 0.9412
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B buildCandidateRow() 0 19 5
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
        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