Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Move PHP settings checker into a class #1188

Merged
merged 4 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 execute(IO $io): int
{
check_php_settings($io);
PhpSettingsChecker::check($io);

Check warning on line 79 in src/Console/Command/Extract.php

View workflow job for this annotation

GitHub Actions / Infection (PHP 8.2)

Escaped Mutant for Mutator "MethodCallRemoval": --- Original +++ New @@ @@ } public function execute(IO $io) : int { - PhpSettingsChecker::check($io); + $pharPath = self::getPharFilePath($io); $outputDir = $io->getTypedArgument(self::OUTPUT_ARG)->asNonEmptyString(); $internal = $io->getTypedOption(self::INTERNAL_OPT)->asBoolean();

$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
Loading