CoC_Location::getLocationId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
class CoC_Location
4
{
5
	protected $api;
6
	protected $locationId;
7
	protected $location = NULL;
8
    
9
	/**
10
	 * Constructor of CoC_Location
11
	 * 
12
	 * @param $locationId
13
	 */
14
	public function __construct($location)
15
	{
16
		$this->api = new ClashOfClans();
17
		if(is_object($location))
18
		{
19
			$this->location = $location;
20
		}
21
		else
22
		{
23
			$this->locationId = $location;
24
			$this->getLocation();
25
		}
26
	}
27
    
28
	/**
29
	 * Gets an stdClass containing location-information
30
	 *
31
	 * @return stdClass, location
0 ignored issues
show
Documentation introduced by
The doc-type stdClass, could not be parsed: Expected "|" or "end of type", but got "," at position 8. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
32
	 */
33
	protected function getLocation()
34
	{
35
		if($this->location == NULL)
36
		{
37
			foreach ($this->api->getLocationList()->items as $location) 
38
			{
39
				if ($location->id == $this->locationId) 
40
				{
41
					$this->location = $location;
42
					return $this->location;
43
				}
44
			}
45
			return 0;
46
		}
47
		else
48
		{
49
			return $this->location;
50
		}
51
	}
52
    
53
	/**
54
	 * Sets the location by providing it's exact name
55
	 *
56
	 * @param string, location name
57
	 * @return bool, success or fail
0 ignored issues
show
Documentation introduced by
The doc-type bool, could not be parsed: Expected "|" or "end of type", but got "," at position 4. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
58
	 */
59 View Code Duplication
	public function setLocationByName($name)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
60
	{
61
		foreach ($this->api->getLocationList()->items as $location) 
62
		{
63
			if ($location->name == $name) 
64
			{
65
				$this->locationId = $location->id;
66
				$this->location = $location;
67
				return 1;
68
			}
69
		}
70
		return 0;
71
	}
72
73
	/**
74
	 * Sets the location by providing it's country code
75
	 *
76
     * @param string
77
     * @return bool
78
     */
79 View Code Duplication
	public function setLocationByCode($cc)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
80
	{
81
		foreach ($this->api->getLocationList()->items as $location) 
82
		{
83
			if ($location->countryCode == $cc) 
84
			{
85
				$this->locationId = $location->id;
86
				$this->location = $location;
87
				return 1;
88
			}
89
		}
90
		return 0;
91
	}
92
93
	/**
94
	 * Gets the location ID
95
	 *
96
	 * @return int
97
	 */
98
	public function getLocationId()
99
	{
100
		return $this->getLocation()->id;
101
	}
102
103
	/**
104
	 * Gets the location name
105
	 *
106
	 * @return string, name
0 ignored issues
show
Documentation introduced by
The doc-type string, could not be parsed: Expected "|" or "end of type", but got "," at position 6. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
107
	 */
108
	public function getLocationName()
109
	{
110
		return $this->getLocation()->name;
111
	}
112
113
	/**
114
	 * Check whether the given location is a country or a region
115
	 *
116
	 * @return bool
117
	 */
118
	public function isCountry()
119
	{
120
		return $this->getLocation()->isCountry;
121
	}
122
123
	/**
124
	 * Gets the country code for the given location
125
	 *
126
	 * @return string, country code
0 ignored issues
show
Documentation introduced by
The doc-type string, could not be parsed: Expected "|" or "end of type", but got "," at position 6. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
127
	 */
128
	public function getCountryCode()
129
	{
130
		if($this->isCountry())
131
		{
132
			return $this->getLocation()->countryCode;
133
		}
134
		else
135
		{
136
			return "nA";
137
		}
138
	}
139
}
140
141
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...