Passed
Push — master ( 9b47e1...f74cd8 )
by Tom
05:04 queued 02:06
created

Artifacts::getPatterns()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
/* this file is part of pipelines */
4
5
namespace Ktomk\Pipelines\File;
6
7
/**
8
 * Artifacts of a pipelines step
9
 *
10
 * @package Ktomk\Pipelines\File\File
11
 */
12
class Artifacts implements \Countable
13
{
14
    /**
15
     * @var array|string[]
16
     */
17
    private $paths;
18
19
    /**
20
     * Artifacts constructor.
21
     *
22
     * @param array|string[] $artifacts
23
     *
24
     * @throws ParseException
25
     */
26 6
    public function __construct(array $artifacts)
27
    {
28 6
        $this->parse($artifacts);
29
    }
30
31
    /**
32
     * @return array|string[]
33
     */
34 2
    public function getPaths()
35
    {
36 2
        return $this->paths;
37
    }
38
39 1
    #[\ReturnTypeWillChange]
40
    /**
41
     * @return int
42
     */
43
    public function count()
44
    {
45 1
        return count($this->paths);
46
    }
47
48
    /**
49
     *
50
     * @throws ParseException
51
     *
52
     * @return void
53
     */
54 6
    private function parse(array $artifacts)
55
    {
56
        // quick validation: if an "object" and it has the "paths" attribute, this is the list
57 6
        if (isset($artifacts['paths']) && is_array($artifacts['paths'])) {
58 1
            $artifacts = $artifacts['paths'];
59
        }
60
61
        // quick validation: requires a list of strings which must not be empty (can't in YAML anyway)
62 6
        if (!count($artifacts)) {
63 1
            throw new ParseException("'artifacts' requires a list");
64
        }
65
66 5
        foreach ($artifacts as $index => $string) {
67 5
            if (!is_string($string)) {
68 1
                throw new ParseException(sprintf(
69
                    "'artifacts' requires a list of paths",
70
                    $index
71
                ));
72
            }
73
        }
74
75 4
        $this->paths = $artifacts;
76
    }
77
}
78