Skip to content

Commit befe69a

Browse files
committed
Simplify redundant type checks and tighten false null guards
1 parent fcbd99b commit befe69a

18 files changed

Lines changed: 39 additions & 44 deletions

src/DispatcherRuntimeHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static function isSetupRouteAllowed(?string $uri, array $setupAllowedPath
5656
}
5757

5858
$path = parse_url($uri, PHP_URL_PATH);
59-
if (!is_string($path) || '' === $path) {
59+
if (null === $path || '' === $path) {
6060
return false;
6161
}
6262

src/base/Router.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ public function getRoute($slug = '', $absolute = false, array $params = [])
258258
if ('' === $slug) {
259259
return $baseUrl . '/';
260260
}
261-
if (!is_array($this->slugs) || !array_key_exists($slug, $this->slugs)) {
261+
if (!array_key_exists($slug, $this->slugs)) {
262262
throw new RouterException(t('Specified route does not exist'));
263263
}
264264
$url = $baseUrl . $this->slugs[$slug];

src/base/Security.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ private function checkAdminRole($role = AuthHelper::USER_ID_TOKEN)
165165
$users = $this->getAdmins();
166166
$logged = $this->getAdmin();
167167
if (is_array($logged)
168-
&& is_array($users)
169168
&& array_key_exists('alias', $logged)
170169
&& array_key_exists($logged['alias'], $users)) {
171170
$security = $users[$logged['alias']]['profile'];
@@ -183,7 +182,6 @@ public function isSuperAdmin()
183182
$users = $this->getAdmins();
184183
$logged = $this->getAdmin();
185184
if (is_array($logged)
186-
&& is_array($users)
187185
&& array_key_exists('alias', $logged)
188186
&& array_key_exists($logged['alias'], $users)) {
189187
$security = $users[$logged['alias']]['profile'];

src/base/dto/JsonResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function __construct($data = [], $result = false, $total = null, $pages =
5151
parent::__construct(false);
5252
$this->data = $this->parseData($data);
5353
$this->success = $result;
54-
$this->total = $total ?: (is_array($this->data) ? count($this->data) : ($total ?? 0));
54+
$this->total = $total ?: (is_countable($this->data) ? count($this->data) : ($total ?? 0));
5555
$this->pages = $pages;
5656
if (null !== $message) {
5757
$this->message = $message;

src/base/extension/TemplateFunctions.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,13 @@ private static function extractPathname(string $path, $domains): string|array
243243
private static function processCssLines($filenamePath): void
244244
{
245245
$handle = @fopen($filenamePath, 'r');
246-
if ($handle) {
247-
while (!feof($handle)) {
248-
AssetsParser::extractCssLineResource($handle, $filenamePath);
249-
}
250-
fclose($handle);
246+
if (false === $handle) {
247+
return;
248+
}
249+
while (!feof($handle)) {
250+
AssetsParser::extractCssLineResource($handle, $filenamePath);
251251
}
252+
fclose($handle);
252253
}
253254

254255
/**

src/base/extension/traits/CssTrait.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,19 @@ protected function processCssLine($file, $base, $data, $hash)
9494
protected function loopCssLines($file)
9595
{
9696
$handle = @fopen($file, 'r');
97-
if ($handle) {
98-
while (!feof($handle)) {
99-
$line = fgets($handle);
100-
$urls = array();
101-
if (preg_match_all('#url\((.*?)\)#', $line, $urls, PREG_SET_ORDER)) {
102-
foreach ($urls as $source) {
103-
$this->extractCssResources($source, $file);
104-
}
97+
if (false === $handle) {
98+
return;
99+
}
100+
while (!feof($handle)) {
101+
$line = fgets($handle);
102+
$urls = array();
103+
if (preg_match_all('#url\((.*?)\)#', $line, $urls, PREG_SET_ORDER)) {
104+
foreach ($urls as $source) {
105+
$this->extractCssResources($source, $file);
105106
}
106107
}
107-
fclose($handle);
108108
}
109+
fclose($handle);
109110
}
110111

111112
/**

src/base/types/CurlService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public function callSrv()
151151
Logger::log(
152152
$this->getUrl() . ' response: ',
153153
LOG_DEBUG,
154-
is_array($this->getRawResult()) ? $this->getRawResult() : [$this->getRawResult()]
154+
[$this->getRawResult()]
155155
);
156156
$this->info = array_merge($this->info, curl_getinfo($this->con));
157157
}

src/base/types/helpers/AuthHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public static function generateProfileHash(?string $role = AuthHelper::SESSION_T
5353

5454
public static function checkBasicAuth(?string $user = null, ?string $pass = null, ?array $admins = []): array
5555
{
56-
$admins = is_array($admins) ? $admins : [];
56+
$admins = $admins ?? [];
5757
[$candidateUser, $candidatePass] = self::resolveBasicCredentials($user, $pass, $admins);
5858
if (null === $candidateUser || !array_key_exists((string)$candidateUser, $admins)) {
5959
return self::authTuple();

src/base/types/helpers/I18nHelper.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,8 @@ public static function utf8Encode($data): mixed
9090
}
9191
} elseif (is_object($data)) {
9292
$properties = get_class_vars(get_class($data));
93-
if (is_array($properties)) {
94-
foreach (array_keys($properties) as $property) {
95-
$data->$property = self::utf8Encode($data->$property);
96-
}
93+
foreach (array_keys($properties) as $property) {
94+
$data->$property = self::utf8Encode($data->$property);
9795
}
9896
} elseif (is_string($data)) {
9997
$data = mb_convert_encoding($data, 'UTF-8');

src/base/types/helpers/RequestHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public static function normalizeOrigin(?string $origin): ?string
8080
}
8181

8282
$parsed = parse_url(trim($origin));
83-
if (!is_array($parsed) || empty($parsed['scheme']) || empty($parsed['host'])) {
83+
if (false === $parsed || empty($parsed['scheme']) || empty($parsed['host'])) {
8484
return null;
8585
}
8686

0 commit comments

Comments
 (0)