Passed
Branch feature/tell-dont-ask/master (82958c)
by Simone
02:17
created

Service::methods()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 0
crap 2
1
<?php
2
3
namespace Sensorario\Container\Objects;
4
5
class Service
6
{
7
    private $params;
8
9 6
    private function __construct(array $params)
10
    {
11 6
        $this->params = $params;
12 6
    }
13
14 6
    public static function box(array $params) : self
15
    {
16 6
        return new self($params);
17
    }
18
19 6
    public function hasParams() : bool
20
    {
21 6
        return isset($this->params['services'][$this->name()]['params']);
22
    }
23
24 6
    public function params() : array
25
    {
26 6
        return $this->hasParams()
27 2
            ? $this->params['services'][$this->name()]['params']
28 6
            : [];
29
    }
30
31 6
    public function hasMethods() : bool
32
    {
33 6
        return isset($this->params['services'][$this->name()]['methods']);
34
    }
35
36 6
    public function methods() : array
37
    {
38 6
        return $this->hasMethods()
39 2
            ? $this->params['services'][$this->name()]['methods']
40 6
            : [];
41
    }
42
43
    public function class() : string
0 ignored issues
show
Coding Style introduced by
Possible parse error: non-abstract method defined as abstract
Loading history...
44
    {
45
        $argument = Argument::fromString($this->params['name']);
0 ignored issues
show
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
Coding Style introduced by
The visibility should be declared for property $argument.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
46
        $serviceName = $argument->name();
0 ignored issues
show
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
Coding Style introduced by
The visibility should be declared for property $serviceName.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
47
        return $this->params['services'][$serviceName]['class'];
0 ignored issues
show
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
Coding Style introduced by
The visibility should be declared for property $this.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
48
    }
49
50 2
    public function getServicesConfiguration() : array
51
    {
52 2
        return $this->params['services'];
53
    }
54
55 6
    public function name() : string
56
    {
57 6
        return $this->params['name'];
58
    }
59
60 6
    public function hasMethodInjection() : bool
61
    {
62 6
        return [] == $this->methods()
63 6
            && [] != $this->params();
64
    }
65
66 6
    public function hasSimpleInjection() : bool
67
    {
68 6
        return [] != $this->methods()
69 6
            && [] == $this->params();
70
    }
71
72 6
    public function classNotExists() : bool
73
    {
74 6
        return !class_exists($this->class());
75
    }
76
}
77