GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

BulbFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 49
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 11 1
A extractIpAndPort() 0 6 1
1
<?php
2
3
namespace Yeelight\Bulb;
4
5
use Socket\Raw\Factory;
6
7
class BulbFactory
8
{
9
    const LOCATION = 'Location';
10
    const ID = 'id';
11
12
    /**
13
     * @var Factory
14
     */
15
    private $socketFactory;
16
17
    /**
18
     * BulbFactory constructor.
19
     *
20
     * @param Factory $socketFactory
21
     */
22
    public function __construct(Factory $socketFactory)
23
    {
24
        $this->socketFactory = $socketFactory;
25
    }
26
27
    /**
28
     * @param array $data
29
     *
30
     * @return Bulb
31
     */
32
    public function create(array $data): Bulb
33
    {
34
        list($ip, $port) = $this->extractIpAndPort($data[self::LOCATION]);
35
36
        return new Bulb(
37
            $this->socketFactory->createTcp4(),
38
            $ip,
39
            (int) $port,
40
            trim($data[self::ID])
41
        );
42
    }
43
44
    /**
45
     * @param string $location
46
     *
47
     * @return array
48
     */
49
    private function extractIpAndPort(string $location): array
50
    {
51
        $address = explode('yeelight://', $location);
52
53
        return explode(':', end($address));
54
    }
55
}
56