Point   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 13
c 3
b 0
f 0
lcom 1
cbo 0
dl 0
loc 89
ccs 0
cts 34
cp 0
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 23 6
A __toString() 0 4 1
A getLatitude() 0 4 1
A getLongitude() 0 4 1
A getType() 0 4 1
A getAddress() 0 4 1
A getKey() 0 9 2
1
<?php
2
/**
3
 *
4
 * PHP version 5.5
5
 *
6
 * @package Forecast\Helper
7
 * @author  Sergey V.Kuzin <[email protected]>
8
 * @license MIT
9
 */
10
declare(strict_types=1);
11
namespace Forecast\Helper;
12
13
14
class Point
15
{
16
    const ADDRESS = 1;
17
    const POINT = 2;
18
    protected $latitude;
19
    protected $longitude;
20
    protected $address;
21
22
    protected $type = 0;
23
24
    /**
25
     * @api
26
     */
27
    public function __construct()
28
    {
29
        $numargs = func_num_args();
30
        if ($numargs > 2) {
31
            throw new \InvalidArgumentException('Ожидалось 1 или 2 параметра');
32
        } elseif ($numargs == 2) {
33
            $arg1 = func_get_arg(0);
34
            $arg2 = func_get_arg(1);
35
            if (is_double($arg1) && is_double($arg2)) {
36
                $this->latitude = $arg1;
37
                $this->longitude = $arg2;
38
                $this->type = self::POINT;
39
            } else {
40
                throw new \InvalidArgumentException();
41
            }
42
        } else {
43
            $arg1 = func_get_arg(0);
44
            if (is_string($arg1)) {
45
                $this->address = $arg1;
46
                $this->type = self::ADDRESS;
47
            }
48
        }
49
    }
50
51
    public function __toString(): string
52
    {
53
        return (string)$this->getLatitude() . ',' . $this->getLongitude();
54
    }
55
56
    /**
57
     * @api
58
     * @return float
59
     */
60
    public function getLatitude(): float
61
    {
62
        return $this->latitude;
63
    }
64
65
    /**
66
     * @api
67
     * @return float
68
     */
69
    public function getLongitude(): float
70
    {
71
        return $this->longitude;
72
    }
73
74
    /**
75
     * @api
76
     * @return int
77
     */
78
    public function getType(): int
79
    {
80
        return $this->type;
81
    }
82
83
    /**
84
     * @api
85
     * @return string
86
     */
87
    public function getAddress(): string
88
    {
89
        return $this->address;
90
    }
91
92
    public function getKey(): string
93
    {
94
        if ($this->type == self::ADDRESS) {
95
            return md5($this->address);
96
        } else {
97
            return md5($this->latitude . '-' . $this->longitude);
98
        }
99
100
    }
101
102
}
103