PushAddress::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
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