| Conditions | 10 |
| Paths | 13 |
| Total Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 59 | public static function getPhpFastCacheVersion($fallbackOnChangelog = true, $cacheable = true): string |
||
| 60 | { |
||
| 61 | /** |
||
| 62 | * Cache the version statically to improve |
||
| 63 | * performances on multiple calls |
||
| 64 | */ |
||
| 65 | static $version; |
||
| 66 | |||
| 67 | if ($version && $cacheable) { |
||
| 68 | return $version; |
||
| 69 | } |
||
| 70 | |||
| 71 | if (\function_exists('shell_exec')) { |
||
| 72 | $command = 'git -C "' . __DIR__ . '" describe --abbrev=0 --tags'; |
||
| 73 | $stdout = shell_exec($command); |
||
| 74 | if (\is_string($stdout)) { |
||
|
|
|||
| 75 | $version = \trim($stdout); |
||
| 76 | return $version; |
||
| 77 | } |
||
| 78 | if (!$fallbackOnChangelog) { |
||
| 79 | throw new PhpfastcacheLogicException('The git command used to retrieve the PhpFastCache version has failed.'); |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 83 | if (!$fallbackOnChangelog) { |
||
| 84 | throw new PhpfastcacheLogicException('shell_exec is disabled therefore the PhpFastCache version cannot be retrieved.'); |
||
| 85 | } |
||
| 86 | |||
| 87 | $changelogFilename = __DIR__ . '/../../CHANGELOG.md'; |
||
| 88 | if (\file_exists($changelogFilename)) { |
||
| 89 | $versionPrefix = '## '; |
||
| 90 | $changelog = \explode("\n", self::getPhpFastCacheChangelog()); |
||
| 91 | foreach ($changelog as $line) { |
||
| 92 | if (\strpos($line, $versionPrefix) === 0) { |
||
| 93 | $version = \trim(\str_replace($versionPrefix, '', $line)); |
||
| 94 | return $version; |
||
| 95 | } |
||
| 96 | } |
||
| 97 | throw new PhpfastcacheLogicException('Unable to retrieve the PhpFastCache version through the CHANGELOG.md as no valid string were found in it.'); |
||
| 98 | } |
||
| 99 | throw new PhpfastcacheLogicException('shell_exec being disabled we attempted to retrieve the PhpFastCache version through the CHANGELOG.md file but it is not readable or has been removed.'); |
||
| 100 | } |
||
| 162 | } |