Conditions | 12 |
Paths | 18 |
Total Lines | 41 |
Code Lines | 23 |
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 |
||
60 | public static function getPhpfastcacheVersion(bool $fallbackOnChangelog = true, bool $cacheable = true): string |
||
61 | { |
||
62 | /** |
||
63 | * Cache the version statically to improve |
||
64 | * performances on multiple calls |
||
65 | */ |
||
66 | static $version; |
||
67 | |||
68 | if ($version && $cacheable) { |
||
69 | return $version; |
||
70 | } |
||
71 | |||
72 | if (\function_exists('shell_exec')) { |
||
73 | $command = 'git -C "' . __DIR__ . '" describe --abbrev=0 --tags ' . (DIRECTORY_SEPARATOR === '\\' ? '2>nul' : '2>/dev/null'); |
||
74 | $stdout = \shell_exec($command); |
||
75 | if (\is_string($stdout)) { |
||
76 | return trim($stdout); |
||
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 | $semverRegexp = '/^([\d]+)\.([\d]+)\.([\d]+)(?:-([\dA-Za-z-]+(?:\.[\dA-Za-z-]+)*))?(?:\+[\dA-Za-z-]+)?$/'; |
||
90 | $changelog = \explode("\n", self::getPhpfastcacheChangelog()); |
||
91 | foreach ($changelog as $line) { |
||
92 | $trimmedLine = \trim($line, " \t\n\r\0\x0B#"); |
||
93 | if (\str_starts_with($line, '#') && \preg_match($semverRegexp, $trimmedLine)) { |
||
94 | return $trimmedLine; |
||
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( |
||
100 | '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.' |
||
101 | ); |
||
163 |