PushAddress   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 0
cbo 1
dl 0
loc 41
ccs 15
cts 15
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A setAddress() 0 16 4
1
<?php
2
3
namespace PHPushbullet\Request;
4
5
class PushAddress extends Request
6
{
7
    /**
8
     * The type according to the Pushbullet API
9
     *
10
     * @var string $type
11
     */
12
13
    protected $type = 'address';
14
15 2
    public function __construct($name, $address)
16
    {
17 2
        $this->parameters['name']    = $name;
18 2
        $this->parameters['address'] = $this->setAddress($address);
19 2
    }
20
21
    /**
22
     * The address can either be a string or an array,
23
     * make sure it's a string in the end
24
     *
25
     * @param string|array $address
26
     * @return string
27
     */
28
29 2
    protected function setAddress($address)
30
    {
31 2
        if (is_array($address)) {
32 1
            $new_address = [];
33
34 1
            foreach (['address', 'city', 'state', 'zip'] as $field) {
35 1
                if (array_key_exists($field, $address)) {
36 1
                    $new_address[] = $address[$field];
37 1
                }
38 1
            }
39
40 1
            $address = implode(' ', $new_address);
41 1
        }
42
43 2
        return $address;
44
    }
45
}
46