Passed
Push — master ( 1b8175...e65fee )
by Nico
02:12
created

CoC_Clan::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
/**
4
 * Class to get information about Clans. This class uses the data provided by the API.class.php
5
 */
6
7
class CoC_Clan
8
{
9
	protected $api;
10
	protected $tag; 
11
	protected $clan = NULL;
12
13
	/**
14
	 * Constructor of CoC_Clan
15
	 * 
16
	 * @param $tag, clantag as string (including #)
17
	 */
18
	public function __construct($tag) 
19
	{
20
		$this->api = new ClashOfClans();
21
		$this->tag = $tag;
22
		$this->getClan();
23
   	}
24
	
25
   	protected function getClan()
26
   	{
27
   		if($this->clan == NULL)
28
		{
29
			$this->clan = $this->api->getClanByTag($this->tag);
30
		}
31
		return $this->clan;
32
   	}
33
34
	/**
35
	 * Gets the clantag
36
	 *
37
	 * @return string, clantag
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...
38
	 */
39
   	public function getTag()
40
   	{
41
   		return $this->tag;
42
   	}
43
44
   	/**
45
   	 * Gets the clan's name
46
   	 *
47
   	 * @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...
48
   	 */
49
	public function getName()
50
	{
51
		return $this->getClan()->name;
52
	}
53
54
	/**
55
	 * Gets the clan's description
56
	 *
57
	 * @return string, description
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...
58
	 */
59
	public function getDescription()
60
	{
61
		return $this->getClan()->description;
62
	}
63
64
	/**
65
	 * Gets the clan's type
66
	 *
67
	 * @return string, type ("open", "inviteOnly" or "closed")
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...
68
	 */
69
	public function getType()
70
	{
71
		return $this->getClan()->type;
72
	}
73
74
	/**
75
	 * Gets the clan's location ID. You can get more information about a location using the Location.class.php
76
	 *
77
	 * @return int, locationId
0 ignored issues
show
Documentation introduced by
The doc-type int, could not be parsed: Expected "|" or "end of type", but got "," at position 3. (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...
78
	 */
79
	public function getLocationId()
80
	{
81
		return $this->getClan()->location->id;
82
	}
83
84
	/**
85
	 * Get's the URL to the clan badge in the given size.
86
	 * 
87
	 * @param (optional) $size ("small", "medium", "large")
88
	 * @return string, URL to the picture
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...
89
	 */
90
	public function getBadgeUrl($size = "") //small, large, medium.
91
	{
92
		switch ($size)
93
		{
94
			case "small":
95
				return $this->getClan()->badgeUrls->small; 
96
				break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
97
			case "medium":
98
				return $this->getClan()->badgeUrls->medium;
99
				break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
100
			case "large":
101
				return $this->getClan()->badgeUrls->large;
102
				break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
103
			default:
104
				return $this->getClan()->badgeUrls->large; //return the largest because it can be resized using HTML
105
				break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
106
		}
107
		
108
	}
109
110
	/**
111
	 * Gets the clan's war frequency
112
	 *
113
	 * @return string, war-frequency ("always", "lessThanOncePerWeek", "once per week", "moreThanOncePerWeek" or "unknown")
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...
114
	 */
115
	public function getWarFrequency()
116
	{
117
		return $this->getClan()->warFrequency;
118
	}
119
120
	/**
121
	 * Gets the clan's level
122
	 *
123
	 * @return int, level
0 ignored issues
show
Documentation introduced by
The doc-type int, could not be parsed: Expected "|" or "end of type", but got "," at position 3. (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...
124
	 */
125
	public function getLevel()
126
	{
127
		return $this->getClan()->clanLevel;
128
	}
129
130
	/**
131
	 * Gets the clan's war wins
132
	 *
133
	 * @return int, wins
0 ignored issues
show
Documentation introduced by
The doc-type int, could not be parsed: Expected "|" or "end of type", but got "," at position 3. (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...
134
	 */
135
	public function getWarWins()
136
	{
137
		return $this->getClan()->warWins;
138
	}
139
140
	/**
141
	 * Gets the clan's points (trophies)
142
	 *
143
	 * @return int, points
0 ignored issues
show
Documentation introduced by
The doc-type int, could not be parsed: Expected "|" or "end of type", but got "," at position 3. (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...
144
	 */
145
	public function getPoints()
146
	{
147
		return $this->getClan()->clanPoints;
148
	}
149
150
	/**
151
	 * Gets the clan's required trophies to join
152
	 *
153
	 * @return int, required trophies
0 ignored issues
show
Documentation introduced by
The doc-type int, could not be parsed: Expected "|" or "end of type", but got "," at position 3. (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...
154
	 */
155
	public function getRequiredTrophies()
156
	{
157
		return $this->getClan()->requiredTrophies;
158
	}
159
160
	/**
161
	 * Gets the amount of members in the clan
162
	 *
163
	 * @return int, membercount
0 ignored issues
show
Documentation introduced by
The doc-type int, could not be parsed: Expected "|" or "end of type", but got "," at position 3. (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...
164
	 */
165
	public function getMemberCount()
166
	{
167
		return $this->getClan()->members;
168
	}
169
170
	/**
171
	 * Gets a member from the clan by providing an index (usually clan-ranklist position - 1)
172
	 * Member.class.php will work with the returned class.
173
	 *
174
	 * @return stdClass, member
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...
175
	 */
176
	public function getMemberByIndex($index)
177
	{
178
		return $this->getClan()->memberList[$index];
179
	}
180
181
	/**
182
	 * Gets an array of all members in the clan
183
	 *
184
	 * @return array (type of stdClass), all members
185
	 */
186
	public function getAllMembers()
187
	{
188
		return $this->getClan()->memberList;
189
	}
190
191
	/**
192
	 * Gets the first(!) member with the given name
193
	 * If there are multiple members using the same name inside the clan, use a different method.
194
	 *
195
	 * @return stdClass, member
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...
196
	 */
197
	public function getMemberByName($name)
198
	{
199
		foreach ($this->api->getClan()->memberList as $member)
0 ignored issues
show
Bug introduced by
The method getClan() does not exist on ClashOfClans. Did you maybe mean getClanByTag()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
200
		{
201
			if ($member->name == $name)
202
			{
203
				return $member;
204
			}
205
		}
206
		return 0;
207
	} 
208
};