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

Apply PHP 7.4 syntax and typed property #101

Merged
merged 1 commit into from
Aug 3, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/AbstractContainerCommandLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
*/
abstract class AbstractContainerCommandLoader implements CommandLoaderInterface
{
/** @var ContainerInterface */
private $container;
private ContainerInterface $container;

/** @psalm-var array<string, string> */
private $commandMap;
Expand Down
2 changes: 1 addition & 1 deletion src/Command/AbstractParamAwareCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
abstract class AbstractParamAwareCommand extends Command
{
/** @var array<string, InputParamInterface> */
private $inputParams = [];
private array $inputParams = [];

/**
* @return $this
Expand Down
7 changes: 2 additions & 5 deletions src/ContainerResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@
*/
final class ContainerResolver
{
/**
* @var string
* @psalm-var non-empty-string
*/
private $projectRoot;
/** @psalm-var non-empty-string */
private string $projectRoot;

/**
* @psalm-param non-empty-string $projectRoot
Expand Down
10 changes: 3 additions & 7 deletions src/Input/AbstractInputParam.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,14 @@ abstract class AbstractInputParam implements InputParamInterface
/** @var mixed */
private $default;

/** @var string */
private $description = '';
private string $description = '';

/**
* Parameter name; must be set by class composing trait!
*
* @var string
*/
private $name;
private string $name;

/** @var bool */
private $required = false;
private bool $required = false;

/** @var null|string|string[] */
private $shortcut;
Expand Down
2 changes: 1 addition & 1 deletion src/Input/AbstractParamAwareInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ abstract class AbstractParamAwareInput implements ParamAwareInputInterface
protected $output;

/** @var array<string, InputParamInterface> */
private $params;
private array $params;

/**
* @param array<string, InputParamInterface> $params
Expand Down
7 changes: 2 additions & 5 deletions src/Input/ChoiceParam.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ final class ChoiceParam extends AbstractInputParam
{
use AllowMultipleTrait;

/** @var array */
private $haystack;
private array $haystack;

/**
* @param array $haystack Choices to choose from.
Expand Down Expand Up @@ -63,9 +62,7 @@ private function createDefaultPrompt($defaultValue): string

if (is_array($defaultValue)) {
$defaultValue = implode(', ', array_map(
static function ($value): string {
return (string) $value;
},
static fn($value): string => (string) $value,
$defaultValue
));
}
Expand Down
6 changes: 2 additions & 4 deletions src/Input/IntParam.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ final class IntParam extends AbstractInputParam
use AllowMultipleTrait;
use StandardQuestionTrait;

/** @var null|int */
private $max;
private ?int $max = null;

/** @var null|int */
private $min;
private ?int $min = null;

public function getQuestion(): Question
{
Expand Down
12 changes: 3 additions & 9 deletions src/Input/PathParam.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,13 @@ final class PathParam extends AbstractInputParam

/**
* Whether or not the path provided must exist.
*
* @var bool
*/
private $mustExist = false;
private bool $mustExist = false;

/**
* One of the TYPE_* constants
*
* @var string
*/
private $type;
private string $type;

/**
* @param string $pathType One of the TYPE_* constants, indicating whether
Expand All @@ -62,9 +58,7 @@ public function getQuestion(): Question

$foundFilesAndDirs = is_dir($inputPath) ? scandir($inputPath) : [];

return array_map(static function (string $dirOrFile) use ($inputPath): string {
return $inputPath . $dirOrFile;
}, $foundFilesAndDirs);
return array_map(static fn(string $dirOrFile): string => $inputPath . $dirOrFile, $foundFilesAndDirs);
});

$mustExist = $this->mustExist;
Expand Down
3 changes: 1 addition & 2 deletions src/Input/StringParam.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ final class StringParam extends AbstractInputParam
use AllowMultipleTrait;
use StandardQuestionTrait;

/** @var null|string */
private $pattern;
private ?string $pattern = null;

public function getQuestion(): Question
{
Expand Down
3 changes: 1 addition & 2 deletions src/Listener/TerminateListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ final class TerminateListener

private const HOME_PATH_REGEX = '#^(~|\$HOME)#';

/** @var array */
private $config;
private array $config;

public function __construct(array $config)
{
Expand Down
4 changes: 2 additions & 2 deletions test/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ public function testListIncludesCommandWithDependencies(): void

$container
->method('get')
->will($this->returnCallback(function (string $service) use ($config, $container) {
->will($this->returnCallback(static function (string $service) use ($config, $container) {
switch ($service) {
case 'config':
return $config;
Expand Down Expand Up @@ -602,7 +602,7 @@ public function testHelpDisplaysInformationForCommandWithDependencies(): void

$container
->method('get')
->will($this->returnCallback(function (string $service) use ($config, $container) {
->will($this->returnCallback(static function (string $service) use ($config, $container) {
switch ($service) {
case 'config':
return $config;
Expand Down
3 changes: 1 addition & 2 deletions test/Input/AbstractInputParamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@

class AbstractInputParamTest extends TestCase
{
/** @var AbstractInputParam */
private $param;
private AbstractInputParam $param;

public function setUp(): void
{
Expand Down
3 changes: 1 addition & 2 deletions test/Input/BoolParamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@

class BoolParamTest extends TestCase
{
/** @var BoolParam */
private $param;
private BoolParam $param;

public function setUp(): void
{
Expand Down
5 changes: 2 additions & 3 deletions test/Input/ChoiceParamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
class ChoiceParamTest extends TestCase
{
/** @var string[] */
private $choices;
private array $choices;

/** @var ChoiceParam */
private $param;
private ChoiceParam $param;

public function setUp(): void
{
Expand Down
3 changes: 1 addition & 2 deletions test/Input/IntParamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@

class IntParamTest extends TestCase
{
/** @var IntParam */
private $param;
private IntParam $param;

public function setUp(): void
{
Expand Down
15 changes: 5 additions & 10 deletions test/Input/ParamAwareInputTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,8 @@

class ParamAwareInputTest extends TestCase
{
/**
* @var string
* @psalm-var class-string<ParamAwareInputInterface>
*/
private $class;
/** @psalm-var class-string<ParamAwareInputInterface> */
private string $class;

/**
* @var InputInterface|MockObject
Expand All @@ -60,7 +57,7 @@ class ParamAwareInputTest extends TestCase
private $output;

/** @var InputParamInterface[] */
private $params;
private array $params;

public function setUp(): void
{
Expand Down Expand Up @@ -610,10 +607,8 @@ public function testGetParamAllowsEmptyValuesForParamsWithValidationIfParamIsNot
$this->output
->expects($this->any())
->method('write')
->with($this->callback(function (string $message): bool {
return preg_match('/^\s*$/', $message)
|| false !== strpos($message, '<question>');
}));
->with($this->callback(static fn(string $message): bool => preg_match('/^\s*$/', $message)
|| false !== strpos($message, '<question>')));

$helper = new QuestionHelper();
$input = new $this->class(
Expand Down
8 changes: 3 additions & 5 deletions test/Input/PathParamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@

class PathParamTest extends TestCase
{
/** @var PathParam */
private $param;
private PathParam $param;

public function setUp(): void
{
Expand Down Expand Up @@ -140,9 +139,8 @@ public function testAutocompleterReturnsFilesAndDirectoriesBasedOnProvidedInput(
$this->assertIsArray($paths);
$this->assertGreaterThan(0, count($paths));

$actual = array_reduce($paths, function (bool $isValid, string $path) {
return $isValid && 0 === strpos($path, realpath(dirname(__DIR__)));
}, true);
$actual = array_reduce($paths, static fn(bool $isValid, string $path) =>
$isValid && 0 === strpos($path, (string) realpath(dirname(__DIR__))), true);

$this->assertTrue($actual, 'One or more autocompletion paths were invalid');
}
Expand Down
3 changes: 1 addition & 2 deletions test/Input/StringParamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@

class StringParamTest extends TestCase
{
/** @var StringParam */
private $param;
private StringParam $param;

public function setUp(): void
{
Expand Down
7 changes: 3 additions & 4 deletions test/Listener/TerminateListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,8 @@ public function testNotifiesOfThirdPartyCommandInChain(): void
->method('writeln')
->with($this->stringContains('Break'));

$expectedChoiceQuestion = function (Question $question): bool {
return (bool) preg_match('#<error>.*?This is a third-party command</error>#i', $question->getQuestion());
};
$expectedChoiceQuestion = static fn(Question $question): bool =>
(bool) preg_match('#<error>.*?This is a third-party command</error>#i', $question->getQuestion());

$questionHelper = $this->createMock(QuestionHelper::class);
$questionHelper
Expand Down Expand Up @@ -210,7 +209,7 @@ public function testDoesNotNotifyForLocalCommandInChain(): void
->method('isInteractive')
->willReturn(true);

$expectedChoiceQuestion = function (Question $question): bool {
$expectedChoiceQuestion = static function (Question $question): bool {
$query = $question->getQuestion();
return ! preg_match('#<error>.*?This is a third-party command</error>#i', $query)
&& (bool) preg_match('#<info>Executing local:command</info>#i', $query);
Expand Down
3 changes: 1 addition & 2 deletions test/TestAsset/ExampleCommandWithDependencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ class ExampleCommandWithDependencies extends Command
/** @var string|null */
protected static $defaultName = 'example:command-with-deps';

/** @var ExampleDependency */
// phpcs:ignore SlevomatCodingStandard.Classes.UnusedPrivateElements
private $dependency;
private ExampleDependency $dependency;

public function __construct(ExampleDependency $dependency)
{
Expand Down