Skip to content

Commit

Permalink
Polish
Browse files Browse the repository at this point in the history
  • Loading branch information
Théo FIDRY committed Oct 7, 2017
1 parent 79eff9f commit f62e813
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 23 deletions.
10 changes: 7 additions & 3 deletions bin/php-scoper
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ $isVeryVerbose = array_reduce(
false
);

//if ('phar:' === substr(__FILE__, 0, 5)) {
check_requirements($autoload, $isVeryVerbose);
//}
if ('phar:' === substr(__FILE__, 0, 5)) {
$checkPassed = check_requirements($autoload, $isVeryVerbose);

if (false === $checkPassed) {
exit(1);
}
}

$app = create_application();

Expand Down
12 changes: 2 additions & 10 deletions src/Autoload/Requirements.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,12 @@ private function addPhpVersionRequirement(array $composerConfig)
$this->addRequirement(
Semver::satisfies(phpversion(), $requiredPhpVersion),
sprintf(
'PHP version must satisfies <comment>%s</comment> (<comment>%s</comment> installed)',
'PHP version must satisfies "%s" ("%s" installed)',
$requiredPhpVersion,
$installedPhpVersion
),
'',
''
);

$this->addRequirement(
version_compare($installedPhpVersion, '5.3.16', '!='),
'PHP version must not be 5.3.16 as Symfony won\'t work properly with it',
'Install PHP 5.3.17 or newer (or downgrade to an earlier PHP version)'
);
}

private function addExtensionRequirements(array $composerConfig)
Expand All @@ -95,10 +88,9 @@ private function addExtensionRequirement($extension)
$this->addRequirement(
extension_loaded($extension),
sprintf(
'The extension <comment>%s</comment> must be enabled.',
'The extension "%s" must be enabled.',
$extension
),
'',
''
);
}
Expand Down
49 changes: 39 additions & 10 deletions src/check.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,37 @@ function check_requirements($autoload, $verbose)
$requirements = new Requirements(dirname(dirname(realpath($autoload))));
$iniPath = $requirements->getPhpIniPath();

$checkPassed = array_reduce(
$requirements->getRequirements(),
/**
* @param bool $checkPassed
* @param Requirement $requirement
*
* @return bool
*/
function ($checkPassed, Requirement $requirement) use ($lineSize) {
return $checkPassed || null ===get_error_message($requirement, $lineSize);
},
false
);

if (false === $checkPassed) {
// Override the default verbosity to output errors regardless of the verbosity asked by the user
$verbose = true;
}

echo_title('PHP-Scoper Requirements Checker', null, $verbose);

echo '> PHP is using the following php.ini file:' . PHP_EOL;
vecho('> PHP is using the following php.ini file:' . PHP_EOL, $verbose);

if ($iniPath) {
echo_style('green', ' ' . $iniPath, $verbose);
} else {
echo_style('yellow', ' WARNING: No configuration file (php.ini) used by PHP!', $verbose);
}

echo PHP_EOL . PHP_EOL;

echo '> Checking PHP-Scoper requirements:' . PHP_EOL . ' ';
vecho(PHP_EOL . PHP_EOL, $verbose);
vecho('> Checking PHP-Scoper requirements:' . PHP_EOL . ' ', $verbose);

$messages = [];

Expand All @@ -53,8 +72,6 @@ function check_requirements($autoload, $verbose)
}
}

$checkPassed = empty($messages['error']);

foreach ($requirements->getRecommendations() as $requirement) {
if ($helpText = get_error_message($requirement, $lineSize)) {
echo_style('yellow', 'W', $verbose);
Expand All @@ -67,26 +84,35 @@ function check_requirements($autoload, $verbose)
if ($checkPassed) {
echo_block('success', 'OK', 'Your system is ready to run PHP-Scoper.', $verbose);
} else {
echo_block('error', 'ERROR', 'Your system is not ready to run Symfony projects', $verbose);
echo_block('error', 'ERROR', 'Your system is not ready to run PHP-Scoper', $verbose);

echo_title('Fix the following mandatory requirements', 'red', $verbose);

foreach ($messages['error'] as $helpText) {
echo ' * ' . $helpText . PHP_EOL;
vecho(' * ' . $helpText . PHP_EOL, $verbose);
}
}

if (!empty($messages['warning'])) {
echo_title('Optional recommendations to improve your setup', 'yellow', $verbose);

foreach ($messages['warning'] as $helpText) {
echo ' * ' . $helpText . PHP_EOL;
vecho(' * ' . $helpText . PHP_EOL, $verbose);
}
}

return $checkPassed;
}

function vecho($message, $verbose)
{
if (false === $verbose) {
return;
}

echo $message;
}

/**
* @param Requirement $requirement
* @param int $lineSize
Expand All @@ -99,7 +125,10 @@ function get_error_message(Requirement $requirement, $lineSize)
}

$errorMessage = wordwrap($requirement->getTestMessage(), $lineSize - 3, PHP_EOL.' ').PHP_EOL;
$errorMessage .= ' > '.wordwrap($requirement->getHelpText(), $lineSize - 5, PHP_EOL.' > ').PHP_EOL;

if ('' !== $requirement->getHelpText()) {
$errorMessage .= ' > '.wordwrap($requirement->getHelpText(), $lineSize - 5, PHP_EOL.' > ').PHP_EOL;
}

return $errorMessage;
}
Expand Down

0 comments on commit f62e813

Please sign in to comment.