Passed
Push — master ( ce6411...dc02eb )
by Tom
04:33
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 $artifacts;
18
19
    /**
20
     * Artifacts constructor.
21
     *
22
     * @param array|string[] $artifacts
23
     *
24
     * @throws ParseException
25
     */
26 5
    public function __construct(array $artifacts)
27
    {
28 5
        $this->parse($artifacts);
29 3
    }
30
31
    /**
32
     * @return array|string[]
33
     */
34 1
    public function getPatterns()
35
    {
36 1
        return $this->artifacts;
37
    }
38
39
    /**
40
     * @return int
41
     */
42 1
    public function count()
43
    {
44 1
        return count($this->artifacts);
45
    }
46
47
    /**
48
     * @param array|string[] $artifacts
49
     *
50
     * @throws ParseException
51
     *
52
     * @return void
53
     */
54 5
    private function parse(array $artifacts)
55
    {
56
        // quick validation: requires a list of strings
57 5
        if (!count($artifacts)) {
58 1
            throw new ParseException("'artifacts' requires a list");
59
        }
60
61 4
        foreach ($artifacts as $index => $string) {
62 4
            if (!is_string($string)) {
63 1
                throw new ParseException(sprintf(
64 1
                    "'artifacts' requires a list of strings, #%d is not a string",
65
                    $index
66
                ));
67
            }
68
        }
69
70 3
        $this->artifacts = $artifacts;
71 3
    }
72
}
73