Skip to content

Commit

Permalink
refactor: Move PHP settings checker into a class (#1188)
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry authored Nov 22, 2023
1 parent 65cd2df commit b17f5ee
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/Console/Command/Compile.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use KevinGH\Box\Console\Logger\CompilerLogger;
use KevinGH\Box\Console\MessageRenderer;
use KevinGH\Box\Console\OpenFileDescriptorLimiter;
use KevinGH\Box\Console\PhpSettingsChecker;
use KevinGH\Box\Constants;
use KevinGH\Box\MapFile;
use KevinGH\Box\Phar\CompressionAlgorithm;
Expand All @@ -63,7 +64,6 @@
use function implode;
use function is_callable;
use function is_string;
use function KevinGH\Box\check_php_settings;
use function KevinGH\Box\disable_parallel_processing;
use function KevinGH\Box\format_size;
use function KevinGH\Box\format_time;
Expand Down Expand Up @@ -190,7 +190,7 @@ public function execute(IO $io): int
$io->setVerbosity(OutputInterface::VERBOSITY_DEBUG);
}

check_php_settings($io);
PhpSettingsChecker::check($io);

if ($io->getTypedOption(self::NO_PARALLEL_PROCESSING_OPTION)->asBoolean()) {
disable_parallel_processing();
Expand Down
4 changes: 2 additions & 2 deletions src/Console/Command/Extract.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Fidry\Console\ExitCode;
use Fidry\Console\IO;
use Fidry\FileSystem\FS;
use KevinGH\Box\Console\PhpSettingsChecker;
use KevinGH\Box\Phar\InvalidPhar;
use KevinGH\Box\Phar\PharFactory;
use KevinGH\Box\Phar\PharMeta;
Expand All @@ -28,7 +29,6 @@
use Throwable;
use function bin2hex;
use function file_exists;
use function KevinGH\Box\check_php_settings;
use function realpath;
use function sprintf;
use const DIRECTORY_SEPARATOR;
Expand Down Expand Up @@ -76,7 +76,7 @@ public function getConfiguration(): Configuration

public function execute(IO $io): int
{
check_php_settings($io);
PhpSettingsChecker::check($io);

$pharPath = self::getPharFilePath($io);
$outputDir = $io->getTypedArgument(self::OUTPUT_ARG)->asNonEmptyString();
Expand Down
4 changes: 2 additions & 2 deletions src/Console/Command/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use KevinGH\Box\Compactor\PhpScoper;
use KevinGH\Box\Compactor\Placeholder;
use KevinGH\Box\Configuration\Configuration;
use KevinGH\Box\Console\PhpSettingsChecker;
use stdClass;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
Expand All @@ -38,7 +39,6 @@
use function explode;
use function getcwd;
use function implode;
use function KevinGH\Box\check_php_settings;
use function putenv;
use function sprintf;
use const KevinGH\Box\BOX_ALLOW_XDEBUG;
Expand Down Expand Up @@ -89,7 +89,7 @@ public function execute(IO $io): int
putenv(BOX_ALLOW_XDEBUG.'=1');
}

check_php_settings($io);
PhpSettingsChecker::check($io);

ChangeWorkingDirOption::changeWorkingDirectory($io);

Expand Down
37 changes: 37 additions & 0 deletions src/Console/PhpSettingsChecker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

/*
* This file is part of the box project.
*
* (c) Kevin Herrera <[email protected]>
* Théo Fidry <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace KevinGH\Box\Console;

use Fidry\Console\IO;
use KevinGH\Box\Console\Php\PhpSettingsHandler;
use KevinGH\Box\NotInstantiable;
use Symfony\Component\Console\Logger\ConsoleLogger;

/**
* @internal
*/
final class PhpSettingsChecker
{
use NotInstantiable;

public static function check(IO $io): void
{
(new PhpSettingsHandler(
new ConsoleLogger(
$io->getOutput(),
),
))->check();
}
}
15 changes: 0 additions & 15 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@

use Composer\InstalledVersions;
use ErrorException;
use Fidry\Console\IO;
use KevinGH\Box\Console\Php\PhpSettingsHandler;
use Phar;
use Symfony\Component\Console\Helper\Helper;
use Symfony\Component\Console\Logger\ConsoleLogger;
use Webmozart\Assert\Assert;
use function bin2hex;
use function class_alias;
Expand Down Expand Up @@ -199,18 +196,6 @@ function unique_id(string $prefix): string
return $prefix.bin2hex(random_bytes(6));
}

/**
* @private
*/
function check_php_settings(IO $io): void
{
(new PhpSettingsHandler(
new ConsoleLogger(
$io->getOutput(),
),
))->check();
}

/**
* Converts errors to exceptions.
*
Expand Down

0 comments on commit b17f5ee

Please sign in to comment.