@@ -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 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | /** |
| 22 | 22 | * @param EndpointFactory $endpointFactory |
| 23 | 23 | */ |
| 24 | - public function __construct(EndpointFactory $endpointFactory){ |
|
| 24 | + public function __construct(EndpointFactory $endpointFactory) { |
|
| 25 | 25 | $this->endpointFactory = $endpointFactory; |
| 26 | 26 | } |
| 27 | 27 | |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | * @throws MethodNotFoundException |
| 44 | 44 | */ |
| 45 | 45 | protected function executeEndpoint(Endpoint $endpoint, Request $request): ResponseData { |
| 46 | - if(!method_exists($endpoint, $request->getMethod())){ |
|
| 46 | + if(!method_exists($endpoint, $request->getMethod())) { |
|
| 47 | 47 | throw new MethodNotFoundException("The endpoint method " . $request->getMethod() . " was not found"); |
| 48 | 48 | } |
| 49 | 49 | return call_user_func([$endpoint, $request->getMethod()], $request); |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | * @param ResponseFactory $responseFactory |
| 41 | 41 | * @param EndpointFactory $endpointFactory |
| 42 | 42 | */ |
| 43 | - public function __construct(AccessControl $accessControl, Throttle $throttle, ResponseFactory $responseFactory, EndpointFactory $endpointFactory){ |
|
| 43 | + public function __construct(AccessControl $accessControl, Throttle $throttle, ResponseFactory $responseFactory, EndpointFactory $endpointFactory) { |
|
| 44 | 44 | $this->accessControl = $accessControl; |
| 45 | 45 | $this->throttle = $throttle; |
| 46 | 46 | $this->responseFactory = $responseFactory; |
@@ -80,8 +80,8 @@ discard block |
||
| 80 | 80 | * @param Request $request |
| 81 | 81 | * @throws InvalidAPIKeyException |
| 82 | 82 | */ |
| 83 | - protected function validateKey(Request $request){ |
|
| 84 | - if(!$this->accessControl->validateKey($request->getApiKey())){ |
|
| 83 | + protected function validateKey(Request $request) { |
|
| 84 | + if(!$this->accessControl->validateKey($request->getApiKey())) { |
|
| 85 | 85 | throw new InvalidAPIKeyException('Invalid API key'); |
| 86 | 86 | } |
| 87 | 87 | } |
@@ -42,26 +42,26 @@ |
||
| 42 | 42 | $response = $this->server->handleRequest($request); |
| 43 | 43 | header("Content-Type: " . $response->getMIMEType()); |
| 44 | 44 | echo $response->getAsString(); |
| 45 | - } catch(InvalidAPIKeyException $e){ |
|
| 45 | + } catch(InvalidAPIKeyException $e) { |
|
| 46 | 46 | header('400 Bad Request', true, 400); |
| 47 | - } catch(UnknownEndpointException $e){ |
|
| 47 | + } catch(UnknownEndpointException $e) { |
|
| 48 | 48 | header('404 Not Found', true, 404); |
| 49 | - } catch(NotAcceptableResponseTypeException $e){ |
|
| 49 | + } catch(NotAcceptableResponseTypeException $e) { |
|
| 50 | 50 | header('406 Not Acceptable', true, 406); |
| 51 | - } catch(AccessDeniedException $e){ |
|
| 51 | + } catch(AccessDeniedException $e) { |
|
| 52 | 52 | header('403 Access Denied', true, 403); |
| 53 | - } catch(ThrottleLimitExceededException $e){ |
|
| 53 | + } catch(ThrottleLimitExceededException $e) { |
|
| 54 | 54 | header('429 Too Many Requests', true, 429); |
| 55 | 55 | } catch (\Exception $e) { |
| 56 | 56 | header('500 Internal Server Error', true, 500); |
| 57 | 57 | } |
| 58 | - } catch(InvalidRequestURLException $e){ |
|
| 58 | + } catch(InvalidRequestURLException $e) { |
|
| 59 | 59 | header('400 Bad Request', true, 400); |
| 60 | - } catch(UnknownContentTypeException $e){ |
|
| 60 | + } catch(UnknownContentTypeException $e) { |
|
| 61 | 61 | header('400 Bad Request', true, 400); |
| 62 | - } catch(InvalidRequestDataException $e){ |
|
| 62 | + } catch(InvalidRequestDataException $e) { |
|
| 63 | 63 | header('400 Bad Request', true, 400); |
| 64 | - } catch(\Exception $e){ |
|
| 64 | + } catch(\Exception $e) { |
|
| 65 | 65 | header('500 Internal Server Error', true, 500); |
| 66 | 66 | } |
| 67 | 67 | } |
@@ -23,7 +23,7 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | public function getEndpoint(string $name, string $version): Endpoint { |
| 25 | 25 | $className = $this->buildVersionedEndpointNamespace($version) . $name; |
| 26 | - if(!class_exists($className)){ |
|
| 26 | + if(!class_exists($className)) { |
|
| 27 | 27 | throw new UnknownEndpointException("Could not find $className"); |
| 28 | 28 | } |
| 29 | 29 | |
@@ -9,7 +9,7 @@ |
||
| 9 | 9 | class DoctrineEndpoint extends DefaultEndpoint { |
| 10 | 10 | protected $entityManager; |
| 11 | 11 | |
| 12 | - public function __construct(EntityManager $em){ |
|
| 12 | + public function __construct(EntityManager $em) { |
|
| 13 | 13 | $this->entityManager = $em; |
| 14 | 14 | } |
| 15 | 15 | } |
@@ -11,9 +11,9 @@ discard block |
||
| 11 | 11 | * @param \LunixREST\Request\Request $request |
| 12 | 12 | * @return bool true if all of the $accessControls' validate access methods returned true for the given request |
| 13 | 13 | */ |
| 14 | - public function validateAccess(Request $request){ |
|
| 15 | - foreach($this->accessControls as $accessControl){ |
|
| 16 | - if(!$accessControl->validateAccess($request)){ |
|
| 14 | + public function validateAccess(Request $request) { |
|
| 15 | + foreach($this->accessControls as $accessControl) { |
|
| 16 | + if(!$accessControl->validateAccess($request)) { |
|
| 17 | 17 | return false; |
| 18 | 18 | } |
| 19 | 19 | } |
@@ -24,9 +24,9 @@ discard block |
||
| 24 | 24 | * @param $apiKey |
| 25 | 25 | * @return bool true if all of the $accessControls' validate key methods returned true for the given request |
| 26 | 26 | */ |
| 27 | - public function validateKey($apiKey){ |
|
| 28 | - foreach($this->accessControls as $accessControl){ |
|
| 29 | - if(!$accessControl->validateKey($apiKey)){ |
|
| 27 | + public function validateKey($apiKey) { |
|
| 28 | + foreach($this->accessControls as $accessControl) { |
|
| 29 | + if(!$accessControl->validateKey($apiKey)) { |
|
| 30 | 30 | return false; |
| 31 | 31 | } |
| 32 | 32 | } |
@@ -11,7 +11,7 @@ |
||
| 11 | 11 | * @throws NotAcceptableResponseTypeException |
| 12 | 12 | */ |
| 13 | 13 | public function getResponse(ResponseData $data, array $acceptedMIMETypes): Response { |
| 14 | - if(empty($acceptedMIMETypes)){ |
|
| 14 | + if(empty($acceptedMIMETypes)) { |
|
| 15 | 15 | $acceptedMIMETypes = $this->getSupportedMIMETypes(); |
| 16 | 16 | } |
| 17 | 17 | |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | * @param string $filename |
| 23 | 23 | * @param string $nameSpace |
| 24 | 24 | */ |
| 25 | - public function __construct($filename, $nameSpace = null){ |
|
| 25 | + public function __construct($filename, $nameSpace = null) { |
|
| 26 | 26 | $this->filename = $filename; |
| 27 | 27 | $this->nameSpace = $nameSpace; |
| 28 | 28 | } |
@@ -33,10 +33,10 @@ discard block |
||
| 33 | 33 | * @throws INIKeyNotFoundException |
| 34 | 34 | * @throws INIParseException |
| 35 | 35 | */ |
| 36 | - public function get($key){ |
|
| 36 | + public function get($key) { |
|
| 37 | 37 | $config = parse_ini_file($this->filename, (bool)$this->nameSpace); |
| 38 | 38 | |
| 39 | - if($config === false){ |
|
| 39 | + if($config === false) { |
|
| 40 | 40 | throw new INIParseException('Could not parse: ' . $this->filename, true); |
| 41 | 41 | } |
| 42 | 42 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | /** |
| 55 | 55 | * @param $key |
| 56 | 56 | */ |
| 57 | - public function set($key){ |
|
| 57 | + public function set($key) { |
|
| 58 | 58 | //TODO write this |
| 59 | 59 | } |
| 60 | 60 | } |