api_parameters::getAcceptedParameters()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 8
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
/* zKillboard
3
 * Copyright (C) 2012-2015 EVE-KILL Team and EVSCO.
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU Affero General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU Affero General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU Affero General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
class api_parameters implements apiEndpoint
20
{
21
	public function getDescription()
22
	{
23
		return array("type" => "description", "message" =>
24
				"Lists the parameters accepted by an endpoint."
25
			);
26
	}
27
28
	public function getAcceptedParameters()
29
	{
30
		return array("type" => "parameters", "parameters" =>
31
			array(
32
				"/api/parameters/<endPoint>/" => "Lists the parameters accepted by an endpoint."
33
			)
34
		);
35
	}
36
	public function execute($parameters)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
37
	{
38
		$endPoint = isset($parameters["parameters"]) ? $parameters["parameters"] : NULL;
39
40
		if(!$endPoint)
41
			return array(
42
				"type" => "error",
43
				"message" => "No endpoint selected"
44
			);
45
46
		try
47
		{
48
			$fileName = __DIR__ . "/$endPoint.php";
49
			if(!file_exists($fileName))
50
				throw new Exception();
51
52
			require_once $fileName;
53
			$className = "api_$endPoint";
54
			$class = new $className();
55
56
			if(!is_a($class, "apiEndpoint"))
57
			{
58
				$data = array(
59
					"type" => "error",
60
					"message" => "Endpoint does not implement apiEndpoint"
61
				);
62
			}
63
64
			$data = $class->getAcceptedParameters();
65
		}
66
		catch (Exception $e)
67
		{
68
			$data = array(
69
				"type" => "error",
70
				"message" => "$endpoint ended with error: " . $e->getMessage()
0 ignored issues
show
Bug introduced by
The variable $endpoint does not exist. Did you mean $endPoint?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
71
			);
72
		}
73
74
		return $data;
75
	}
76
}
77