diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index fd60101c2..df50051d9 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -14,7 +14,10 @@ 'bin/box', 'bin/generate_default_stub', ]) - ->exclude('build/dir018/var') + ->exclude([ + 'bench', + 'build/dir018/var', + ]) ->notName('*-phar-stub.php'); $overriddenRules = [ diff --git a/fixtures/bench/with-compactors/res/requirement-checker/bin/check-requirements.php b/fixtures/bench/with-compactors/res/requirement-checker/bin/check-requirements.php index 99eaca5bc..43c38684f 100644 --- a/fixtures/bench/with-compactors/res/requirement-checker/bin/check-requirements.php +++ b/fixtures/bench/with-compactors/res/requirement-checker/bin/check-requirements.php @@ -1,45 +1,24 @@ - * Théo Fidry - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - namespace HumbugBox451\KevinGH\RequirementChecker; -use function gettype; -use function in_array; -use function is_bool; -use function is_string; -use const false; -use const PHP_EOL; -use const PHP_SAPI; -use const true; - if (isset($_SERVER['BOX_REQUIREMENT_CHECKER'])) { $enableRequirementChecker = $_SERVER['BOX_REQUIREMENT_CHECKER']; - if (is_bool($enableRequirementChecker) && !$enableRequirementChecker) { + if (\is_bool($enableRequirementChecker) && !$enableRequirementChecker) { return; } - if (is_string($enableRequirementChecker) && in_array(mb_strtolower($enableRequirementChecker), ['false', '0'], true)) { + if (\is_string($enableRequirementChecker) && \in_array(\strtolower($enableRequirementChecker), ['false', '0'], \true)) { return; } - if (!is_bool($enableRequirementChecker) && !is_string($enableRequirementChecker)) { - echo PHP_EOL.'Unhandled value type for "BOX_REQUIREMENT_CHECKER". Got "'.gettype($enableRequirementChecker).'". Proceeding with the requirement checks.'.PHP_EOL; + if (!\is_bool($enableRequirementChecker) && !\is_string($enableRequirementChecker)) { + echo \PHP_EOL . 'Unhandled value type for "BOX_REQUIREMENT_CHECKER". Got "' . \gettype($enableRequirementChecker) . '". Proceeding with the requirement checks.' . \PHP_EOL; } } -if (false === in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed', 'micro'], true)) { - echo PHP_EOL.'The application may only be invoked from a command line, got "'.PHP_SAPI.'"'.PHP_EOL; +if (\false === \in_array(\PHP_SAPI, array('cli', 'phpdbg', 'embed', 'micro'), \true)) { + echo \PHP_EOL . 'The application may only be invoked from a command line, got "' . \PHP_SAPI . '"' . \PHP_EOL; exit(1); } -require __DIR__.'/../vendor/autoload.php'; +require __DIR__ . '/../vendor/autoload.php'; if (!Checker::checkRequirements()) { exit(1); } diff --git a/fixtures/bench/with-compactors/res/requirement-checker/src/Checker.php b/fixtures/bench/with-compactors/res/requirement-checker/src/Checker.php index 5a2896d20..21850a9a7 100644 --- a/fixtures/bench/with-compactors/res/requirement-checker/src/Checker.php +++ b/fixtures/bench/with-compactors/res/requirement-checker/src/Checker.php @@ -1,53 +1,36 @@ - * Théo Fidry - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - +declare (strict_types=1); namespace HumbugBox451\KevinGH\RequirementChecker; use InvalidArgumentException; use function count; use function sprintf; -use const false; -use const PHP_VERSION; - /** @internal */ final class Checker { private static $requirementsConfig; - - public static function checkRequirements(): bool + public static function checkRequirements() : bool { $requirements = self::retrieveRequirements(); $checkPassed = $requirements->evaluateRequirements(); $io = new IO(); self::printCheck($checkPassed, new Printer($io->getVerbosity(), $io->hasColorSupport()), $requirements); - return $checkPassed; } - - public static function printCheck($checkPassed, Printer $printer, RequirementCollection $requirements): void + public static function printCheck($checkPassed, Printer $printer, RequirementCollection $requirements) : void { - if (false === $checkPassed && IO::VERBOSITY_VERY_VERBOSE > $printer->getVerbosity()) { + if (\false === $checkPassed && IO::VERBOSITY_VERY_VERBOSE > $printer->getVerbosity()) { $printer->setVerbosity(IO::VERBOSITY_VERY_VERBOSE); } $verbosity = IO::VERBOSITY_VERY_VERBOSE; $iniPath = $requirements->getPhpIniPath(); $printer->title('Box Requirements Checker', $verbosity); $printer->printv('> Using PHP ', $verbosity); - $printer->printvln(PHP_VERSION, $verbosity, 'green'); + $printer->printvln(\PHP_VERSION, $verbosity, 'green'); if ($iniPath) { $printer->printvln('> PHP is using the following php.ini file:', $verbosity); - $printer->printvln(' '.$iniPath, $verbosity, 'green'); + $printer->printvln(' ' . $iniPath, $verbosity, 'green'); } else { $printer->printvln('> PHP is not using any php.ini file.', $verbosity, 'yellow'); } @@ -62,18 +45,17 @@ public static function printCheck($checkPassed, Printer $printer, RequirementCol foreach ($requirements->getRequirements() as $requirement) { if ($errorMessage = $printer->getRequirementErrorMessage($requirement)) { if (IO::VERBOSITY_DEBUG === $printer->getVerbosity()) { - $printer->printvln('✘ '.$requirement->getTestMessage(), IO::VERBOSITY_DEBUG, 'red'); + $printer->printvln('✘ ' . $requirement->getTestMessage(), IO::VERBOSITY_DEBUG, 'red'); $printer->printv(' ', IO::VERBOSITY_DEBUG); $errorMessages[] = $errorMessage; } else { $printer->printv('E', $verbosity, 'red'); $errorMessages[] = $errorMessage; } - continue; } if (IO::VERBOSITY_DEBUG === $printer->getVerbosity()) { - $printer->printvln('✔ '.$requirement->getTestMessage(), IO::VERBOSITY_DEBUG, 'green'); + $printer->printvln('✔ ' . $requirement->getTestMessage(), IO::VERBOSITY_DEBUG, 'green'); $printer->printv(' ', IO::VERBOSITY_DEBUG); } else { $printer->printv('.', $verbosity, 'green'); @@ -88,27 +70,24 @@ public static function printCheck($checkPassed, Printer $printer, RequirementCol $printer->block('ERROR', 'Your system is not ready to run the application.', $verbosity, 'error'); $printer->title('Fix the following mandatory requirements:', $verbosity, 'red'); foreach ($errorMessages as $errorMessage) { - $printer->printv(' * '.$errorMessage, $verbosity); + $printer->printv(' * ' . $errorMessage, $verbosity); } } $printer->printvln('', $verbosity); } - - private static function retrieveRequirements(): RequirementCollection + private static function retrieveRequirements() : RequirementCollection { if (null === self::$requirementsConfig) { - self::$requirementsConfig = __DIR__.'/../.requirements.php'; + self::$requirementsConfig = __DIR__ . '/../.requirements.php'; } $config = (require self::$requirementsConfig); $requirements = new RequirementCollection(); foreach ($config as $constraint) { $requirements->addRequirement(self::createCondition($constraint['type'], $constraint['condition']), $constraint['message'], $constraint['helpMessage']); } - return $requirements; } - - private static function createCondition($type, $condition): IsFulfilled + private static function createCondition($type, $condition) : IsFulfilled { switch ($type) { case 'php': diff --git a/fixtures/bench/with-compactors/res/requirement-checker/src/IO.php b/fixtures/bench/with-compactors/res/requirement-checker/src/IO.php index 6d9cf869e..f9b3b12bf 100644 --- a/fixtures/bench/with-compactors/res/requirement-checker/src/IO.php +++ b/fixtures/bench/with-compactors/res/requirement-checker/src/IO.php @@ -1,17 +1,6 @@ - * Théo Fidry - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - +declare (strict_types=1); namespace HumbugBox451\KevinGH\RequirementChecker; use function fstat; @@ -26,10 +15,7 @@ use function str_replace; use function stream_isatty; use const DIRECTORY_SEPARATOR; -use const false; use const STDOUT; -use const true; - /** @internal */ final class IO { @@ -42,7 +28,6 @@ final class IO private $verbosity = self::VERBOSITY_NORMAL; private $colorSupport; private $options; - public function __construct() { $this->options = implode(' ', $_SERVER['argv']); @@ -50,51 +35,43 @@ public function __construct() $this->interactive = $this->checkInteractivity($shellVerbosity); $this->colorSupport = $this->checkColorSupport(); } - - public function isInteractive(): bool + public function isInteractive() : bool { return $this->interactive; } - - public function getVerbosity(): int + public function getVerbosity() : int { return $this->verbosity; } - - public function hasColorSupport(): bool + public function hasColorSupport() : bool { return $this->colorSupport; } - - public function hasParameter($values): bool + public function hasParameter($values) : bool { $values = (array) $values; foreach ($values as $value) { $regexp = sprintf('/\\s%s\\b/', str_replace(' ', '\\s+', preg_quote($value, '/'))); if (1 === preg_match($regexp, $this->options)) { - return true; + return \true; } } - - return false; + return \false; } - - private function checkInteractivity(int $shellVerbosity): bool + private function checkInteractivity(int $shellVerbosity) : bool { if (-1 === $shellVerbosity) { - return false; + return \false; } - if (true === $this->hasParameter(['--no-interaction', '-n'])) { - return false; + if (\true === $this->hasParameter(['--no-interaction', '-n'])) { + return \false; } - if (function_exists('posix_isatty') && !@posix_isatty(STDOUT) && false === getenv('SHELL_INTERACTIVE')) { - return false; + if (function_exists('posix_isatty') && !@posix_isatty(STDOUT) && \false === getenv('SHELL_INTERACTIVE')) { + return \false; } - - return true; + return \true; } - - private function configureVerbosity(): int + private function configureVerbosity() : int { switch ($shellVerbosity = (int) getenv('SHELL_VERBOSITY')) { case -1: @@ -126,20 +103,18 @@ private function configureVerbosity(): int $this->verbosity = self::VERBOSITY_VERBOSE; $shellVerbosity = 1; } - return $shellVerbosity; } - - private function checkColorSupport(): bool + private function checkColorSupport() : bool { if ($this->hasParameter(['--ansi'])) { - return true; + return \true; } if ($this->hasParameter(['--no-ansi'])) { - return false; + return \false; } if (DIRECTORY_SEPARATOR === '\\') { - return function_exists('sapi_windows_vt100_support') && sapi_windows_vt100_support(STDOUT) || false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI') || 'xterm' === getenv('TERM'); + return function_exists('sapi_windows_vt100_support') && sapi_windows_vt100_support(STDOUT) || \false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI') || 'xterm' === getenv('TERM'); } if (function_exists('stream_isatty')) { return stream_isatty(STDOUT); @@ -148,7 +123,6 @@ private function checkColorSupport(): bool return posix_isatty(STDOUT); } $stat = fstat(STDOUT); - - return $stat ? 0o20000 === ($stat['mode'] & 0o170000) : false; + return $stat ? 020000 === ($stat['mode'] & 0170000) : \false; } } diff --git a/fixtures/bench/with-compactors/res/requirement-checker/src/IsExtensionConflictFulfilled.php b/fixtures/bench/with-compactors/res/requirement-checker/src/IsExtensionConflictFulfilled.php index b829755a2..a8fa58f59 100644 --- a/fixtures/bench/with-compactors/res/requirement-checker/src/IsExtensionConflictFulfilled.php +++ b/fixtures/bench/with-compactors/res/requirement-checker/src/IsExtensionConflictFulfilled.php @@ -1,32 +1,18 @@ - * Théo Fidry - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - +declare (strict_types=1); namespace HumbugBox451\KevinGH\RequirementChecker; use function extension_loaded; - /** @internal */ final class IsExtensionConflictFulfilled implements IsFulfilled { private $conflictingExtension; - public function __construct(string $requiredExtension) { $this->conflictingExtension = $requiredExtension; } - - public function __invoke(): bool + public function __invoke() : bool { return !extension_loaded($this->conflictingExtension); } diff --git a/fixtures/bench/with-compactors/res/requirement-checker/src/IsExtensionFulfilled.php b/fixtures/bench/with-compactors/res/requirement-checker/src/IsExtensionFulfilled.php index 79cdd212e..4e9111b2b 100644 --- a/fixtures/bench/with-compactors/res/requirement-checker/src/IsExtensionFulfilled.php +++ b/fixtures/bench/with-compactors/res/requirement-checker/src/IsExtensionFulfilled.php @@ -1,32 +1,18 @@ - * Théo Fidry - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - +declare (strict_types=1); namespace HumbugBox451\KevinGH\RequirementChecker; use function extension_loaded; - /** @internal */ final class IsExtensionFulfilled implements IsFulfilled { private $requiredExtension; - public function __construct(string $requiredExtension) { $this->requiredExtension = $requiredExtension; } - - public function __invoke(): bool + public function __invoke() : bool { return extension_loaded($this->requiredExtension); } diff --git a/fixtures/bench/with-compactors/res/requirement-checker/src/IsFulfilled.php b/fixtures/bench/with-compactors/res/requirement-checker/src/IsFulfilled.php index 353270a7d..4087023d0 100644 --- a/fixtures/bench/with-compactors/res/requirement-checker/src/IsFulfilled.php +++ b/fixtures/bench/with-compactors/res/requirement-checker/src/IsFulfilled.php @@ -1,21 +1,10 @@ - * Théo Fidry - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - +declare (strict_types=1); namespace HumbugBox451\KevinGH\RequirementChecker; /** @internal */ interface IsFulfilled { - public function __invoke(): bool; + public function __invoke() : bool; } diff --git a/fixtures/bench/with-compactors/res/requirement-checker/src/IsPhpVersionFulfilled.php b/fixtures/bench/with-compactors/res/requirement-checker/src/IsPhpVersionFulfilled.php index fd88cf43b..2ba78b424 100644 --- a/fixtures/bench/with-compactors/res/requirement-checker/src/IsPhpVersionFulfilled.php +++ b/fixtures/bench/with-compactors/res/requirement-checker/src/IsPhpVersionFulfilled.php @@ -1,17 +1,6 @@ - * Théo Fidry - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - +declare (strict_types=1); namespace HumbugBox451\KevinGH\RequirementChecker; use HumbugBox451\Composer\Semver\Semver; @@ -19,18 +8,15 @@ use const PHP_MAJOR_VERSION; use const PHP_MINOR_VERSION; use const PHP_RELEASE_VERSION; - /** @internal */ final class IsPhpVersionFulfilled implements IsFulfilled { private $requiredPhpVersion; - public function __construct(string $requiredPhpVersion) { $this->requiredPhpVersion = $requiredPhpVersion; } - - public function __invoke(): bool + public function __invoke() : bool { return Semver::satisfies(sprintf('%d.%d.%d', PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION), $this->requiredPhpVersion); } diff --git a/fixtures/bench/with-compactors/res/requirement-checker/src/Printer.php b/fixtures/bench/with-compactors/res/requirement-checker/src/Printer.php index f26b424c2..68ba63edb 100644 --- a/fixtures/bench/with-compactors/res/requirement-checker/src/Printer.php +++ b/fixtures/bench/with-compactors/res/requirement-checker/src/Printer.php @@ -1,35 +1,20 @@ - * Théo Fidry - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - +declare (strict_types=1); namespace HumbugBox451\KevinGH\RequirementChecker; use function array_shift; use function count; use function explode; -use function fwrite; -use function getenv; use function ltrim; use function min; use function sprintf; use function str_pad; use function str_repeat; +use function strlen; use function trim; use function wordwrap; use const PHP_EOL; -use const STDERR; -use const STR_PAD_RIGHT; - /** @internal */ final class Printer { @@ -37,7 +22,6 @@ final class Printer private $verbosity; private $supportColors; private $width; - public function __construct(int $verbosity, bool $supportColors, ?int $width = null) { if (null === $width) { @@ -48,45 +32,39 @@ public function __construct(int $verbosity, bool $supportColors, ?int $width = n $this->supportColors = $supportColors; $this->width = $width ?: 80; } - - public function getVerbosity(): int + public function getVerbosity() : int { return $this->verbosity; } - - public function setVerbosity($verbosity): void + public function setVerbosity($verbosity) : void { $this->verbosity = $verbosity; } - - public function title(string $title, int $verbosity, ?string $style = null): void + public function title(string $title, int $verbosity, ?string $style = null) : void { if (null === $style) { $style = 'title'; } $this->printvln('', $verbosity, $style); $this->printvln($title, $verbosity, $style); - $this->printvln(str_repeat('=', min(mb_strlen($title), $this->width)), $verbosity, $style); + $this->printvln(str_repeat('=', min(strlen($title), $this->width)), $verbosity, $style); $this->printvln('', $verbosity, $style); } - - public function getRequirementErrorMessage(Requirement $requirement): ?string + public function getRequirementErrorMessage(Requirement $requirement) : ?string { if ($requirement->isFulfilled()) { return null; } - - return wordwrap($requirement->getHelpText(), $this->width - 3, PHP_EOL.' ').PHP_EOL; + return wordwrap($requirement->getHelpText(), $this->width - 3, PHP_EOL . ' ') . PHP_EOL; } - - public function block(string $title, string $message, int $verbosity, ?string $style = null): void + public function block(string $title, string $message, int $verbosity, ?string $style = null) : void { - $prefix = ' ['.$title.'] '; - $lineLength = $this->width - mb_strlen($prefix) - 1; + $prefix = ' [' . $title . '] '; + $lineLength = $this->width - strlen($prefix) - 1; if ($lineLength < 0) { $lineLength = 0; } - $message = $prefix.trim($message); + $message = $prefix . trim($message); $lines = []; $remainingMessage = $message; $wrapped = wordwrap($remainingMessage, $lineLength, '¬'); @@ -94,9 +72,9 @@ public function block(string $title, string $message, int $verbosity, ?string $s do { $line = array_shift($wrapped); if ($lines && $lineLength > 0) { - $line = str_repeat(' ', mb_strlen($prefix)).ltrim($line); + $line = str_repeat(' ', strlen($prefix)) . ltrim($line); } - $lines[] = str_pad($line, $this->width, ' ', STR_PAD_RIGHT); + $lines[] = str_pad($line, $this->width, ' ', \STR_PAD_RIGHT); } while (count($wrapped)); $this->printvln('', $verbosity); $this->printvln(str_repeat(' ', $this->width), $verbosity, $style); @@ -106,24 +84,22 @@ public function block(string $title, string $message, int $verbosity, ?string $s $this->printv(str_repeat(' ', $this->width), $verbosity, $style); $this->printvln('', $verbosity); } - - public function printvln(string $message, int $verbosity, ?string $style = null): void + public function printvln(string $message, int $verbosity, ?string $style = null) : void { $this->printv($message, $verbosity, $style); $this->printv(PHP_EOL, $verbosity, null); } - - public function printv(string $message, int $verbosity, ?string $style = null): void + public function printv(string $message, int $verbosity, ?string $style = null) : void { if ($verbosity > $this->verbosity) { return; } $message = wordwrap($message, $this->width); $message = sprintf('%s%s%s', $this->supportColors && isset($this->styles[$style]) ? $this->styles[$style] : '', $message, $this->supportColors ? $this->styles['reset'] : ''); - if ('1' === getenv('BOX_REQUIREMENTS_CHECKER_LOG_TO_STDOUT')) { + if ('1' === \getenv('BOX_REQUIREMENTS_CHECKER_LOG_TO_STDOUT')) { echo $message; } else { - fwrite(STDERR, $message); + \fwrite(\STDERR, $message); } } } diff --git a/fixtures/bench/with-compactors/res/requirement-checker/src/Requirement.php b/fixtures/bench/with-compactors/res/requirement-checker/src/Requirement.php index 22ce53364..b18a73aa6 100644 --- a/fixtures/bench/with-compactors/res/requirement-checker/src/Requirement.php +++ b/fixtures/bench/with-compactors/res/requirement-checker/src/Requirement.php @@ -1,17 +1,6 @@ - * Théo Fidry - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - +declare (strict_types=1); namespace HumbugBox451\KevinGH\RequirementChecker; /** @internal */ @@ -21,34 +10,28 @@ final class Requirement private $fulfilled; private $testMessage; private $helpText; - public function __construct(IsFulfilled $checkIsFulfilled, string $testMessage, string $helpText) { $this->checkIsFulfilled = $checkIsFulfilled; $this->testMessage = $testMessage; $this->helpText = $helpText; } - - public function isFulfilled(): bool + public function isFulfilled() : bool { if (!isset($this->fulfilled)) { $this->fulfilled = $this->checkIsFulfilled->__invoke(); } - return $this->fulfilled; } - - public function getIsFullfilledChecker(): IsFulfilled + public function getIsFullfilledChecker() : IsFulfilled { return $this->checkIsFulfilled; } - - public function getTestMessage(): string + public function getTestMessage() : string { return $this->testMessage; } - - public function getHelpText(): string + public function getHelpText() : string { return $this->helpText; } diff --git a/fixtures/bench/with-compactors/res/requirement-checker/src/RequirementCollection.php b/fixtures/bench/with-compactors/res/requirement-checker/src/RequirementCollection.php index 923602515..d7a7b6fb4 100644 --- a/fixtures/bench/with-compactors/res/requirement-checker/src/RequirementCollection.php +++ b/fixtures/bench/with-compactors/res/requirement-checker/src/RequirementCollection.php @@ -1,71 +1,51 @@ - * Théo Fidry - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - +declare (strict_types=1); namespace HumbugBox451\KevinGH\RequirementChecker; use ArrayIterator; use Countable; use IteratorAggregate; use Traversable; -use function array_reduce; use function count; use function get_cfg_var; -use const true; - /** @internal */ final class RequirementCollection implements IteratorAggregate, Countable { private $requirements = []; private $phpIniPath; - public function __construct($phpIniPath = null) { $this->phpIniPath = null === $phpIniPath ? get_cfg_var('cfg_file_path') : $phpIniPath; } - - public function getIterator(): Traversable + public function getIterator() : Traversable { return new ArrayIterator($this->requirements); } - - public function count(): int + public function count() : int { return count($this->requirements); } - - public function add(Requirement $requirement): void + public function add(Requirement $requirement) : void { $this->requirements[] = $requirement; } - - public function addRequirement(IsFulfilled $checkIsFulfilled, string $testMessage, string $helpText): void + public function addRequirement(IsFulfilled $checkIsFulfilled, string $testMessage, string $helpText) : void { $this->add(new Requirement($checkIsFulfilled, $testMessage, $helpText)); } - - public function getRequirements(): array + public function getRequirements() : array { return $this->requirements; } - public function getPhpIniPath() { return $this->phpIniPath; } - public function evaluateRequirements() { - return array_reduce($this->requirements, static fn (bool $checkPassed, Requirement $requirement): bool => $checkPassed && $requirement->isFulfilled(), true); + return \array_reduce($this->requirements, static function (bool $checkPassed, Requirement $requirement) : bool { + return $checkPassed && $requirement->isFulfilled(); + }, \true); } } diff --git a/fixtures/bench/with-compactors/res/requirement-checker/src/Terminal.php b/fixtures/bench/with-compactors/res/requirement-checker/src/Terminal.php index fdbb16333..999969357 100644 --- a/fixtures/bench/with-compactors/res/requirement-checker/src/Terminal.php +++ b/fixtures/bench/with-compactors/res/requirement-checker/src/Terminal.php @@ -1,17 +1,6 @@ - * Théo Fidry - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - +declare (strict_types=1); namespace HumbugBox451\KevinGH\RequirementChecker; use function exec; @@ -27,56 +16,46 @@ use function stream_get_contents; use function trim; use const DIRECTORY_SEPARATOR; -use const false; -use const true; - /** @internal */ class Terminal { private static $width; private static $height; private static $stty; - - public function getWidth(): int + public function getWidth() : int { $width = getenv('COLUMNS'); - if (false !== $width) { + if (\false !== $width) { return (int) trim($width); } if (!isset(self::$width)) { self::initDimensions(); } - return self::$width ?: 80; } - - public function getHeight(): int + public function getHeight() : int { $height = getenv('LINES'); - if (false !== $height) { + if (\false !== $height) { return (int) trim($height); } if (!isset(self::$height)) { self::initDimensions(); } - return self::$height ?: 50; } - - public static function hasSttyAvailable(): bool + public static function hasSttyAvailable() : bool { if (isset(self::$stty)) { return self::$stty; } if (!function_exists('exec')) { - return false; + return \false; } exec('stty 2>&1', $output, $exitcode); - return self::$stty = 0 === $exitcode; } - - private static function initDimensions(): void + private static function initDimensions() : void { if ('\\' === DIRECTORY_SEPARATOR) { if (preg_match('/^(\\d+)x(\\d+)(?: \\((\\d+)x(\\d+)\\))?$/', trim(getenv('ANSICON') ?: ''), $matches)) { @@ -92,13 +71,11 @@ private static function initDimensions(): void self::initDimensionsUsingStty(); } } - - private static function hasVt100Support(): bool + private static function hasVt100Support() : bool { return function_exists('sapi_windows_vt100_support') && sapi_windows_vt100_support(fopen('php://stdout', 'wb')); } - - private static function initDimensionsUsingStty(): void + private static function initDimensionsUsingStty() : void { if ($sttyString = self::getSttyColumns()) { if (preg_match('/rows.(\\d+);.columns.(\\d+);/i', $sttyString, $matches)) { @@ -110,29 +87,25 @@ private static function initDimensionsUsingStty(): void } } } - - private static function getConsoleMode(): ?array + private static function getConsoleMode() : ?array { $info = self::readFromProcess('mode CON'); if (null === $info || !preg_match('/--------+\\r?\\n.+?(\\d+)\\r?\\n.+?(\\d+)\\r?\\n/', $info, $matches)) { return null; } - return [(int) $matches[2], (int) $matches[1]]; } - - private static function getSttyColumns(): ?string + private static function getSttyColumns() : ?string { return self::readFromProcess('stty -a | grep columns'); } - - private static function readFromProcess(string $command): ?string + private static function readFromProcess(string $command) : ?string { if (!function_exists('proc_open')) { return null; } $descriptorspec = [1 => ['pipe', 'w'], 2 => ['pipe', 'w']]; - $process = proc_open($command, $descriptorspec, $pipes, null, null, ['suppress_errors' => true]); + $process = proc_open($command, $descriptorspec, $pipes, null, null, ['suppress_errors' => \true]); if (!is_resource($process)) { return null; } @@ -140,7 +113,6 @@ private static function readFromProcess(string $command): ?string fclose($pipes[1]); fclose($pipes[2]); proc_close($process); - return $info; } } diff --git a/fixtures/bench/without-compactors/res/requirement-checker/bin/check-requirements.php b/fixtures/bench/without-compactors/res/requirement-checker/bin/check-requirements.php index 99eaca5bc..43c38684f 100644 --- a/fixtures/bench/without-compactors/res/requirement-checker/bin/check-requirements.php +++ b/fixtures/bench/without-compactors/res/requirement-checker/bin/check-requirements.php @@ -1,45 +1,24 @@ - * Théo Fidry - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - namespace HumbugBox451\KevinGH\RequirementChecker; -use function gettype; -use function in_array; -use function is_bool; -use function is_string; -use const false; -use const PHP_EOL; -use const PHP_SAPI; -use const true; - if (isset($_SERVER['BOX_REQUIREMENT_CHECKER'])) { $enableRequirementChecker = $_SERVER['BOX_REQUIREMENT_CHECKER']; - if (is_bool($enableRequirementChecker) && !$enableRequirementChecker) { + if (\is_bool($enableRequirementChecker) && !$enableRequirementChecker) { return; } - if (is_string($enableRequirementChecker) && in_array(mb_strtolower($enableRequirementChecker), ['false', '0'], true)) { + if (\is_string($enableRequirementChecker) && \in_array(\strtolower($enableRequirementChecker), ['false', '0'], \true)) { return; } - if (!is_bool($enableRequirementChecker) && !is_string($enableRequirementChecker)) { - echo PHP_EOL.'Unhandled value type for "BOX_REQUIREMENT_CHECKER". Got "'.gettype($enableRequirementChecker).'". Proceeding with the requirement checks.'.PHP_EOL; + if (!\is_bool($enableRequirementChecker) && !\is_string($enableRequirementChecker)) { + echo \PHP_EOL . 'Unhandled value type for "BOX_REQUIREMENT_CHECKER". Got "' . \gettype($enableRequirementChecker) . '". Proceeding with the requirement checks.' . \PHP_EOL; } } -if (false === in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed', 'micro'], true)) { - echo PHP_EOL.'The application may only be invoked from a command line, got "'.PHP_SAPI.'"'.PHP_EOL; +if (\false === \in_array(\PHP_SAPI, array('cli', 'phpdbg', 'embed', 'micro'), \true)) { + echo \PHP_EOL . 'The application may only be invoked from a command line, got "' . \PHP_SAPI . '"' . \PHP_EOL; exit(1); } -require __DIR__.'/../vendor/autoload.php'; +require __DIR__ . '/../vendor/autoload.php'; if (!Checker::checkRequirements()) { exit(1); } diff --git a/fixtures/bench/without-compactors/res/requirement-checker/src/Checker.php b/fixtures/bench/without-compactors/res/requirement-checker/src/Checker.php index 5a2896d20..21850a9a7 100644 --- a/fixtures/bench/without-compactors/res/requirement-checker/src/Checker.php +++ b/fixtures/bench/without-compactors/res/requirement-checker/src/Checker.php @@ -1,53 +1,36 @@ - * Théo Fidry - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - +declare (strict_types=1); namespace HumbugBox451\KevinGH\RequirementChecker; use InvalidArgumentException; use function count; use function sprintf; -use const false; -use const PHP_VERSION; - /** @internal */ final class Checker { private static $requirementsConfig; - - public static function checkRequirements(): bool + public static function checkRequirements() : bool { $requirements = self::retrieveRequirements(); $checkPassed = $requirements->evaluateRequirements(); $io = new IO(); self::printCheck($checkPassed, new Printer($io->getVerbosity(), $io->hasColorSupport()), $requirements); - return $checkPassed; } - - public static function printCheck($checkPassed, Printer $printer, RequirementCollection $requirements): void + public static function printCheck($checkPassed, Printer $printer, RequirementCollection $requirements) : void { - if (false === $checkPassed && IO::VERBOSITY_VERY_VERBOSE > $printer->getVerbosity()) { + if (\false === $checkPassed && IO::VERBOSITY_VERY_VERBOSE > $printer->getVerbosity()) { $printer->setVerbosity(IO::VERBOSITY_VERY_VERBOSE); } $verbosity = IO::VERBOSITY_VERY_VERBOSE; $iniPath = $requirements->getPhpIniPath(); $printer->title('Box Requirements Checker', $verbosity); $printer->printv('> Using PHP ', $verbosity); - $printer->printvln(PHP_VERSION, $verbosity, 'green'); + $printer->printvln(\PHP_VERSION, $verbosity, 'green'); if ($iniPath) { $printer->printvln('> PHP is using the following php.ini file:', $verbosity); - $printer->printvln(' '.$iniPath, $verbosity, 'green'); + $printer->printvln(' ' . $iniPath, $verbosity, 'green'); } else { $printer->printvln('> PHP is not using any php.ini file.', $verbosity, 'yellow'); } @@ -62,18 +45,17 @@ public static function printCheck($checkPassed, Printer $printer, RequirementCol foreach ($requirements->getRequirements() as $requirement) { if ($errorMessage = $printer->getRequirementErrorMessage($requirement)) { if (IO::VERBOSITY_DEBUG === $printer->getVerbosity()) { - $printer->printvln('✘ '.$requirement->getTestMessage(), IO::VERBOSITY_DEBUG, 'red'); + $printer->printvln('✘ ' . $requirement->getTestMessage(), IO::VERBOSITY_DEBUG, 'red'); $printer->printv(' ', IO::VERBOSITY_DEBUG); $errorMessages[] = $errorMessage; } else { $printer->printv('E', $verbosity, 'red'); $errorMessages[] = $errorMessage; } - continue; } if (IO::VERBOSITY_DEBUG === $printer->getVerbosity()) { - $printer->printvln('✔ '.$requirement->getTestMessage(), IO::VERBOSITY_DEBUG, 'green'); + $printer->printvln('✔ ' . $requirement->getTestMessage(), IO::VERBOSITY_DEBUG, 'green'); $printer->printv(' ', IO::VERBOSITY_DEBUG); } else { $printer->printv('.', $verbosity, 'green'); @@ -88,27 +70,24 @@ public static function printCheck($checkPassed, Printer $printer, RequirementCol $printer->block('ERROR', 'Your system is not ready to run the application.', $verbosity, 'error'); $printer->title('Fix the following mandatory requirements:', $verbosity, 'red'); foreach ($errorMessages as $errorMessage) { - $printer->printv(' * '.$errorMessage, $verbosity); + $printer->printv(' * ' . $errorMessage, $verbosity); } } $printer->printvln('', $verbosity); } - - private static function retrieveRequirements(): RequirementCollection + private static function retrieveRequirements() : RequirementCollection { if (null === self::$requirementsConfig) { - self::$requirementsConfig = __DIR__.'/../.requirements.php'; + self::$requirementsConfig = __DIR__ . '/../.requirements.php'; } $config = (require self::$requirementsConfig); $requirements = new RequirementCollection(); foreach ($config as $constraint) { $requirements->addRequirement(self::createCondition($constraint['type'], $constraint['condition']), $constraint['message'], $constraint['helpMessage']); } - return $requirements; } - - private static function createCondition($type, $condition): IsFulfilled + private static function createCondition($type, $condition) : IsFulfilled { switch ($type) { case 'php': diff --git a/fixtures/bench/without-compactors/res/requirement-checker/src/IO.php b/fixtures/bench/without-compactors/res/requirement-checker/src/IO.php index 6d9cf869e..f9b3b12bf 100644 --- a/fixtures/bench/without-compactors/res/requirement-checker/src/IO.php +++ b/fixtures/bench/without-compactors/res/requirement-checker/src/IO.php @@ -1,17 +1,6 @@ - * Théo Fidry - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - +declare (strict_types=1); namespace HumbugBox451\KevinGH\RequirementChecker; use function fstat; @@ -26,10 +15,7 @@ use function str_replace; use function stream_isatty; use const DIRECTORY_SEPARATOR; -use const false; use const STDOUT; -use const true; - /** @internal */ final class IO { @@ -42,7 +28,6 @@ final class IO private $verbosity = self::VERBOSITY_NORMAL; private $colorSupport; private $options; - public function __construct() { $this->options = implode(' ', $_SERVER['argv']); @@ -50,51 +35,43 @@ public function __construct() $this->interactive = $this->checkInteractivity($shellVerbosity); $this->colorSupport = $this->checkColorSupport(); } - - public function isInteractive(): bool + public function isInteractive() : bool { return $this->interactive; } - - public function getVerbosity(): int + public function getVerbosity() : int { return $this->verbosity; } - - public function hasColorSupport(): bool + public function hasColorSupport() : bool { return $this->colorSupport; } - - public function hasParameter($values): bool + public function hasParameter($values) : bool { $values = (array) $values; foreach ($values as $value) { $regexp = sprintf('/\\s%s\\b/', str_replace(' ', '\\s+', preg_quote($value, '/'))); if (1 === preg_match($regexp, $this->options)) { - return true; + return \true; } } - - return false; + return \false; } - - private function checkInteractivity(int $shellVerbosity): bool + private function checkInteractivity(int $shellVerbosity) : bool { if (-1 === $shellVerbosity) { - return false; + return \false; } - if (true === $this->hasParameter(['--no-interaction', '-n'])) { - return false; + if (\true === $this->hasParameter(['--no-interaction', '-n'])) { + return \false; } - if (function_exists('posix_isatty') && !@posix_isatty(STDOUT) && false === getenv('SHELL_INTERACTIVE')) { - return false; + if (function_exists('posix_isatty') && !@posix_isatty(STDOUT) && \false === getenv('SHELL_INTERACTIVE')) { + return \false; } - - return true; + return \true; } - - private function configureVerbosity(): int + private function configureVerbosity() : int { switch ($shellVerbosity = (int) getenv('SHELL_VERBOSITY')) { case -1: @@ -126,20 +103,18 @@ private function configureVerbosity(): int $this->verbosity = self::VERBOSITY_VERBOSE; $shellVerbosity = 1; } - return $shellVerbosity; } - - private function checkColorSupport(): bool + private function checkColorSupport() : bool { if ($this->hasParameter(['--ansi'])) { - return true; + return \true; } if ($this->hasParameter(['--no-ansi'])) { - return false; + return \false; } if (DIRECTORY_SEPARATOR === '\\') { - return function_exists('sapi_windows_vt100_support') && sapi_windows_vt100_support(STDOUT) || false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI') || 'xterm' === getenv('TERM'); + return function_exists('sapi_windows_vt100_support') && sapi_windows_vt100_support(STDOUT) || \false !== getenv('ANSICON') || 'ON' === getenv('ConEmuANSI') || 'xterm' === getenv('TERM'); } if (function_exists('stream_isatty')) { return stream_isatty(STDOUT); @@ -148,7 +123,6 @@ private function checkColorSupport(): bool return posix_isatty(STDOUT); } $stat = fstat(STDOUT); - - return $stat ? 0o20000 === ($stat['mode'] & 0o170000) : false; + return $stat ? 020000 === ($stat['mode'] & 0170000) : \false; } } diff --git a/fixtures/bench/without-compactors/res/requirement-checker/src/IsExtensionConflictFulfilled.php b/fixtures/bench/without-compactors/res/requirement-checker/src/IsExtensionConflictFulfilled.php index b829755a2..a8fa58f59 100644 --- a/fixtures/bench/without-compactors/res/requirement-checker/src/IsExtensionConflictFulfilled.php +++ b/fixtures/bench/without-compactors/res/requirement-checker/src/IsExtensionConflictFulfilled.php @@ -1,32 +1,18 @@ - * Théo Fidry - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - +declare (strict_types=1); namespace HumbugBox451\KevinGH\RequirementChecker; use function extension_loaded; - /** @internal */ final class IsExtensionConflictFulfilled implements IsFulfilled { private $conflictingExtension; - public function __construct(string $requiredExtension) { $this->conflictingExtension = $requiredExtension; } - - public function __invoke(): bool + public function __invoke() : bool { return !extension_loaded($this->conflictingExtension); } diff --git a/fixtures/bench/without-compactors/res/requirement-checker/src/IsExtensionFulfilled.php b/fixtures/bench/without-compactors/res/requirement-checker/src/IsExtensionFulfilled.php index 79cdd212e..4e9111b2b 100644 --- a/fixtures/bench/without-compactors/res/requirement-checker/src/IsExtensionFulfilled.php +++ b/fixtures/bench/without-compactors/res/requirement-checker/src/IsExtensionFulfilled.php @@ -1,32 +1,18 @@ - * Théo Fidry - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - +declare (strict_types=1); namespace HumbugBox451\KevinGH\RequirementChecker; use function extension_loaded; - /** @internal */ final class IsExtensionFulfilled implements IsFulfilled { private $requiredExtension; - public function __construct(string $requiredExtension) { $this->requiredExtension = $requiredExtension; } - - public function __invoke(): bool + public function __invoke() : bool { return extension_loaded($this->requiredExtension); } diff --git a/fixtures/bench/without-compactors/res/requirement-checker/src/IsFulfilled.php b/fixtures/bench/without-compactors/res/requirement-checker/src/IsFulfilled.php index 353270a7d..4087023d0 100644 --- a/fixtures/bench/without-compactors/res/requirement-checker/src/IsFulfilled.php +++ b/fixtures/bench/without-compactors/res/requirement-checker/src/IsFulfilled.php @@ -1,21 +1,10 @@ - * Théo Fidry - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - +declare (strict_types=1); namespace HumbugBox451\KevinGH\RequirementChecker; /** @internal */ interface IsFulfilled { - public function __invoke(): bool; + public function __invoke() : bool; } diff --git a/fixtures/bench/without-compactors/res/requirement-checker/src/IsPhpVersionFulfilled.php b/fixtures/bench/without-compactors/res/requirement-checker/src/IsPhpVersionFulfilled.php index fd88cf43b..2ba78b424 100644 --- a/fixtures/bench/without-compactors/res/requirement-checker/src/IsPhpVersionFulfilled.php +++ b/fixtures/bench/without-compactors/res/requirement-checker/src/IsPhpVersionFulfilled.php @@ -1,17 +1,6 @@ - * Théo Fidry - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - +declare (strict_types=1); namespace HumbugBox451\KevinGH\RequirementChecker; use HumbugBox451\Composer\Semver\Semver; @@ -19,18 +8,15 @@ use const PHP_MAJOR_VERSION; use const PHP_MINOR_VERSION; use const PHP_RELEASE_VERSION; - /** @internal */ final class IsPhpVersionFulfilled implements IsFulfilled { private $requiredPhpVersion; - public function __construct(string $requiredPhpVersion) { $this->requiredPhpVersion = $requiredPhpVersion; } - - public function __invoke(): bool + public function __invoke() : bool { return Semver::satisfies(sprintf('%d.%d.%d', PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION), $this->requiredPhpVersion); } diff --git a/fixtures/bench/without-compactors/res/requirement-checker/src/Printer.php b/fixtures/bench/without-compactors/res/requirement-checker/src/Printer.php index f26b424c2..68ba63edb 100644 --- a/fixtures/bench/without-compactors/res/requirement-checker/src/Printer.php +++ b/fixtures/bench/without-compactors/res/requirement-checker/src/Printer.php @@ -1,35 +1,20 @@ - * Théo Fidry - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - +declare (strict_types=1); namespace HumbugBox451\KevinGH\RequirementChecker; use function array_shift; use function count; use function explode; -use function fwrite; -use function getenv; use function ltrim; use function min; use function sprintf; use function str_pad; use function str_repeat; +use function strlen; use function trim; use function wordwrap; use const PHP_EOL; -use const STDERR; -use const STR_PAD_RIGHT; - /** @internal */ final class Printer { @@ -37,7 +22,6 @@ final class Printer private $verbosity; private $supportColors; private $width; - public function __construct(int $verbosity, bool $supportColors, ?int $width = null) { if (null === $width) { @@ -48,45 +32,39 @@ public function __construct(int $verbosity, bool $supportColors, ?int $width = n $this->supportColors = $supportColors; $this->width = $width ?: 80; } - - public function getVerbosity(): int + public function getVerbosity() : int { return $this->verbosity; } - - public function setVerbosity($verbosity): void + public function setVerbosity($verbosity) : void { $this->verbosity = $verbosity; } - - public function title(string $title, int $verbosity, ?string $style = null): void + public function title(string $title, int $verbosity, ?string $style = null) : void { if (null === $style) { $style = 'title'; } $this->printvln('', $verbosity, $style); $this->printvln($title, $verbosity, $style); - $this->printvln(str_repeat('=', min(mb_strlen($title), $this->width)), $verbosity, $style); + $this->printvln(str_repeat('=', min(strlen($title), $this->width)), $verbosity, $style); $this->printvln('', $verbosity, $style); } - - public function getRequirementErrorMessage(Requirement $requirement): ?string + public function getRequirementErrorMessage(Requirement $requirement) : ?string { if ($requirement->isFulfilled()) { return null; } - - return wordwrap($requirement->getHelpText(), $this->width - 3, PHP_EOL.' ').PHP_EOL; + return wordwrap($requirement->getHelpText(), $this->width - 3, PHP_EOL . ' ') . PHP_EOL; } - - public function block(string $title, string $message, int $verbosity, ?string $style = null): void + public function block(string $title, string $message, int $verbosity, ?string $style = null) : void { - $prefix = ' ['.$title.'] '; - $lineLength = $this->width - mb_strlen($prefix) - 1; + $prefix = ' [' . $title . '] '; + $lineLength = $this->width - strlen($prefix) - 1; if ($lineLength < 0) { $lineLength = 0; } - $message = $prefix.trim($message); + $message = $prefix . trim($message); $lines = []; $remainingMessage = $message; $wrapped = wordwrap($remainingMessage, $lineLength, '¬'); @@ -94,9 +72,9 @@ public function block(string $title, string $message, int $verbosity, ?string $s do { $line = array_shift($wrapped); if ($lines && $lineLength > 0) { - $line = str_repeat(' ', mb_strlen($prefix)).ltrim($line); + $line = str_repeat(' ', strlen($prefix)) . ltrim($line); } - $lines[] = str_pad($line, $this->width, ' ', STR_PAD_RIGHT); + $lines[] = str_pad($line, $this->width, ' ', \STR_PAD_RIGHT); } while (count($wrapped)); $this->printvln('', $verbosity); $this->printvln(str_repeat(' ', $this->width), $verbosity, $style); @@ -106,24 +84,22 @@ public function block(string $title, string $message, int $verbosity, ?string $s $this->printv(str_repeat(' ', $this->width), $verbosity, $style); $this->printvln('', $verbosity); } - - public function printvln(string $message, int $verbosity, ?string $style = null): void + public function printvln(string $message, int $verbosity, ?string $style = null) : void { $this->printv($message, $verbosity, $style); $this->printv(PHP_EOL, $verbosity, null); } - - public function printv(string $message, int $verbosity, ?string $style = null): void + public function printv(string $message, int $verbosity, ?string $style = null) : void { if ($verbosity > $this->verbosity) { return; } $message = wordwrap($message, $this->width); $message = sprintf('%s%s%s', $this->supportColors && isset($this->styles[$style]) ? $this->styles[$style] : '', $message, $this->supportColors ? $this->styles['reset'] : ''); - if ('1' === getenv('BOX_REQUIREMENTS_CHECKER_LOG_TO_STDOUT')) { + if ('1' === \getenv('BOX_REQUIREMENTS_CHECKER_LOG_TO_STDOUT')) { echo $message; } else { - fwrite(STDERR, $message); + \fwrite(\STDERR, $message); } } } diff --git a/fixtures/bench/without-compactors/res/requirement-checker/src/Requirement.php b/fixtures/bench/without-compactors/res/requirement-checker/src/Requirement.php index 22ce53364..b18a73aa6 100644 --- a/fixtures/bench/without-compactors/res/requirement-checker/src/Requirement.php +++ b/fixtures/bench/without-compactors/res/requirement-checker/src/Requirement.php @@ -1,17 +1,6 @@ - * Théo Fidry - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - +declare (strict_types=1); namespace HumbugBox451\KevinGH\RequirementChecker; /** @internal */ @@ -21,34 +10,28 @@ final class Requirement private $fulfilled; private $testMessage; private $helpText; - public function __construct(IsFulfilled $checkIsFulfilled, string $testMessage, string $helpText) { $this->checkIsFulfilled = $checkIsFulfilled; $this->testMessage = $testMessage; $this->helpText = $helpText; } - - public function isFulfilled(): bool + public function isFulfilled() : bool { if (!isset($this->fulfilled)) { $this->fulfilled = $this->checkIsFulfilled->__invoke(); } - return $this->fulfilled; } - - public function getIsFullfilledChecker(): IsFulfilled + public function getIsFullfilledChecker() : IsFulfilled { return $this->checkIsFulfilled; } - - public function getTestMessage(): string + public function getTestMessage() : string { return $this->testMessage; } - - public function getHelpText(): string + public function getHelpText() : string { return $this->helpText; } diff --git a/fixtures/bench/without-compactors/res/requirement-checker/src/RequirementCollection.php b/fixtures/bench/without-compactors/res/requirement-checker/src/RequirementCollection.php index 923602515..d7a7b6fb4 100644 --- a/fixtures/bench/without-compactors/res/requirement-checker/src/RequirementCollection.php +++ b/fixtures/bench/without-compactors/res/requirement-checker/src/RequirementCollection.php @@ -1,71 +1,51 @@ - * Théo Fidry - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - +declare (strict_types=1); namespace HumbugBox451\KevinGH\RequirementChecker; use ArrayIterator; use Countable; use IteratorAggregate; use Traversable; -use function array_reduce; use function count; use function get_cfg_var; -use const true; - /** @internal */ final class RequirementCollection implements IteratorAggregate, Countable { private $requirements = []; private $phpIniPath; - public function __construct($phpIniPath = null) { $this->phpIniPath = null === $phpIniPath ? get_cfg_var('cfg_file_path') : $phpIniPath; } - - public function getIterator(): Traversable + public function getIterator() : Traversable { return new ArrayIterator($this->requirements); } - - public function count(): int + public function count() : int { return count($this->requirements); } - - public function add(Requirement $requirement): void + public function add(Requirement $requirement) : void { $this->requirements[] = $requirement; } - - public function addRequirement(IsFulfilled $checkIsFulfilled, string $testMessage, string $helpText): void + public function addRequirement(IsFulfilled $checkIsFulfilled, string $testMessage, string $helpText) : void { $this->add(new Requirement($checkIsFulfilled, $testMessage, $helpText)); } - - public function getRequirements(): array + public function getRequirements() : array { return $this->requirements; } - public function getPhpIniPath() { return $this->phpIniPath; } - public function evaluateRequirements() { - return array_reduce($this->requirements, static fn (bool $checkPassed, Requirement $requirement): bool => $checkPassed && $requirement->isFulfilled(), true); + return \array_reduce($this->requirements, static function (bool $checkPassed, Requirement $requirement) : bool { + return $checkPassed && $requirement->isFulfilled(); + }, \true); } } diff --git a/fixtures/bench/without-compactors/res/requirement-checker/src/Terminal.php b/fixtures/bench/without-compactors/res/requirement-checker/src/Terminal.php index fdbb16333..999969357 100644 --- a/fixtures/bench/without-compactors/res/requirement-checker/src/Terminal.php +++ b/fixtures/bench/without-compactors/res/requirement-checker/src/Terminal.php @@ -1,17 +1,6 @@ - * Théo Fidry - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - +declare (strict_types=1); namespace HumbugBox451\KevinGH\RequirementChecker; use function exec; @@ -27,56 +16,46 @@ use function stream_get_contents; use function trim; use const DIRECTORY_SEPARATOR; -use const false; -use const true; - /** @internal */ class Terminal { private static $width; private static $height; private static $stty; - - public function getWidth(): int + public function getWidth() : int { $width = getenv('COLUMNS'); - if (false !== $width) { + if (\false !== $width) { return (int) trim($width); } if (!isset(self::$width)) { self::initDimensions(); } - return self::$width ?: 80; } - - public function getHeight(): int + public function getHeight() : int { $height = getenv('LINES'); - if (false !== $height) { + if (\false !== $height) { return (int) trim($height); } if (!isset(self::$height)) { self::initDimensions(); } - return self::$height ?: 50; } - - public static function hasSttyAvailable(): bool + public static function hasSttyAvailable() : bool { if (isset(self::$stty)) { return self::$stty; } if (!function_exists('exec')) { - return false; + return \false; } exec('stty 2>&1', $output, $exitcode); - return self::$stty = 0 === $exitcode; } - - private static function initDimensions(): void + private static function initDimensions() : void { if ('\\' === DIRECTORY_SEPARATOR) { if (preg_match('/^(\\d+)x(\\d+)(?: \\((\\d+)x(\\d+)\\))?$/', trim(getenv('ANSICON') ?: ''), $matches)) { @@ -92,13 +71,11 @@ private static function initDimensions(): void self::initDimensionsUsingStty(); } } - - private static function hasVt100Support(): bool + private static function hasVt100Support() : bool { return function_exists('sapi_windows_vt100_support') && sapi_windows_vt100_support(fopen('php://stdout', 'wb')); } - - private static function initDimensionsUsingStty(): void + private static function initDimensionsUsingStty() : void { if ($sttyString = self::getSttyColumns()) { if (preg_match('/rows.(\\d+);.columns.(\\d+);/i', $sttyString, $matches)) { @@ -110,29 +87,25 @@ private static function initDimensionsUsingStty(): void } } } - - private static function getConsoleMode(): ?array + private static function getConsoleMode() : ?array { $info = self::readFromProcess('mode CON'); if (null === $info || !preg_match('/--------+\\r?\\n.+?(\\d+)\\r?\\n.+?(\\d+)\\r?\\n/', $info, $matches)) { return null; } - return [(int) $matches[2], (int) $matches[1]]; } - - private static function getSttyColumns(): ?string + private static function getSttyColumns() : ?string { return self::readFromProcess('stty -a | grep columns'); } - - private static function readFromProcess(string $command): ?string + private static function readFromProcess(string $command) : ?string { if (!function_exists('proc_open')) { return null; } $descriptorspec = [1 => ['pipe', 'w'], 2 => ['pipe', 'w']]; - $process = proc_open($command, $descriptorspec, $pipes, null, null, ['suppress_errors' => true]); + $process = proc_open($command, $descriptorspec, $pipes, null, null, ['suppress_errors' => \true]); if (!is_resource($process)) { return null; } @@ -140,7 +113,6 @@ private static function readFromProcess(string $command): ?string fclose($pipes[1]); fclose($pipes[2]); proc_close($process); - return $info; } }