@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * @param array $acceptableMIMETypes |
43 | 43 | * @param null|string $queryString |
44 | 44 | */ |
45 | - public function __construct(string $endpoint, ?string $element, ?string $version, ?string $apiKey, array $acceptableMIMETypes, ?string $queryString) |
|
45 | + public function __construct(string $endpoint, ? string $element, ? string $version, ? string $apiKey, array $acceptableMIMETypes, ? string $queryString) |
|
46 | 46 | { |
47 | 47 | $this->endpoint = $endpoint; |
48 | 48 | $this->element = $element; |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | /** |
64 | 64 | * @return null|string |
65 | 65 | */ |
66 | - public function getElement(): ?string |
|
66 | + public function getElement(): ? string |
|
67 | 67 | { |
68 | 68 | return $this->element; |
69 | 69 | } |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | /** |
72 | 72 | * @return null|string |
73 | 73 | */ |
74 | - public function getVersion(): ?string |
|
74 | + public function getVersion(): ? string |
|
75 | 75 | { |
76 | 76 | return $this->version; |
77 | 77 | } |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | /** |
80 | 80 | * @return null|string |
81 | 81 | */ |
82 | - public function getApiKey(): ?string |
|
82 | + public function getApiKey(): ? string |
|
83 | 83 | { |
84 | 84 | return $this->apiKey; |
85 | 85 | } |
@@ -6,8 +6,7 @@ discard block |
||
6 | 6 | * Class ParsedURL |
7 | 7 | * @package LunixREST\RequestFactory\URLParser |
8 | 8 | */ |
9 | -class ParsedURL |
|
10 | -{ |
|
9 | +class ParsedURL { |
|
11 | 10 | /** |
12 | 11 | * @var string |
13 | 12 | */ |
@@ -42,8 +41,7 @@ discard block |
||
42 | 41 | * @param array $acceptableMIMETypes |
43 | 42 | * @param null|string $queryString |
44 | 43 | */ |
45 | - public function __construct(string $endpoint, ?string $element, ?string $version, ?string $apiKey, array $acceptableMIMETypes, ?string $queryString) |
|
46 | - { |
|
44 | + public function __construct(string $endpoint, ?string $element, ?string $version, ?string $apiKey, array $acceptableMIMETypes, ?string $queryString) { |
|
47 | 45 | $this->endpoint = $endpoint; |
48 | 46 | $this->element = $element; |
49 | 47 | $this->version = $version; |
@@ -95,8 +93,7 @@ discard block |
||
95 | 93 | /** |
96 | 94 | * @return null|string |
97 | 95 | */ |
98 | - public function getQueryString() |
|
99 | - { |
|
96 | + public function getQueryString() { |
|
100 | 97 | return $this->queryString; |
101 | 98 | } |
102 | 99 | } |
@@ -1,7 +1,6 @@ |
||
1 | 1 | <?php |
2 | 2 | namespace LunixREST\RequestFactory\URLParser\Exceptions; |
3 | 3 | |
4 | -class UnableToProvideMIMEException extends \Exception |
|
5 | -{ |
|
4 | +class UnableToProvideMIMEException extends \Exception { |
|
6 | 5 | |
7 | 6 | } |
@@ -15,8 +15,7 @@ discard block |
||
15 | 15 | * Class RegexURLParser |
16 | 16 | * @package LunixREST\RequestFactory\URLParser\RegexURLParser |
17 | 17 | */ |
18 | -class RegexURLParser implements URLParser |
|
19 | -{ |
|
18 | +class RegexURLParser implements URLParser { |
|
20 | 19 | /** |
21 | 20 | * @var string |
22 | 21 | */ |
@@ -32,8 +31,7 @@ discard block |
||
32 | 31 | * @param MIMEProvider|null $MIMEProvider |
33 | 32 | * @throws InvalidRegexPatternException |
34 | 33 | */ |
35 | - public function __construct(string $pattern, ?MIMEProvider $MIMEProvider = null) |
|
36 | - { |
|
34 | + public function __construct(string $pattern, ?MIMEProvider $MIMEProvider = null) { |
|
37 | 35 | $this->pattern = $pattern; |
38 | 36 | |
39 | 37 | if(@preg_match($pattern, null) === false) { |
@@ -33,11 +33,11 @@ discard block |
||
33 | 33 | * @param MIMEProvider|null $MIMEProvider |
34 | 34 | * @throws InvalidRegexPatternException |
35 | 35 | */ |
36 | - public function __construct(string $pattern, ?MIMEProvider $MIMEProvider = null) |
|
36 | + public function __construct(string $pattern, ? MIMEProvider $MIMEProvider = null) |
|
37 | 37 | { |
38 | 38 | $this->pattern = $pattern; |
39 | 39 | |
40 | - if(@preg_match($pattern, null) === false) { |
|
40 | + if (@preg_match($pattern, null) === false) { |
|
41 | 41 | throw new InvalidRegexPatternException("Unable to parse regex pattern", preg_last_error()); |
42 | 42 | } |
43 | 43 | $this->MIMEProvider = $MIMEProvider; |
@@ -53,10 +53,10 @@ discard block |
||
53 | 53 | public function parse(UriInterface $uri): ParsedURL |
54 | 54 | { |
55 | 55 | $matches = []; |
56 | - if(preg_match($this->pattern, $uri->getPath(), $matches) === 0) { |
|
56 | + if (preg_match($this->pattern, $uri->getPath(), $matches) === 0) { |
|
57 | 57 | throw new InvalidRequestURLException("Unable to parse request path: did not match regex"); |
58 | 58 | } |
59 | - if(!($endpoint = $matches["endpoint"] ?? null)) { |
|
59 | + if (!($endpoint = $matches["endpoint"] ?? null)) { |
|
60 | 60 | throw new InvalidRequestURLException("Unable to match endpoint in url"); |
61 | 61 | } |
62 | 62 | $element = $matches["element"] ?? null; |
@@ -64,8 +64,8 @@ discard block |
||
64 | 64 | $apiKey = $matches["apiKey"] ?? null; |
65 | 65 | |
66 | 66 | $acceptableMimeTypes = []; |
67 | - if(($acceptableExtension = $matches["acceptableExtension"] ?? null)) { |
|
68 | - if(!$this->MIMEProvider) { |
|
67 | + if (($acceptableExtension = $matches["acceptableExtension"] ?? null)) { |
|
68 | + if (!$this->MIMEProvider) { |
|
69 | 69 | throw new UnableToParseURLException("Unable to accept acceptable extensions"); |
70 | 70 | } else { |
71 | 71 | try { |
@@ -6,7 +6,6 @@ |
||
6 | 6 | * Class InvalidRequestURLException |
7 | 7 | * @package LunixREST\RequestFactory\URLParser\RegexURLParser\Exceptions |
8 | 8 | */ |
9 | -class InvalidRegexPatternException extends \Exception |
|
10 | -{ |
|
9 | +class InvalidRegexPatternException extends \Exception { |
|
11 | 10 | |
12 | 11 | } |
@@ -9,8 +9,7 @@ |
||
9 | 9 | * Interface URLParser |
10 | 10 | * @package LunixREST\RequestFactory\URLParser |
11 | 11 | */ |
12 | -interface URLParser |
|
13 | -{ |
|
12 | +interface URLParser { |
|
14 | 13 | /** |
15 | 14 | * Parses API request data out of a url |
16 | 15 | * @param UriInterface $uri |
@@ -47,7 +47,7 @@ |
||
47 | 47 | { |
48 | 48 | foreach ($headers as $key => $values) { |
49 | 49 | if (strtolower($key) == strtolower($this->apiKeyHeaderKey)) { |
50 | - foreach($values as $value) { |
|
50 | + foreach ($values as $value) { |
|
51 | 51 | return $value; |
52 | 52 | } |
53 | 53 | } |
@@ -6,8 +6,7 @@ discard block |
||
6 | 6 | * Class DefaultHeaderParser |
7 | 7 | * @package LunixREST\RequestFactory\HeaderParser |
8 | 8 | */ |
9 | -class DefaultHeaderParser implements HeaderParser |
|
10 | -{ |
|
9 | +class DefaultHeaderParser implements HeaderParser { |
|
11 | 10 | |
12 | 11 | /** |
13 | 12 | * @var string |
@@ -18,8 +17,7 @@ discard block |
||
18 | 17 | * DefaultHeaderParser constructor. |
19 | 18 | * @param string $apiKeyHeaderKey |
20 | 19 | */ |
21 | - public function __construct($apiKeyHeaderKey = 'x-api-key') |
|
22 | - { |
|
20 | + public function __construct($apiKeyHeaderKey = 'x-api-key') { |
|
23 | 21 | $this->apiKeyHeaderKey = $apiKeyHeaderKey; |
24 | 22 | } |
25 | 23 | |
@@ -63,8 +61,7 @@ discard block |
||
63 | 61 | * @param array $headers |
64 | 62 | * @return null |
65 | 63 | */ |
66 | - protected function findAPIKey(array $headers) |
|
67 | - { |
|
64 | + protected function findAPIKey(array $headers) { |
|
68 | 65 | foreach ($headers as $key => $values) { |
69 | 66 | if (strtolower($key) == strtolower($this->apiKeyHeaderKey)) { |
70 | 67 | foreach($values as $value) { |
@@ -79,8 +76,7 @@ discard block |
||
79 | 76 | * @param array $headers |
80 | 77 | * @return null |
81 | 78 | */ |
82 | - protected function getContentType(array $headers) |
|
83 | - { |
|
79 | + protected function getContentType(array $headers) { |
|
84 | 80 | foreach ($headers as $key => $values) { |
85 | 81 | if (strtolower($key) == 'content-type') { |
86 | 82 | foreach ($values as $value) { |
@@ -6,8 +6,7 @@ |
||
6 | 6 | * Interface HeaderParser |
7 | 7 | * @package LunixREST\RequestFactory\HeaderParser |
8 | 8 | */ |
9 | -interface HeaderParser |
|
10 | -{ |
|
9 | +interface HeaderParser { |
|
11 | 10 | /** |
12 | 11 | * @param array $headers |
13 | 12 | * @return ParsedHeaders |
@@ -6,8 +6,7 @@ discard block |
||
6 | 6 | * Class ParsedHeaders |
7 | 7 | * @package LunixREST\RequestFactory\HeaderParser |
8 | 8 | */ |
9 | -class ParsedHeaders |
|
10 | -{ |
|
9 | +class ParsedHeaders { |
|
11 | 10 | /** |
12 | 11 | * @var array |
13 | 12 | */ |
@@ -27,8 +26,7 @@ discard block |
||
27 | 26 | * @param array $acceptableMIMETypes |
28 | 27 | * @param $APIKey |
29 | 28 | */ |
30 | - public function __construct($contentType, array $acceptableMIMETypes, $APIKey) |
|
31 | - { |
|
29 | + public function __construct($contentType, array $acceptableMIMETypes, $APIKey) { |
|
32 | 30 | $this->contentType = $contentType; |
33 | 31 | $this->acceptableMIMETypes = $acceptableMIMETypes; |
34 | 32 | $this->APIKey = $APIKey; |
@@ -37,8 +35,7 @@ discard block |
||
37 | 35 | /** |
38 | 36 | * @return mixed |
39 | 37 | */ |
40 | - public function getContentType() |
|
41 | - { |
|
38 | + public function getContentType() { |
|
42 | 39 | return $this->contentType; |
43 | 40 | } |
44 | 41 | |
@@ -53,8 +50,7 @@ discard block |
||
53 | 50 | /** |
54 | 51 | * @return mixed |
55 | 52 | */ |
56 | - public function getAPIKey() |
|
57 | - { |
|
53 | + public function getAPIKey() { |
|
58 | 54 | return $this->APIKey; |
59 | 55 | } |
60 | 56 | } |
@@ -9,10 +9,8 @@ |
||
9 | 9 | * Class BasicRequestFactory |
10 | 10 | * @package LunixREST\RequestFactory |
11 | 11 | */ |
12 | -class DefaultRequestFactory extends GenericRequestFactory |
|
13 | -{ |
|
14 | - public function __construct(URLParser $URLParser) |
|
15 | - { |
|
12 | +class DefaultRequestFactory extends GenericRequestFactory { |
|
13 | + public function __construct(URLParser $URLParser) { |
|
16 | 14 | parent::__construct($URLParser, new DefaultHeaderParser()); |
17 | 15 | } |
18 | 16 | } |