Skip to content

Commit e5f867a

Browse files
committed
Small optimizations
1 parent 6d8cea9 commit e5f867a

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

.github/workflows/tests.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ jobs:
3838
ini-values: apc.enabled=1, apc.shm_size=32M, apc.ttl=7200, apc.enable_cli=1, apc.serializer=php
3939
- name: Run tests on PHP 7.4
4040
run: php -f ./bin/ci/run_tests.php
41-
4241
# Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit"
4342
# Docs: https://getcomposer.org/doc/articles/scripts.md
4443
- name: Run tests on PHP 8.0

lib/Phpfastcache/Api.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ public static function getPhpFastCacheVersion(bool $fallbackOnChangelog = true,
7474
return $version;
7575
}
7676

77-
if (function_exists('shell_exec')) {
77+
if (\function_exists('shell_exec')) {
7878
$command = 'git -C "' . __DIR__ . '" describe --abbrev=0 --tags';
79-
$stdout = shell_exec($command);
80-
if (is_string($stdout)) {
79+
$stdout = \shell_exec($command);
80+
if (\is_string($stdout)) {
8181
$version = trim($stdout);
8282
return $version;
8383
}
@@ -91,12 +91,12 @@ public static function getPhpFastCacheVersion(bool $fallbackOnChangelog = true,
9191
}
9292

9393
$changelogFilename = __DIR__ . '/../../CHANGELOG.md';
94-
if (file_exists($changelogFilename)) {
94+
if (\file_exists($changelogFilename)) {
9595
$versionPrefix = '## ';
96-
$changelog = explode("\n", self::getPhpFastCacheChangelog());
96+
$changelog = \explode("\n", self::getPhpFastCacheChangelog());
9797
foreach ($changelog as $line) {
98-
if (strpos($line, $versionPrefix) === 0) {
99-
$version = trim(str_replace($versionPrefix, '', $line));
98+
if (\strpos($line, $versionPrefix) === 0) {
99+
$version = \trim(\str_replace($versionPrefix, '', $line));
100100
return $version;
101101
}
102102
}
@@ -116,8 +116,8 @@ public static function getPhpFastCacheVersion(bool $fallbackOnChangelog = true,
116116
public static function getPhpFastCacheChangelog(): string
117117
{
118118
$changelogFilename = __DIR__ . '/../../CHANGELOG.md';
119-
if (file_exists($changelogFilename)) {
120-
$string = str_replace(["\r\n", "\r"], "\n", trim(file_get_contents($changelogFilename)));
119+
if (\file_exists($changelogFilename)) {
120+
$string = \str_replace(["\r\n", "\r"], "\n", \trim(\file_get_contents($changelogFilename)));
121121
if ($string) {
122122
return $string;
123123
}
@@ -138,10 +138,10 @@ public static function getPhpFastCacheGitHeadHash(bool $cacheable = true): strin
138138
return $hash;
139139
}
140140

141-
if (function_exists('shell_exec')) {
142-
$stdout = shell_exec('git rev-parse --short HEAD');
143-
if (is_string($stdout)) {
144-
$hash = trim($stdout);
141+
if (\function_exists('shell_exec')) {
142+
$stdout = \shell_exec('git rev-parse --short HEAD');
143+
if (\is_string($stdout)) {
144+
$hash = \trim($stdout);
145145
return "#{$hash}";
146146
}
147147
}
@@ -157,8 +157,8 @@ public static function getPhpFastCacheGitHeadHash(bool $cacheable = true): strin
157157
public static function getChangelog(): string
158158
{
159159
$changelogFilename = __DIR__ . '/../../CHANGELOG_API.md';
160-
if (file_exists($changelogFilename)) {
161-
$string = str_replace(["\r\n", "\r"], "\n", trim(file_get_contents($changelogFilename)));
160+
if (\file_exists($changelogFilename)) {
161+
$string = \str_replace(["\r\n", "\r"], "\n", \trim(\file_get_contents($changelogFilename)));
162162
if ($string) {
163163
return $string;
164164
}

lib/Phpfastcache/CacheManager.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,15 @@ public static function getInstance(string $driver, ?ConfigurationOptionInterface
177177
$config = self::validateConfig($config);
178178
$driver = self::standardizeDriverName($driver);
179179

180-
$instanceId = $instanceId ?: md5($driver . serialize(\array_filter($config->toArray(), static function ($val){
180+
$instanceId = $instanceId ?: md5($driver . \serialize(\array_filter($config->toArray(), static function ($val){
181181
return !\is_callable($val);
182182
})));
183183

184184
if (!isset(self::$instances[$instanceId])) {
185185
self::$badPracticeOmeter[$driver] = 1;
186186
$driverClass = self::validateDriverClass(self::getDriverClass($driver));
187187

188-
if (class_exists($driverClass)) {
188+
if (\class_exists($driverClass)) {
189189
$configClass = $driverClass::getConfigClass();
190190
self::$instances[$instanceId] = new $driverClass(new $configClass($config->toArray()), $instanceId);
191191
self::$instances[$instanceId]->setEventManager(EventManager::getInstance());
@@ -194,7 +194,7 @@ public static function getInstance(string $driver, ?ConfigurationOptionInterface
194194
}
195195
} else {
196196
if (self::$badPracticeOmeter[$driver] >= 2) {
197-
trigger_error(
197+
\trigger_error(
198198
'[' . $driver . '] Calling many times CacheManager::getInstance() for already instanced drivers is a bad practice and have a significant impact on performances.
199199
See https://github.com/PHPSocialNetwork/phpfastcache/wiki/[V5]-Why-calling-getInstance%28%29-each-time-is-a-bad-practice-%3F'
200200
);
@@ -219,7 +219,7 @@ protected static function validateConfig(?ConfigurationOptionInterface $config):
219219
$config = self::getDefaultConfig();
220220
} else {
221221
if (!($config instanceof ConfigurationOption)) {
222-
throw new PhpfastcacheInvalidArgumentException(sprintf('Unsupported config type: %s', gettype($config)));
222+
throw new PhpfastcacheInvalidArgumentException(\sprintf('Unsupported config type: %s', \gettype($config)));
223223
}
224224
}
225225

@@ -242,7 +242,7 @@ public static function getDefaultConfig(): ConfigurationOptionInterface
242242
*/
243243
public static function standardizeDriverName(string $driverName): string
244244
{
245-
return ucfirst(strtolower(trim($driverName)));
245+
return \ucfirst(\strtolower(\trim($driverName)));
246246
}
247247

248248
/**

0 commit comments

Comments
 (0)