DarkSkyUmbrella::input()   B
last analyzed

Complexity

Conditions 10
Paths 6

Size

Total Lines 34
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 24
CRAP Score 10

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 34
ccs 24
cts 24
cp 1
rs 7.6666
c 0
b 0
f 0
cc 10
nc 6
nop 4
crap 10

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace KW\Models;
4
5
class DarkSkyUmbrella
6
{
7
8
    /**
9
    * @var array $wobj array med info om ett ipnummer, koordinater samt ev väderresultat
10
    */
11
12
    public $wobj = array(
13
        "ip"=>"",
14
        "valid"=>false,
15
        "type" => "",
16
        "latitude" => 0,
17
        "longitude" => 0,
18
        "city"=>"",
19
        "country"=>"",
20
        "weatherresult"=>[]
21
    );
22
23 7
    public function __construct($di)
24
    {
25 7
        $this->di = $di;
0 ignored issues
show
Bug Best Practice introduced by
The property di does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
26 7
        $this->ipValidate = new IpValidate($this->di);
0 ignored issues
show
Bug Best Practice introduced by
The property ipValidate does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
Unused Code introduced by
The call to KW\Models\IpValidate::__construct() has too many arguments starting with $this->di. ( Ignorable by Annotation )

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

26
        $this->ipValidate = /** @scrutinizer ignore-call */ new IpValidate($this->di);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
27 7
        $this->ipDomainname = new IpDomainname($this->di);
0 ignored issues
show
Bug Best Practice introduced by
The property ipDomainname does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
Unused Code introduced by
The call to KW\Models\IpDomainname::__construct() has too many arguments starting with $this->di. ( Ignorable by Annotation )

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

27
        $this->ipDomainname = /** @scrutinizer ignore-call */ new IpDomainname($this->di);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
28 7
        $this->ipCheckCoordinates = new IpCheckCoordinates($this->di);
0 ignored issues
show
Bug Best Practice introduced by
The property ipCheckCoordinates does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
29 7
        $this->osmr = new OpenStreetMapReverse($this->di);
0 ignored issues
show
Bug Best Practice introduced by
The property osmr does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
30 7
        $this->darkSky = new DarkSky($this->di);
0 ignored issues
show
Bug Best Practice introduced by
The property darkSky does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
31 7
    }
32
33
    /**
34
     * Get url-type according to type and position to send to Dark Sky
35
     *
36
     * @return array
37
     */
38 7
    public function input($longitude, $latitude, $type, $ipn)
39
    {
40 7
        if (abs($longitude) >= 180 or abs($latitude) >= 90) {
41 1
            $this->wobj["error"] = "Du angav in felaktiga kooridnater!";
42 1
            return $this->wobj;
43
        };
44 6
        $this->wobj["type"] = $type;
45 6
        if ($ipn != "") {
46 3
            $this->wobj["valid"] = $this->ipValidate->validate($ipn);
47
48 3
            if ($this->wobj["valid"]) {
49 2
                list($this->wobj["latitude"], $this->wobj["longitude"],
50 2
                    $this->wobj["country"], $this->wobj["city"])
51 2
                    = $this->ipCheckCoordinates->ipCheckCoordinates($ipn);
52 2
                if ($this->wobj["country"] == "" and $this->wobj["latitude"] == 0 and $this->wobj["latitude"] == 0) {
53 1
                    $this->wobj["error"] = "Ip-adressen matchar ingen geografisk plats. Denna vädertjänst redovisar inga cyberväder";
54 2
                    return $this->wobj;
55
                }
56
            } else {
57 1
                $this->wobj["error"] = "Du angav en felaktig ip-adress!";
58 2
                return $this->wobj;
59
            }
60
        } else {
61 3
            if ($longitude == "" or $latitude == "") {
62 1
                $this->wobj["error"] = "Du måste ange korrekt longitud och latitud om ipnummer ej anges!";
63 1
                return $this->wobj;
64
            }
65 2
            $this->wobj["latitude"]= $latitude;
66 2
            $this->wobj["longitude"] = $longitude;
67 2
            list($this->wobj["country"], $this->wobj["city"]) = $this->osmr->osmCheckCoordinates($longitude, $latitude);
68
        }
69 3
        $this->wobj["weatherresult"] = $this->darkSky->weather($this->wobj["longitude"], $this->wobj["latitude"], $type);
70
71 3
        return $this->wobj;
72
    }
73
}
74