DeviceSpecification::getOptionalServices()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: sheldon
5
 * Date: 18-6-8
6
 * Time: 下午3:43.
7
 */
8
9
namespace MiotApi\Contract\Specification;
10
11
/**
12
 * 设备是一个独立的有意义的设备,比如:灯泡、插座、风扇。
13
 * 描述一个设备,需要说清楚:是什么设备?有哪些服务可用?
14
 *
15
 * Class DeviceSpecification
16
 */
17
class DeviceSpecification extends Specification
18
{
19
    /**
20
     * 必选服务
21
     *
22
     * @var
23
     */
24
    protected $requiredServices;
25
26
    /**
27
     * 可选服务
28
     *
29
     * @var
30
     */
31
    protected $optionalServices;
32
33
    /**
34
     * @throws \MiotApi\Exception\SpecificationErrorException
35
     */
36
    public function init()
37
    {
38
        parent::init();
39
40
        if ($this->has('required-services')) {
0 ignored issues
show
Bug introduced by
The method has() does not exist on MiotApi\Contract\Specification\DeviceSpecification. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

40
        if ($this->/** @scrutinizer ignore-call */ has('required-services')) {
Loading history...
41
            $requiredServices = $this->__get('required-services');
42
            if (!empty($requiredServices)) {
43
                foreach ($requiredServices as $index => $service) {
44
                    $this->requiredServices[] = new ServiceSpecification($service);
45
                }
46
            }
47
        }
48
49
        if ($this->has('required-services')) {
50
            $optionalServices = $this->__get('optional-services');
51
            if (!empty($optionalServices)) {
52
                foreach ($optionalServices as $index => $service) {
53
                    $this->optionalServices[] = new ServiceSpecification($service);
54
                }
55
            }
56
        }
57
    }
58
59
    /**
60
     * 获取 必选服务
61
     *
62
     * @return mixed
63
     */
64
    public function getRequiredServices()
65
    {
66
        return $this->requiredServices;
67
    }
68
69
    /**
70
     * 获取 可选服务
71
     *
72
     * @return mixed
73
     */
74
    public function getOptionalServices()
75
    {
76
        return $this->optionalServices;
77
    }
78
}
79