Skip to content

Commit 55cf31c

Browse files
committed
Various minor performance improvements.
1 parent b995a9d commit 55cf31c

5 files changed

Lines changed: 68 additions & 68 deletions

File tree

src/CompressionHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* License: GNU/GPLv2
99
* @see LICENSE.txt
1010
*
11-
* This file: Compression handler (last modified: 2026.03.17).
11+
* This file: Compression handler (last modified: 2026.03.18).
1212
*/
1313

1414
namespace phpMussel\Core;
@@ -127,7 +127,7 @@ public function TryEverything(): bool
127127
private function TryX(string $Using): int
128128
{
129129
/** Guard. */
130-
if (!function_exists($Using)) {
130+
if (!\function_exists($Using)) {
131131
return 1;
132132
}
133133

src/Loader.php

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* License: GNU/GPLv2
99
* @see LICENSE.txt
1010
*
11-
* This file: The loader (last modified: 2026.03.17).
11+
* This file: The loader (last modified: 2026.03.18).
1212
*/
1313

1414
namespace phpMussel\Core;
@@ -166,12 +166,12 @@ class Loader
166166
/**
167167
* @var string The path to the core asset files.
168168
*/
169-
private $AssetsPath = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR;
169+
private $AssetsPath = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'assets' . \DIRECTORY_SEPARATOR;
170170

171171
/**
172172
* @var string The path to the core L10N files.
173173
*/
174-
private $L10NPath = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'l10n' . DIRECTORY_SEPARATOR;
174+
private $L10NPath = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'l10n' . \DIRECTORY_SEPARATOR;
175175

176176
/**
177177
* @var array Channels information for request.
@@ -221,7 +221,7 @@ public function __construct(
221221

222222
/** Fallback to try for undefined VendorPath. */
223223
if (!$VendorPath) {
224-
$VendorPath = __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'vendor';
224+
$VendorPath = __DIR__ . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'vendor';
225225
}
226226

227227
/** The specified vendor directory doesn't exist or isn't readable. */
@@ -233,7 +233,7 @@ public function __construct(
233233

234234

235235
/** Safeguard for symlinked installations. */
236-
$VendorPath = $this->buildPath(\dirname($_SERVER['DOCUMENT_ROOT'] . $_SERVER['SCRIPT_NAME']) . DIRECTORY_SEPARATOR . 'vendor', false);
236+
$VendorPath = $this->buildPath(\dirname($_SERVER['DOCUMENT_ROOT'] . $_SERVER['SCRIPT_NAME']) . \DIRECTORY_SEPARATOR . 'vendor', false);
237237

238238
/** Eep.. Still not working. Generate exception. */
239239
if ($VendorPath === '' || !\is_dir($VendorPath) || !\is_readable($VendorPath)) {
@@ -281,10 +281,10 @@ public function __construct(
281281
/** Calculate configuration path. */
282282
if ($ConfigurationPath && \is_readable($ConfigurationPath)) {
283283
$this->ConfigurationPath = $ConfigurationPath;
284-
} elseif ($VendorPath && \is_readable($VendorPath . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'phpmussel.ini')) {
285-
$this->ConfigurationPath = $VendorPath . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'phpmussel.ini';
286-
} elseif ($VendorPath && \is_readable($VendorPath . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'phpmussel.yml')) {
287-
$this->ConfigurationPath = $VendorPath . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'phpmussel.yml';
284+
} elseif ($VendorPath && \is_readable($VendorPath . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'phpmussel.ini')) {
285+
$this->ConfigurationPath = $VendorPath . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'phpmussel.ini';
286+
} elseif ($VendorPath && \is_readable($VendorPath . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'phpmussel.yml')) {
287+
$this->ConfigurationPath = $VendorPath . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'phpmussel.yml';
288288
} else {
289289
throw new \Exception('Unable to locate phpMussel\'s configuration file.');
290290
}
@@ -323,13 +323,13 @@ public function __construct(
323323
if (!$VendorPath) {
324324
continue;
325325
}
326-
$$Path = $VendorPath . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'phpmussel-' . \strtolower(\substr($Path, 0, -4));
326+
$$Path = $VendorPath . \DIRECTORY_SEPARATOR . '..' . \DIRECTORY_SEPARATOR . 'phpmussel-' . \strtolower(\substr($Path, 0, -4));
327327
}
328328
if (!$this->buildPath($$Path, false)) {
329329
throw new \Exception(\sprintf('Unable to build the path, "%s".', $$Path));
330330
}
331331
if (($End = \substr($$Path, -1)) && $End !== '/' && $End !== '\\') {
332-
$$Path .= DIRECTORY_SEPARATOR;
332+
$$Path .= \DIRECTORY_SEPARATOR;
333333
}
334334
$this->$Path = $$Path;
335335
}
@@ -811,20 +811,20 @@ public function buildPath(string $Path, bool $PointsToFile = true): string
811811
$Path = $this->timeFormat($this->Time, $Path);
812812

813813
/** We'll skip is_dir/mkdir calls if open_basedir is populated (to avoid PHP bug #69240). */
814-
$Restrictions = \strlen(ini_get('open_basedir')) > 0;
814+
$Restrictions = \strlen(\ini_get('open_basedir')) > 0;
815815

816816
/** Split path into steps. */
817-
$Steps = \preg_split('~[\\\\/]~', $Path, -1, PREG_SPLIT_NO_EMPTY);
817+
$Steps = \preg_split('~[\\\\/]~', $Path, -1, \PREG_SPLIT_NO_EMPTY);
818818

819819
/** Separate file from path. */
820820
$File = $PointsToFile ? \array_pop($Steps) : '';
821821

822822
/** Build directories. */
823823
foreach ($Steps as $Step) {
824824
if (!isset($Rebuilt)) {
825-
$Rebuilt = \preg_match('~^[\\\\/]~', $Path) ? DIRECTORY_SEPARATOR . $Step : $Step;
825+
$Rebuilt = \preg_match('~^[\\\\/]~', $Path) ? \DIRECTORY_SEPARATOR . $Step : $Step;
826826
} else {
827-
$Rebuilt .= DIRECTORY_SEPARATOR . $Step;
827+
$Rebuilt .= \DIRECTORY_SEPARATOR . $Step;
828828
}
829829
if (\preg_match('~^\.+$~', $Step)) {
830830
continue;
@@ -846,7 +846,7 @@ public function buildPath(string $Path, bool $PointsToFile = true): string
846846

847847
/** Append file. */
848848
if ($File) {
849-
$Rebuilt .= ($Rebuilt ? DIRECTORY_SEPARATOR : '') . $File;
849+
$Rebuilt .= ($Rebuilt ? \DIRECTORY_SEPARATOR : '') . $File;
850850
}
851851

852852
/** Return the final rebuilt path. */
@@ -1047,8 +1047,8 @@ public function isDirEmpty(string $Directory): bool
10471047
*/
10481048
public function deleteDirectory(string $Dir): void
10491049
{
1050-
while (\strrpos($Dir, DIRECTORY_SEPARATOR) !== false) {
1051-
$Dir = \substr($Dir, 0, \strrpos($Dir, DIRECTORY_SEPARATOR));
1050+
while (\strrpos($Dir, \DIRECTORY_SEPARATOR) !== false) {
1051+
$Dir = \substr($Dir, 0, \strrpos($Dir, \DIRECTORY_SEPARATOR));
10521052
if (!\is_dir($Dir) || !$this->isDirEmpty($Dir)) {
10531053
break;
10541054
}
@@ -1085,10 +1085,10 @@ public function logRotation(string $Pattern): bool
10851085
$Files[$Item] = \filemtime($Item);
10861086
}
10871087
}
1088-
$Count = count($Files);
1088+
$Count = \count($Files);
10891089
$Err = 0;
10901090
if ($Count > $Limit) {
1091-
\asort($Files, SORT_NUMERIC);
1091+
\asort($Files, \SORT_NUMERIC);
10921092
foreach ($Files as $Item => $Modified) {
10931093
if ($Action === 'Archive') {
10941094
$Err += !$this->gZCompressFile($Item);
@@ -1114,22 +1114,22 @@ public function logRotation(string $Pattern): bool
11141114
*/
11151115
public function resolvePaths(string $Base, bool $LastIsFile = true, bool $GZ = true): \Generator
11161116
{
1117-
$Steps = \preg_split('~[\\\\/]~', $Base, -1, PREG_SPLIT_NO_EMPTY);
1117+
$Steps = \preg_split('~[\\\\/]~', $Base, -1, \PREG_SPLIT_NO_EMPTY);
11181118
$LastStep = $LastIsFile ? \array_pop($Steps) : '';
11191119
$BaseFrom = '';
11201120
$Remainder = '';
11211121
foreach ($Steps as $Step) {
11221122
if (!$Remainder && \strpos($Step, '{') === false && \strpos($Step, '}') === false) {
1123-
$BaseFrom .= $Step . DIRECTORY_SEPARATOR;
1123+
$BaseFrom .= $Step . \DIRECTORY_SEPARATOR;
11241124
continue;
11251125
}
1126-
$Remainder .= ($Remainder ? DIRECTORY_SEPARATOR : '') . $Step;
1126+
$Remainder .= ($Remainder ? \DIRECTORY_SEPARATOR : '') . $Step;
11271127
}
11281128
if (!$BaseFrom || !\is_dir($BaseFrom) || !\is_readable($BaseFrom)) {
11291129
return;
11301130
}
11311131
if ($Remainder && $LastStep) {
1132-
$LastStep = DIRECTORY_SEPARATOR . $LastStep;
1132+
$LastStep = \DIRECTORY_SEPARATOR . $LastStep;
11331133
}
11341134
$Steps = \preg_replace(
11351135
['~\\{(?:dd|mm|yy|hh|ii|ss)\\}~i', '~\\{yyyy\\}~i', '~\\{(?:Day|Mon)\\}~i', '~\\{tz\\}~i', '~\\{t:z\\}~i'],
@@ -1309,7 +1309,7 @@ private function initialiseCache(): void
13091309
if (($End = \substr($this->CachePath, -1)) === '\\' || $End === '/') {
13101310
$this->Cache->FFDefault = $this->CachePath . 'cache.dat';
13111311
} else {
1312-
$this->Cache->FFDefault = $this->CachePath . DIRECTORY_SEPARATOR . 'cache.dat';
1312+
$this->Cache->FFDefault = $this->CachePath . \DIRECTORY_SEPARATOR . 'cache.dat';
13131313
}
13141314
}
13151315

src/PdfHandler.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* License: GNU/GPLv2
99
* @see LICENSE.txt
1010
*
11-
* This file: Pdf handler (last modified: 2026.03.17).
11+
* This file: Pdf handler (last modified: 2026.03.18).
1212
*/
1313

1414
namespace phpMussel\Core;
@@ -65,7 +65,7 @@ public function __construct(string $File)
6565
$Tree = [];
6666
$Check = \preg_match_all('~\n(\d+) (\d+) obj ?(?:\r?\n|\r\n?)(.+?) ?(?:\r?\n|\r\n?)endobj ?(?:\r?\n|\r\n?)~s', $File, $Matches);
6767
if ($Check && isset($Matches, $Matches[0], $Matches[0][0])) {
68-
$Count = count($Matches[0]);
68+
$Count = \count($Matches[0]);
6969
for ($Iterator = 0; $Iterator < $Count; $Iterator++) {
7070
$Tree[$Iterator] = [
7171
'Object Number' => $Matches[1][$Iterator],
@@ -212,7 +212,7 @@ public function __construct(string $File)
212212
}
213213
if (\substr($Params['Filter'], 0, 10) === '/LZWDecode') {
214214
$Params['Filter'] = \trim(\substr($Params['Filter'], 10));
215-
if (function_exists('lzf_decompress')) {
215+
if (\function_exists('lzf_decompress')) {
216216
$Try = lzf_decompress($Tree[$Iterator]['Stream']);
217217
if ($Try !== false) {
218218
$Tree[$Iterator]['Stream'] = $Try;
@@ -236,7 +236,7 @@ public function __construct(string $File)
236236
if (!$Len || \preg_match('/[^\da-f]/i', $Bytes) || ($Len % 2)) {
237237
break;
238238
}
239-
$Params['Type'] = \substr($Params['Type'], 0, $HPos) . chr(\hexdec($Bytes)) . \substr($Params['Type'], $HPos + 3);
239+
$Params['Type'] = \substr($Params['Type'], 0, $HPos) . \chr(\hexdec($Bytes)) . \substr($Params['Type'], $HPos + 3);
240240
}
241241
}
242242

@@ -245,7 +245,7 @@ public function __construct(string $File)
245245
}
246246

247247
/** Total objects. */
248-
$Counts = count($Tree);
248+
$Counts = \count($Tree);
249249

250250
/** Build references. */
251251
for ($Iterator = 0; $Iterator < $Counts; $Iterator++) {

0 commit comments

Comments
 (0)