Passed
Push — test ( 1f6f72...276f1a )
by Tom
02:41
created

Services::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
/* this file is part of pipelines */
4
5
namespace Ktomk\Pipelines\File\Definitions;
6
7
use Countable;
8
use Ktomk\Pipelines\File\ParseException;
9
10
/**
11
 * Class Services
12
 *
13
 * @package Ktomk\Pipelines\File\Definitions
14
 */
15
class Services implements Countable
16
{
17
    /**
18
     * @var array
19
     */
20
    private $array;
21
22
    /**
23
     * @var array|Service
24
     */
25
    private $services = array();
26
27
    /**
28
     * Services constructor.
29
     *
30
     * @param array $array
31
     */
32 3
    public function __construct(array $array)
33
    {
34 3
        $this->parseServices($array);
35
36 2
        $this->array = $array;
37 2
    }
38
39
    /**
40
     * @return int
41
     */
42 1
    public function count()
43
    {
44 1
        $count = count($this->services);
0 ignored issues
show
Bug introduced by
It seems like $this->services can also be of type Ktomk\Pipelines\File\Definitions\Service; however, parameter $var of count() does only seem to accept Countable|array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

44
        $count = count(/** @scrutinizer ignore-type */ $this->services);
Loading history...
45
46
        // special docker service does not count
47 1
        isset($this->services['docker']) && $count--;
48
49 1
        return $count;
50
    }
51
52
    /**
53
     * @param array $array
54
     *
55
     * @return void
56
     */
57 3
    private function parseServices(array $array)
58
    {
59 3
        foreach ($array as $name => $service) {
60 2
            if (!is_string($name)) {
61 1
                throw new ParseException(sprintf('Invalid service definition name: %s', var_export($name, true)));
62
            }
63 1
            $this->services[$name] = $this->parseNamedService($name, $service);
64
        }
65 2
    }
66
67
    /**
68
     * @param string $name
69
     * @param array $service
70
     *
71
     * @return Service
72
     */
73 1
    private function parseNamedService($name, array $service)
74
    {
75 1
        return new Service($name, $service);
76
    }
77
}
78