refactor: PHP 8 features

This commit is contained in:
Nuno Maduro
2021-10-24 18:29:59 +01:00
parent e8c2fe6e35
commit 2b687a7269
43 changed files with 283 additions and 635 deletions

View File

@ -29,31 +29,30 @@ final class Coverage implements AddsOutput, HandlesArguments
/**
* Whether should show the coverage or not.
*
* @var bool
*/
public $coverage = false;
public bool $coverage = false;
/**
* The minimum coverage.
*
* @var float
*/
public $coverageMin = 0.0;
public float $coverageMin = 0.0;
/**
* @var OutputInterface
* Creates a new Plugin instance.
*/
private $output;
public function __construct(OutputInterface $output)
public function __construct(private OutputInterface $output)
{
$this->output = $output;
// ..
}
/**
* @param array<int, string> $originals
*
* @return array<int, string>
*/
public function handleArguments(array $originals): array
{
$arguments = array_merge([''], array_values(array_filter($originals, function ($original): bool {
$arguments = [...[''], ...array_values(array_filter($originals, function ($original): bool {
foreach ([self::COVERAGE_OPTION, self::MIN_OPTION] as $option) {
if ($original === sprintf('--%s', $option) || Str::startsWith($original, sprintf('--%s=', $option))) {
return true;
@ -61,7 +60,7 @@ final class Coverage implements AddsOutput, HandlesArguments
}
return false;
})));
}))];
$originals = array_flip($originals);
foreach ($arguments as $argument) {
@ -75,9 +74,9 @@ final class Coverage implements AddsOutput, HandlesArguments
$input = new ArgvInput($arguments, new InputDefinition($inputs));
if ((bool) $input->getOption(self::COVERAGE_OPTION)) {
$this->coverage = true;
$originals[] = '--coverage-php';
$originals[] = \Pest\Support\Coverage::getPath();
$this->coverage = true;
$originals[] = '--coverage-php';
$originals[] = \Pest\Support\Coverage::getPath();
}
if ($input->getOption(self::MIN_OPTION) !== null) {

View File

@ -21,17 +21,10 @@ final class Environment implements HandlesArguments
*/
public const LOCAL = 'local';
/**
* @var \Pest\Plugins\Environment|null
*/
private static $instance;
/**
* The current environment.
*
* @var string|null
*/
private static $name;
private static ?string $name = null;
/**
* Allows to handle custom command line arguments.

View File

@ -28,23 +28,14 @@ final class Init implements HandlesArguments
'ExampleTest.php' => 'tests/ExampleTest.php',
];
/**
* @var OutputInterface
*/
private $output;
/**
* @var TestSuite
*/
private $testSuite;
/**
* Creates a new Plugin instance.
*/
public function __construct(TestSuite $testSuite, OutputInterface $output)
{
$this->testSuite = $testSuite;
$this->output = $output;
public function __construct(
private TestSuite $testSuite,
private OutputInterface $output
) {
// ..
}
public function handleArguments(array $arguments): array

View File

@ -13,17 +13,13 @@ use Symfony\Component\Console\Output\OutputInterface;
*/
final class Version implements HandlesArguments
{
/**
* @var OutputInterface
*/
private $output;
/**
* Creates a new instance of the plugin.
*/
public function __construct(OutputInterface $output)
{
$this->output = $output;
public function __construct(
private OutputInterface $output
) {
// ..
}
public function handleArguments(array $arguments): array