Skip to content

Commit 4d2bac1

Browse files
committed
Strict compare
1 parent 8ab90bf commit 4d2bac1

File tree

9 files changed

+24
-21
lines changed

9 files changed

+24
-21
lines changed

src/ApiDecider.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,18 @@ class ApiDecider
3030
*/
3131
public function getApi(string $method, int $version, string $package, ?string $apiAction = null)
3232
{
33+
$method = strtoupper($method);
34+
$apiAction = $apiAction === '' ? null : $apiAction;
35+
3336
foreach ($this->apis as $api) {
3437
$identifier = $api->getEndpoint();
35-
if ($method == $identifier->getMethod() && $identifier->getVersion() == $version && $identifier->getPackage() == $package && $identifier->getApiAction() == $apiAction) {
38+
if ($method === $identifier->getMethod() && $identifier->getVersion() === $version && $identifier->getPackage() === $package && $identifier->getApiAction() === $apiAction) {
3639
$endpointIdentifier = new EndpointIdentifier($method, $version, $package, $apiAction);
3740
$api->getHandler()->setEndpointIdentifier($endpointIdentifier);
3841
return $api;
3942
}
40-
if ($method == 'OPTIONS' && $this->globalPreflightHandler && $identifier->getVersion() == $version && $identifier->getPackage() == $package && $identifier->getApiAction() == $apiAction) {
41-
return new Api(new EndpointIdentifier('OPTION', $version, $package, $apiAction), $this->globalPreflightHandler, new NoAuthorization());
43+
if ($method === 'OPTIONS' && $this->globalPreflightHandler && $identifier->getVersion() === $version && $identifier->getPackage() === $package && $identifier->getApiAction() === $apiAction) {
44+
return new Api(new EndpointIdentifier('OPTIONS', $version, $package, $apiAction), $this->globalPreflightHandler, new NoAuthorization());
4245
}
4346
}
4447
return new Api(new EndpointIdentifier($method, $version, $package, $apiAction), new DefaultHandler(), new NoAuthorization());

src/Authorization/BearerTokenAuthorization.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private function isValidIp(?string $ipRestrictions): bool
9090
$ipWhiteList = str_replace([',', ' ', "\n"], '#', $ipRestrictions);
9191
$ipWhiteList = explode('#', $ipWhiteList);
9292
foreach ($ipWhiteList as $whiteIp) {
93-
if ($whiteIp == $ip) {
93+
if ($whiteIp === $ip) {
9494
return true;
9595
}
9696
if (strpos($whiteIp, '/') !== false) {
@@ -115,7 +115,7 @@ private function ipInRange(string $ip, string $range): bool
115115
$ipDecimal = ip2long($ip);
116116
$wildcard_decimal = pow(2, (32 - (int)$netmask)) - 1;
117117
$netmask_decimal = ~ $wildcard_decimal;
118-
return (($ipDecimal & $netmask_decimal) == ($range_decimal & $netmask_decimal));
118+
return (($ipDecimal & $netmask_decimal) === ($range_decimal & $netmask_decimal));
119119
}
120120

121121
/**

src/Component/ApiConsoleControl.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ protected function createComponentConsoleForm(): Form
5353
$scheme = $_SERVER['HTTP_X_FORWARDED_PROTO'];
5454
}
5555
$port = '';
56-
if ($uri->scheme == 'http' && $uri->port != 80) {
56+
if ($uri->scheme === 'http' && $uri->port !== 80) {
5757
$port = ':' . $uri->port;
5858
}
5959
$url = $scheme . '://' . $uri->host . $port . '/api/' . $this->endpoint->getUrl();

src/Component/console.latte

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<b>POST FIELDS:</b>
2020
<pre>{foreach $response->getPostFields() as $key => $field}
2121
{spaceless}
22-
{if is_object($field) && get_class($field) == 'CURLFile'}
22+
{if is_object($field) && get_class($field) === 'CURLFile'}
2323
{$key}=@{$field->getFilename()} ({$field->getMimeType()}) [{$field->getPostFilename()}] (file)
2424
{else}
2525
{$key}={$field}

src/Handlers/ApiListingHandler.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function handle(array $params): ResponseInterface
5454
private function getApiList(int $version): array
5555
{
5656
$versionApis = array_filter($this->apiDecider->getApis(), function (Api $api) use ($version) {
57-
return $version == $api->getEndpoint()->getVersion();
57+
return $version === $api->getEndpoint()->getVersion();
5858
});
5959

6060
return array_map(function (Api $api) {

src/Misc/ConsoleRequest.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -140,19 +140,19 @@ private function processValues(array $values): array
140140
if ($param->isMulti()) {
141141
if (in_array($param->getType(), [InputParam::TYPE_POST, InputParam::TYPE_FILE])) {
142142
$postFields[$key][] = $valueData;
143-
} elseif ($param->getType() == InputParam::TYPE_PUT) {
143+
} elseif ($param->getType() === InputParam::TYPE_PUT) {
144144
$putFields[$key][] = $valueData;
145-
} elseif ($param->getType() == InputParam::TYPE_COOKIE) {
145+
} elseif ($param->getType() === InputParam::TYPE_COOKIE) {
146146
$cookieFields[$key][] = $valueData;
147147
} else {
148148
$getFields[$key][] = $valueData;
149149
}
150150
} else {
151151
if (in_array($param->getType(), [InputParam::TYPE_POST, InputParam::TYPE_FILE])) {
152152
$postFields[$key] = $valueData;
153-
} elseif ($param->getType() == InputParam::TYPE_PUT) {
153+
} elseif ($param->getType() === InputParam::TYPE_PUT) {
154154
$putFields[$key] = $valueData;
155-
} elseif ($param->getType() == InputParam::TYPE_COOKIE) {
155+
} elseif ($param->getType() === InputParam::TYPE_COOKIE) {
156156
$cookieFields[$key] = $valueData;
157157
} else {
158158
$getFields[$key] = $valueData;
@@ -175,7 +175,7 @@ private function processValues(array $values): array
175175
*/
176176
private function processParam(ParamInterface $param, string $key, $value): ?string
177177
{
178-
if ($param->getKey() == $key) {
178+
if ($param->getKey() === $key) {
179179
$valueData = $value;
180180

181181
if ($param->getType() === InputParam::TYPE_FILE) {
@@ -202,7 +202,7 @@ private function normalizeValues(array $values): array
202202
if (is_array($value)) {
203203
$counter = 0;
204204
foreach ($value as $innerValue) {
205-
if ($innerValue != null) {
205+
if ($innerValue !== null) {
206206
$result[$key . "[".$counter++."]"] = $innerValue;
207207
}
208208
}

src/Misc/IpDetector.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public function getRequestIp(): string
1111
{
1212
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
1313
$ip = $_SERVER['HTTP_CLIENT_IP'];
14-
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] != '127.0.0.1') {
14+
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] !== '127.0.0.1') {
1515
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
1616
} elseif (!empty($_SERVER['REMOTE_ADDR'])) {
1717
$ip = $_SERVER['REMOTE_ADDR'];

src/Params/InputParam.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,11 @@ protected function getParamLabel(): string
191191
public function isValid(): bool
192192
{
193193
$value = $this->getValue();
194-
if ($this->required === self::OPTIONAL && ($value === null || $value == '')) {
194+
if ($this->required === self::OPTIONAL && ($value === null || $value === '')) {
195195
return true;
196196
}
197197

198-
if ($this->required && ($value === null || $value == '')) {
198+
if ($this->required && ($value === null || $value === '')) {
199199
$this->errors[] = 'Field is required';
200200
return false;
201201
}

src/Presenters/ApiPresenter.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ private function logRequest(ApiLoggerInterface $logger, int $code, float $elapse
145145
$headers = getallheaders();
146146
} else {
147147
foreach ($_SERVER as $name => $value) {
148-
if (substr($name, 0, 5) == 'HTTP_') {
148+
if (substr($name, 0, 5) === 'HTTP_') {
149149
$key = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5)))));
150150
$headers[$key] = $value;
151151
}
@@ -173,7 +173,7 @@ protected function sendCorsHeaders(): void
173173
{
174174
$this->getHttpResponse()->addHeader('Access-Control-Allow-Methods', 'POST, DELETE, PUT, GET, OPTIONS');
175175

176-
if ($this->corsHeader == 'auto') {
176+
if ($this->corsHeader === 'auto') {
177177
$domain = $this->getRequestDomain();
178178
if ($domain !== null) {
179179
$this->getHttpResponse()->addHeader('Access-Control-Allow-Origin', $domain);
@@ -182,12 +182,12 @@ protected function sendCorsHeaders(): void
182182
return;
183183
}
184184

185-
if ($this->corsHeader == '*') {
185+
if ($this->corsHeader === '*') {
186186
$this->getHttpResponse()->addHeader('Access-Control-Allow-Origin', '*');
187187
return;
188188
}
189189

190-
if ($this->corsHeader != 'off') {
190+
if ($this->corsHeader !== 'off') {
191191
$this->getHttpResponse()->addHeader('Access-Control-Allow-Origin', $this->corsHeader);
192192
}
193193
}

0 commit comments

Comments
 (0)