Skip to content

Commit

Permalink
Requirement checker optimisations
Browse files Browse the repository at this point in the history
- Add compactors to compress the PHP and JSON code
- Fix the licenses (Closes #192)
- Bump the requirement checker on the library to ship #185
  • Loading branch information
theofidry committed May 3, 2018
1 parent dda8ca6 commit 6df63bf
Show file tree
Hide file tree
Showing 28 changed files with 425 additions and 2,348 deletions.
17 changes: 6 additions & 11 deletions .requirement-checker/bin/check-requirements.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
<?php

/*
* This file is part of the box project.
*
* (c) Kevin Herrera <kevin@herrera.io>
* Théo Fidry <theo.fidry@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace _HumbugBox5addf3ce683e7\KevinGH\RequirementChecker;
namespace _HumbugBox5aeb92ac2e46b\KevinGH\RequirementChecker;

require __DIR__ . '/../vendor/autoload.php';
$checkPassed = \_HumbugBox5addf3ce683e7\KevinGH\RequirementChecker\Checker::checkRequirements();
if (\PHP_SAPI !== 'cli' && \PHP_SAPI !== 'phpdbg') {
echo \PHP_EOL . 'The application may only be invoked from a command line' . \PHP_EOL;
exit(1);
}
$checkPassed = \_HumbugBox5aeb92ac2e46b\KevinGH\RequirementChecker\Checker::checkRequirements();
if (\false === $checkPassed) {
exit(1);
}
40 changes: 1 addition & 39 deletions .requirement-checker/composer.json
Original file line number Diff line number Diff line change
@@ -1,39 +1 @@
{
"name": "humbug\/requirement-checker",
"description": "A tool to check the PHARs dependency requirements.",
"keywords": [
"phar"
],
"license": "MIT",
"authors": [
{
"name": "Th\u00e9o Fidry",
"email": "theo.fidry@gmail.com"
}
],
"bin": [
"bin\/check-requirements.php"
],
"autoload": {
"psr-4": {
"_HumbugBox5addf3ce683e7\\KevinGH\\RequirementChecker\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"_HumbugBox5addf3ce683e7\\KevinGH\\RequirementChecker\\": "tests"
}
},
"require": {
"php": "^5.3 || ^7.0",
"ext-phar": "*",
"composer\/semver": "^1.4"
},
"require-dev": {
"phpunit\/phpunit": "^7.0"
},
"config": {
"bin-dir": "bin",
"sort-packages": true
}
}
{"name":"humbug\/requirement-checker","description":"A tool to check the PHARs dependency requirements.","keywords":["phar"],"license":"MIT","authors":[{"name":"Th\u00e9o Fidry","email":"theo.fidry@gmail.com"}],"bin":["bin\/check-requirements.php"],"autoload":{"psr-4":{"_HumbugBox5aeb92ac2e46b\\KevinGH\\RequirementChecker\\":"src"}},"autoload-dev":{"psr-4":{"_HumbugBox5aeb92ac2e46b\\KevinGH\\RequirementChecker\\":"tests"}},"require":{"php":"^5.3 || ^7.0","ext-phar":"*","composer\/semver":"^1.4"},"require-dev":{"phpunit\/phpunit":"^7.0"},"config":{"bin-dir":"bin","sort-packages":true}}
60 changes: 26 additions & 34 deletions .requirement-checker/src/Checker.php
Original file line number Diff line number Diff line change
@@ -1,43 +1,35 @@
<?php

/*
* This file is part of the box project.
*
* (c) Kevin Herrera <kevin@herrera.io>
* Théo Fidry <theo.fidry@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace _HumbugBox5addf3ce683e7\KevinGH\RequirementChecker;
namespace _HumbugBox5aeb92ac2e46b\KevinGH\RequirementChecker;

/**
* The code in this file must be PHP 5.3+ compatible as is used to know if the application can be run.
*
* @private
*/
@private
@see
@package
@license
*/
final class Checker
{
/** @var null|string */
/**
@var */
private static $requirementsConfig;
/**
* @return bool
*/
@return
*/
public static function checkRequirements()
{
$requirements = self::retrieveRequirements();
$checkPassed = $requirements->evaluateRequirements();
$io = new \_HumbugBox5addf3ce683e7\KevinGH\RequirementChecker\IO();
self::printCheck($checkPassed, new \_HumbugBox5addf3ce683e7\KevinGH\RequirementChecker\Printer($io->getVerbosity(), $io->hasColorSupport()), $requirements);
$io = new \_HumbugBox5aeb92ac2e46b\KevinGH\RequirementChecker\IO();
self::printCheck($checkPassed, new \_HumbugBox5aeb92ac2e46b\KevinGH\RequirementChecker\Printer($io->getVerbosity(), $io->hasColorSupport()), $requirements);
return $checkPassed;
}
public static function printCheck($checkPassed, \_HumbugBox5addf3ce683e7\KevinGH\RequirementChecker\Printer $printer, \_HumbugBox5addf3ce683e7\KevinGH\RequirementChecker\RequirementCollection $requirements)
public static function printCheck($checkPassed, \_HumbugBox5aeb92ac2e46b\KevinGH\RequirementChecker\Printer $printer, \_HumbugBox5aeb92ac2e46b\KevinGH\RequirementChecker\RequirementCollection $requirements)
{
if (\false === $checkPassed && \_HumbugBox5addf3ce683e7\KevinGH\RequirementChecker\IO::VERBOSITY_VERY_VERBOSE > $printer->getVerbosity()) {
// Override the default verbosity to output errors regardless of the verbosity asked by the user
$printer->setVerbosity(\_HumbugBox5addf3ce683e7\KevinGH\RequirementChecker\IO::VERBOSITY_VERY_VERBOSE);
if (\false === $checkPassed && \_HumbugBox5aeb92ac2e46b\KevinGH\RequirementChecker\IO::VERBOSITY_VERY_VERBOSE > $printer->getVerbosity()) {
$printer->setVerbosity(\_HumbugBox5aeb92ac2e46b\KevinGH\RequirementChecker\IO::VERBOSITY_VERY_VERBOSE);
}
$verbosity = \_HumbugBox5addf3ce683e7\KevinGH\RequirementChecker\IO::VERBOSITY_VERY_VERBOSE;
$verbosity = \_HumbugBox5aeb92ac2e46b\KevinGH\RequirementChecker\IO::VERBOSITY_VERY_VERBOSE;
$iniPath = $requirements->getPhpIniPath();
$printer->title('Box Requirements Checker', $verbosity);
$printer->printv('> Using PHP ', $verbosity);
Expand All @@ -58,24 +50,24 @@ public static function printCheck($checkPassed, \_HumbugBox5addf3ce683e7\KevinGH
$errorMessages = array();
foreach ($requirements->getRequirements() as $requirement) {
if ($errorMessage = $printer->getRequirementErrorMessage($requirement)) {
if (\_HumbugBox5addf3ce683e7\KevinGH\RequirementChecker\IO::VERBOSITY_DEBUG === $printer->getVerbosity()) {
$printer->printvln('' . $requirement->getTestMessage(), \_HumbugBox5addf3ce683e7\KevinGH\RequirementChecker\IO::VERBOSITY_DEBUG, 'red');
$printer->printv(' ', \_HumbugBox5addf3ce683e7\KevinGH\RequirementChecker\IO::VERBOSITY_DEBUG);
if (\_HumbugBox5aeb92ac2e46b\KevinGH\RequirementChecker\IO::VERBOSITY_DEBUG === $printer->getVerbosity()) {
$printer->printvln('' . $requirement->getTestMessage(), \_HumbugBox5aeb92ac2e46b\KevinGH\RequirementChecker\IO::VERBOSITY_DEBUG, 'red');
$printer->printv(' ', \_HumbugBox5aeb92ac2e46b\KevinGH\RequirementChecker\IO::VERBOSITY_DEBUG);
$errorMessages[] = $errorMessage;
} else {
$printer->printv('E', $verbosity, 'red');
$errorMessages[] = $errorMessage;
}
continue;
}
if (\_HumbugBox5addf3ce683e7\KevinGH\RequirementChecker\IO::VERBOSITY_DEBUG === $printer->getVerbosity()) {
$printer->printvln('' . $requirement->getHelpText(), \_HumbugBox5addf3ce683e7\KevinGH\RequirementChecker\IO::VERBOSITY_DEBUG, 'green');
$printer->printv(' ', \_HumbugBox5addf3ce683e7\KevinGH\RequirementChecker\IO::VERBOSITY_DEBUG);
if (\_HumbugBox5aeb92ac2e46b\KevinGH\RequirementChecker\IO::VERBOSITY_DEBUG === $printer->getVerbosity()) {
$printer->printvln('' . $requirement->getHelpText(), \_HumbugBox5aeb92ac2e46b\KevinGH\RequirementChecker\IO::VERBOSITY_DEBUG, 'green');
$printer->printv(' ', \_HumbugBox5aeb92ac2e46b\KevinGH\RequirementChecker\IO::VERBOSITY_DEBUG);
} else {
$printer->printv('.', $verbosity, 'green');
}
}
if (\_HumbugBox5addf3ce683e7\KevinGH\RequirementChecker\IO::VERBOSITY_DEBUG !== $printer->getVerbosity() && \count($requirements) > 0) {
if (\_HumbugBox5aeb92ac2e46b\KevinGH\RequirementChecker\IO::VERBOSITY_DEBUG !== $printer->getVerbosity() && \count($requirements) > 0) {
$printer->printvln('', $verbosity);
}
if ($requirements->evaluateRequirements()) {
Expand All @@ -90,15 +82,15 @@ public static function printCheck($checkPassed, \_HumbugBox5addf3ce683e7\KevinGH
$printer->printvln('', $verbosity);
}
/**
* @return RequirementCollection
*/
@return
*/
private static function retrieveRequirements()
{
if (null === self::$requirementsConfig) {
self::$requirementsConfig = __DIR__ . '/../.requirements.php';
}
$config = (require self::$requirementsConfig);
$requirements = new \_HumbugBox5addf3ce683e7\KevinGH\RequirementChecker\RequirementCollection();
$requirements = new \_HumbugBox5aeb92ac2e46b\KevinGH\RequirementChecker\RequirementCollection();
foreach ($config as $constraint) {
\call_user_func_array(array($requirements, 'addRequirement'), $constraint);
}
Expand Down
67 changes: 23 additions & 44 deletions .requirement-checker/src/IO.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
<?php

/*
* This file is part of the box project.
*
* (c) Kevin Herrera <kevin@herrera.io>
* Théo Fidry <theo.fidry@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace _HumbugBox5addf3ce683e7\KevinGH\RequirementChecker;
namespace _HumbugBox5aeb92ac2e46b\KevinGH\RequirementChecker;

/**
* The code in this file must be PHP 5.3+ compatible as is used to know if the application can be run.
*
* @private
*/
@private
*/
final class IO
{
const VERBOSITY_QUIET = 16;
Expand All @@ -35,32 +24,31 @@ public function __construct()
$this->colorSupport = $this->checkColorSupport();
}
/**
* @return bool
*/
@return
*/
public function isInteractive()
{
return $this->interactive;
}
/**
* @return int
*/
@return
*/
public function getVerbosity()
{
return $this->verbosity;
}
/**
* @return bool
*/
@return
*/
public function hasColorSupport()
{
return $this->colorSupport;
}
/**
* @param mixed
* @param mixed $values
*
* @return bool
*/
@param
@param
@return
*/
public function hasParameter($values)
{
$values = (array) $values;
Expand All @@ -73,10 +61,9 @@ public function hasParameter($values)
return \false;
}
/**
* @param int $shellVerbosity
*
* @return bool
*/
@param
@return
*/
private function checkInteractivity($shellVerbosity)
{
if (-1 === $shellVerbosity) {
Expand All @@ -93,8 +80,8 @@ private function checkInteractivity($shellVerbosity)
return \true;
}
/**
* @return int
*/
@return
*/
private function configureVerbosity()
{
switch ($shellVerbosity = (int) \getenv('SHELL_VERBOSITY')) {
Expand Down Expand Up @@ -132,17 +119,10 @@ private function configureVerbosity()
return $shellVerbosity;
}
/**
* Returns true if the stream supports colorization.
*
* Colorization is disabled if not supported by the stream:
*
* - Windows != 10.0.10586 without Ansicon, ConEmu or Mintty
* - non tty consoles
*
* @return bool true if the stream supports colorization, false otherwise
*
* @see \Symfony\Component\Console\Output\StreamOutput
*/
@return
@see
@license
*/
private function checkColorSupport()
{
if ($this->hasParameter(array('--ansi'))) {
Expand All @@ -155,13 +135,12 @@ private function checkColorSupport()
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);
return stream_isatty(\STDOUT);
}
if (\function_exists('posix_isatty')) {
return \posix_isatty(\STDOUT);
}
$stat = \fstat(\STDOUT);
// Check if formatted mode is S_IFCHR
return $stat ? 020000 === ($stat['mode'] & 0170000) : \false;
}
}
Loading

0 comments on commit 6df63bf

Please sign in to comment.