@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * @param ResponseFactory $responseFactory |
44 | 44 | * @param EndpointFactory $endpointFactory |
45 | 45 | */ |
46 | - public function __construct(AccessControl $accessControl, Throttle $throttle, ResponseFactory $responseFactory, EndpointFactory $endpointFactory){ |
|
46 | + public function __construct(AccessControl $accessControl, Throttle $throttle, ResponseFactory $responseFactory, EndpointFactory $endpointFactory) { |
|
47 | 47 | $this->accessControl = $accessControl; |
48 | 48 | $this->throttle = $throttle; |
49 | 49 | $this->responseFactory = $responseFactory; |
@@ -66,11 +66,11 @@ discard block |
||
66 | 66 | |
67 | 67 | $endpoint = $this->endpointFactory->getEndpoint($request->getEndpoint(), $request->getVersion()); |
68 | 68 | |
69 | - if($this->throttle->shouldThrottle($request)) { |
|
69 | + if ($this->throttle->shouldThrottle($request)) { |
|
70 | 70 | throw new ThrottleLimitExceededException('Request limit exceeded'); |
71 | 71 | } |
72 | 72 | |
73 | - if(!$this->accessControl->validateAccess($request)) { |
|
73 | + if (!$this->accessControl->validateAccess($request)) { |
|
74 | 74 | throw new AccessDeniedException("API key does not have the required permissions to access requested resource"); |
75 | 75 | } |
76 | 76 | |
@@ -85,8 +85,8 @@ discard block |
||
85 | 85 | * @param Request $request |
86 | 86 | * @throws InvalidAPIKeyException |
87 | 87 | */ |
88 | - protected function validateKey(Request $request){ |
|
89 | - if(!$this->accessControl->validateKey($request->getApiKey())){ |
|
88 | + protected function validateKey(Request $request) { |
|
89 | + if (!$this->accessControl->validateKey($request->getApiKey())) { |
|
90 | 90 | throw new InvalidAPIKeyException('Invalid API key'); |
91 | 91 | } |
92 | 92 | } |
@@ -97,8 +97,8 @@ discard block |
||
97 | 97 | */ |
98 | 98 | protected function validateExtension(Request $request) { |
99 | 99 | $formats = $this->responseFactory->getSupportedTypes(); |
100 | - if(!$formats || !in_array($request->getExtension(), $formats)){ |
|
101 | - throw new UnknownResponseTypeException('Unknown response format: ' . $request->getExtension()); |
|
100 | + if (!$formats || !in_array($request->getExtension(), $formats)) { |
|
101 | + throw new UnknownResponseTypeException('Unknown response format: '.$request->getExtension()); |
|
102 | 102 | } |
103 | 103 | } |
104 | 104 |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | $router = new \LunixREST\Router\Router($accessControl, $throttle, $responseFactory, $endpointFactory); |
11 | 11 | |
12 | 12 | try { |
13 | - $request = \LunixREST\Request\Request::createFromURL("GET", [], [], '127.0.0.1', "/1/123456/phonenumbers/6517855237.json");// \LunixREST\Request\Request::createFromURL($_SERVER['REQUEST_METHOD'], getallheaders(), $_REQUEST, $_SERVER['REMOTE_ADDR'], $_SERVER['REQUEST_URI']); |
|
13 | + $request = \LunixREST\Request\Request::createFromURL("GET", [], [], '127.0.0.1', "/1/123456/phonenumbers/6517855237.json");// \LunixREST\Request\Request::createFromURL($_SERVER['REQUEST_METHOD'], getallheaders(), $_REQUEST, $_SERVER['REMOTE_ADDR'], $_SERVER['REQUEST_URI']); |
|
14 | 14 | |
15 | 15 | try { |
16 | 16 | $response = $router->route($request); |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | header('500 Internal Server Error', true, 500); |
30 | 30 | } |
31 | 31 | } catch(\LunixREST\Exceptions\InvalidRequestFormatException $e){ |
32 | - header('400 Bad Request', 400); |
|
32 | + header('400 Bad Request', 400); |
|
33 | 33 | } catch(Exception|Error $e){ |
34 | - header('500 Internal Server Error', true, 500); |
|
34 | + header('500 Internal Server Error', true, 500); |
|
35 | 35 | } |
@@ -23,7 +23,7 @@ |
||
23 | 23 | header('404 Not Found', true, 404); |
24 | 24 | } catch(\LunixREST\Exceptions\AccessDeniedException $e){ |
25 | 25 | header('403 Access Denied', true, 403); |
26 | - } catch(\LunixREST\Exceptions\ThrottleLimitExceededException $e){ |
|
26 | + } catch(\LunixREST\Exceptions\ThrottleLimitExceededException $e){ |
|
27 | 27 | header('429 Too Many Requests', true, 429); |
28 | 28 | } catch(Exception|Error $e){ |
29 | 29 | header('500 Internal Server Error', true, 500); |
@@ -9,26 +9,26 @@ |
||
9 | 9 | $router = new \LunixREST\Router\Router($accessControl, $throttle, $responseFactory, $endpointFactory); |
10 | 10 | |
11 | 11 | try { |
12 | - $request = \LunixREST\Request\Request::createFromURL("GET", [], [], '127.0.0.1', "/1/123456/phonenumbers/6517855237.json");// \LunixREST\Request\Request::createFromURL($_SERVER['REQUEST_METHOD'], getallheaders(), $_REQUEST, $_SERVER['REMOTE_ADDR'], $_SERVER['REQUEST_URI']); |
|
12 | + $request = \LunixREST\Request\Request::createFromURL("GET", [], [], '127.0.0.1', "/1/123456/phonenumbers/6517855237.json"); // \LunixREST\Request\Request::createFromURL($_SERVER['REQUEST_METHOD'], getallheaders(), $_REQUEST, $_SERVER['REMOTE_ADDR'], $_SERVER['REQUEST_URI']); |
|
13 | 13 | |
14 | 14 | try { |
15 | 15 | $response = $router->route($request); |
16 | 16 | echo $response->getAsString(); |
17 | - } catch(\LunixREST\Exceptions\InvalidAPIKeyException $e){ |
|
17 | + } catch (\LunixREST\Exceptions\InvalidAPIKeyException $e) { |
|
18 | 18 | header('400 Bad Request', true, 400); |
19 | - } catch(\LunixREST\Endpoint\Exceptions\UnknownEndpointException $e){ |
|
19 | + } catch (\LunixREST\Endpoint\Exceptions\UnknownEndpointException $e) { |
|
20 | 20 | header('404 Not Found', true, 404); |
21 | - } catch(\LunixREST\Response\Exceptions\UnknownResponseTypeException $e){ |
|
21 | + } catch (\LunixREST\Response\Exceptions\UnknownResponseTypeException $e) { |
|
22 | 22 | header('404 Not Found', true, 404); |
23 | - } catch(\LunixREST\Exceptions\AccessDeniedException $e){ |
|
23 | + } catch (\LunixREST\Exceptions\AccessDeniedException $e) { |
|
24 | 24 | header('403 Access Denied', true, 403); |
25 | - } catch(\LunixREST\Exceptions\ThrottleLimitExceededException $e){ |
|
25 | + } catch (\LunixREST\Exceptions\ThrottleLimitExceededException $e) { |
|
26 | 26 | header('429 Too Many Requests', true, 429); |
27 | - } catch(Exception $e){ |
|
27 | + } catch (Exception $e) { |
|
28 | 28 | header('500 Internal Server Error', true, 500); |
29 | 29 | } |
30 | -} catch(\LunixREST\Exceptions\InvalidRequestFormatException $e){ |
|
30 | +} catch (\LunixREST\Exceptions\InvalidRequestFormatException $e) { |
|
31 | 31 | header('400 Bad Request', 400); |
32 | -} catch(Exception $e){ |
|
32 | +} catch (Exception $e) { |
|
33 | 33 | header('500 Internal Server Error', true, 500); |
34 | 34 | } |
@@ -20,7 +20,7 @@ |
||
20 | 20 | * @throws UnknownEndpointException |
21 | 21 | */ |
22 | 22 | public function getEndpoint(string $name, string $version): Endpoint { |
23 | - $className = $this->buildVersionedEndpointNamespace($version) . $name; |
|
23 | + $className = $this->buildVersionedEndpointNamespace($version).$name; |
|
24 | 24 | return new $className($this->entityManager); |
25 | 25 | } |
26 | 26 | } |
@@ -17,5 +17,5 @@ |
||
17 | 17 | $helloWorld = new \HelloWorld\Models\HelloWorld(); |
18 | 18 | |
19 | 19 | return $helloWorld; |
20 | - } |
|
20 | + } |
|
21 | 21 | } |
@@ -21,7 +21,7 @@ |
||
21 | 21 | * @throws UnknownEndpointException |
22 | 22 | */ |
23 | 23 | public function getEndpoint(string $name, string $version): Endpoint { |
24 | - switch($version) { |
|
24 | + switch ($version) { |
|
25 | 25 | case "1": |
26 | 26 | switch (strtolower($name)) { |
27 | 27 | case "phonenumbers": |
@@ -20,6 +20,6 @@ |
||
20 | 20 | |
21 | 21 | |
22 | 22 | public function get(Request $request): ResponseData{ |
23 | - return $this->geoPhone->lookupNumber($request->getInstance()); |
|
24 | - } |
|
23 | + return $this->geoPhone->lookupNumber($request->getInstance()); |
|
24 | + } |
|
25 | 25 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | /** |
15 | 15 | * @param string $filename |
16 | 16 | */ |
17 | - public function __construct($filename = 'data.csv'){ |
|
17 | + public function __construct($filename = 'data.csv') { |
|
18 | 18 | $this->fileHandle = fopen($filename, 'r'); |
19 | 19 | } |
20 | 20 | |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | $nextThree = substr($phoneNumber, 3, 3); |
30 | 30 | |
31 | 31 | while (($data = fgetcsv($this->fileHandle)) !== FALSE) { |
32 | - if($areaCode == $data[0] && $nextThree == $data[1]){ |
|
32 | + if ($areaCode == $data[0] && $nextThree == $data[1]) { |
|
33 | 33 | return new LookupResponse($data[2], $data[3]); |
34 | 34 | } |
35 | 35 | } |
@@ -22,8 +22,8 @@ discard block |
||
22 | 22 | * @throws UnknownEndpointException |
23 | 23 | */ |
24 | 24 | public function getEndpoint(string $name, string $version): Endpoint { |
25 | - $className = $this->buildVersionedEndpointNamespace($version) . $name; |
|
26 | - if(!class_exists($className)){ |
|
25 | + $className = $this->buildVersionedEndpointNamespace($version).$name; |
|
26 | + if (!class_exists($className)) { |
|
27 | 27 | throw new UnknownEndpointException("Could not find $className"); |
28 | 28 | } |
29 | 29 | |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | $classesInNamespace = []; |
40 | 40 | |
41 | 41 | $namespace = $this->buildVersionedEndpointNamespace($version); |
42 | - foreach(get_declared_classes() as $name) { |
|
42 | + foreach (get_declared_classes() as $name) { |
|
43 | 43 | if (strpos($name, $namespace) === 0) { |
44 | 44 | $classesInNamespace[] = $name; |
45 | 45 | } |
@@ -49,6 +49,6 @@ discard block |
||
49 | 49 | } |
50 | 50 | |
51 | 51 | protected function buildVersionedEndpointNamespace(string $version): string { |
52 | - return $this->endpointNamespace . '\v' . str_replace('.', '_', $version) . '\\'; |
|
52 | + return $this->endpointNamespace.'\v'.str_replace('.', '_', $version).'\\'; |
|
53 | 53 | } |
54 | 54 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | */ |
15 | 15 | public function parse(string $url): ParsedURL { |
16 | 16 | $splitURL = explode('/', trim($url, '/')); |
17 | - if(count($splitURL) < 3){ |
|
17 | + if (count($splitURL) < 3) { |
|
18 | 18 | throw new InvalidRequestURLException(); |
19 | 19 | } |
20 | 20 | //Find endpoint |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | |
28 | 28 | $instance = null; |
29 | 29 | |
30 | - if(count($splitURL) == 4){ |
|
30 | + if (count($splitURL) == 4) { |
|
31 | 31 | $instance = implode('.', $splitExtension); |
32 | 32 | } else { |
33 | 33 | $endpoint = implode('.', $splitExtension); |