Completed
Push — master ( 093ab2...84b6a3 )
by John
01:55
created
src/Response/DefaultResponseFactory.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -11,11 +11,11 @@
 block discarded – undo
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
 
18
-        foreach($acceptedMIMETypes as $acceptedMIMEType) {
18
+        foreach ($acceptedMIMETypes as $acceptedMIMEType) {
19 19
             switch (strtolower($acceptedMIMEType)) {
20 20
                 case "application/json":
21 21
                     return new JSONResponse($data);
Please login to merge, or discard this patch.
src/Server/Server.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
      * @param ResponseFactory $responseFactory
40 40
      * @param EndpointFactory $endpointFactory
41 41
      */
42
-    public function __construct(AccessControl $accessControl, Throttle $throttle, ResponseFactory $responseFactory, EndpointFactory $endpointFactory){
42
+    public function __construct(AccessControl $accessControl, Throttle $throttle, ResponseFactory $responseFactory, EndpointFactory $endpointFactory) {
43 43
         $this->accessControl = $accessControl;
44 44
         $this->throttle = $throttle;
45 45
         $this->responseFactory = $responseFactory;
@@ -60,11 +60,11 @@  discard block
 block discarded – undo
60 60
 
61 61
         $this->validateExtension($request);
62 62
 
63
-        if($this->throttle->shouldThrottle($request)) {
63
+        if ($this->throttle->shouldThrottle($request)) {
64 64
             throw new ThrottleLimitExceededException('Request limit exceeded');
65 65
         }
66 66
 
67
-        if(!$this->accessControl->validateAccess($request)) {
67
+        if (!$this->accessControl->validateAccess($request)) {
68 68
             throw new AccessDeniedException("API key does not have the required permissions to access requested resource");
69 69
         }
70 70
 
@@ -79,8 +79,8 @@  discard block
 block discarded – undo
79 79
      * @param Request $request
80 80
      * @throws InvalidAPIKeyException
81 81
      */
82
-    protected function validateKey(Request $request){
83
-        if(!$this->accessControl->validateKey($request->getApiKey())){
82
+    protected function validateKey(Request $request) {
83
+        if (!$this->accessControl->validateKey($request->getApiKey())) {
84 84
             throw new InvalidAPIKeyException('Invalid API key');
85 85
         }
86 86
     }
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
      */
92 92
     protected function validateExtension(Request $request) {
93 93
         $formats = $this->responseFactory->getSupportedMIMETypes();
94
-        if(empty($formats) || (
94
+        if (empty($formats) || (
95 95
             !empty($request->getAcceptableMIMETypes()) && empty(array_intersect($request->getAcceptableMIMETypes(), $formats))
96 96
             )) {
97 97
             throw new NotAcceptableResponseTypeException('None of the requests acceptable response types are valid');
Please login to merge, or discard this patch.
src/Request/Request.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
      * @param string $instance
69 69
      */
70 70
 
71
-    public function __construct(MIMEProvider $MIMEProvider, $method, array $headers, RequestData $body, RequestData $urlData, $ip, $version, $apiKey, $endpoint, $extension, $instance = null){
71
+    public function __construct(MIMEProvider $MIMEProvider, $method, array $headers, RequestData $body, RequestData $urlData, $ip, $version, $apiKey, $endpoint, $extension, $instance = null) {
72 72
         $this->MIMEProvider = $MIMEProvider;
73 73
         $this->method = strtolower($method);
74 74
         $this->headers = $headers;
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
      * @return string
94 94
      */
95 95
     public function getMethod() {
96
-        return $this->method . ($this->instance ? '' : 'All');
96
+        return $this->method.($this->instance ? '' : 'All');
97 97
     }
98 98
 
99 99
     /**
@@ -155,18 +155,18 @@  discard block
 block discarded – undo
155 155
     //TODO: Unit test
156 156
     public function getAcceptableMIMETypes(): array {
157 157
         $acceptedMIMETypes = [];
158
-        if($this->extension) {
158
+        if ($this->extension) {
159 159
             //extension to mime type conversion
160 160
             $acceptedMIMETypes[] = $this->MIMEProvider->getByFileExtension($this->extension);
161 161
         } else {
162 162
             //TODO: follow RFC2616 order
163 163
             $headerAccepts = [];
164
-            foreach($this->headers as $key => $value) {
165
-                if(strtolower($key) == 'http_accept'){
164
+            foreach ($this->headers as $key => $value) {
165
+                if (strtolower($key) == 'http_accept') {
166 166
                     $values = explode(',', $value);
167
-                    foreach($values as $acceptedType) {
167
+                    foreach ($values as $acceptedType) {
168 168
                         $typeParts = explode(';', $acceptedType);
169
-                        if(count($typeParts) > 0 ){
169
+                        if (count($typeParts) > 0) {
170 170
                             $headerAccepts[] = trim($typeParts);
171 171
                         }
172 172
                     }
Please login to merge, or discard this patch.
src/Request/MIMEFileProvider.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -13,21 +13,21 @@
 block discarded – undo
13 13
 
14 14
     //Borrowed from http://stackoverflow.com/a/1147952
15 15
     public function getAll(): array {
16
-        if($this->cache){
16
+        if ($this->cache) {
17 17
             return $this->cache;
18 18
         }
19 19
 
20 20
         # Returns the system MIME type mapping of extensions to MIME types, as defined in /etc/mime.types.
21 21
         $out = array();
22
-        while(($line = fgets($this->file)) !== false) {
22
+        while (($line = fgets($this->file)) !== false) {
23 23
             $line = trim(preg_replace('/#.*/', '', $line));
24
-            if(!$line)
24
+            if (!$line)
25 25
                 continue;
26 26
             $parts = preg_split('/\s+/', $line);
27
-            if(count($parts) == 1)
27
+            if (count($parts) == 1)
28 28
                 continue;
29 29
             $type = array_shift($parts);
30
-            foreach($parts as $part)
30
+            foreach ($parts as $part)
31 31
                 $out[$part] = $type;
32 32
         }
33 33
 
Please login to merge, or discard this patch.
Braces   +9 added lines, -6 removed lines patch added patch discarded remove patch
@@ -21,14 +21,17 @@
 block discarded – undo
21 21
         $out = array();
22 22
         while(($line = fgets($this->file)) !== false) {
23 23
             $line = trim(preg_replace('/#.*/', '', $line));
24
-            if(!$line)
25
-                continue;
24
+            if(!$line) {
25
+                            continue;
26
+            }
26 27
             $parts = preg_split('/\s+/', $line);
27
-            if(count($parts) == 1)
28
-                continue;
28
+            if(count($parts) == 1) {
29
+                            continue;
30
+            }
29 31
             $type = array_shift($parts);
30
-            foreach($parts as $part)
31
-                $out[$part] = $type;
32
+            foreach($parts as $part) {
33
+                            $out[$part] = $type;
34
+            }
32 35
         }
33 36
 
34 37
         $this->cache = $out;
Please login to merge, or discard this patch.