Skip to content

Commit fe47ede

Browse files
committed
refactor: enforce short-array syntax.
1 parent 5d74408 commit fe47ede

27 files changed

+237
-231
lines changed

Src/CommandLoader.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ class CommandLoader implements Countable {
2727
* @param array<string,class-string<Console>> $commands
2828
*/
2929
final private function __construct(
30-
private array $namespacedDirectory = array(),
31-
private array $commands = array(),
30+
private array $namespacedDirectory = [],
31+
private array $commands = [],
3232
private ?EventDispatcher $dispatcher = null
3333
) {}
3434

@@ -61,7 +61,7 @@ public static function loadCommands( array $namespacedDirectories, ContainerInte
6161
}
6262

6363
public function inDirectory( string $path, string $namespace ): static {
64-
$this->namespacedDirectory[] = array( $namespace => $path );
64+
$this->namespacedDirectory[] = [ $namespace => $path ];
6565

6666
return $this;
6767
}
@@ -128,7 +128,7 @@ protected function forCurrentFile(): void {
128128
return;
129129
}
130130

131-
$lazyload = array( $commandClass, 'start' );
131+
$lazyload = [ $commandClass, 'start' ];
132132
$commandName = $commandClass::asCommandName();
133133
$this->commands[ $commandName ] = $commandClass;
134134

Src/Console.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ final public function hasInputAttribute(): bool {
5959
*/
6060
final public static function start(
6161
?ContainerInterface $container = null,
62-
array $constructorArgs = array(),
62+
array $constructorArgs = [],
6363
bool $infer = true
6464
): static {
6565
[$command, $reflection] = static::getInstance( $container, $constructorArgs );
@@ -134,7 +134,7 @@ public function assistFrom( string $helperClass ): HelperInterface {
134134
protected static function getInstance( ?ContainerInterface $container, array $constructorArgs ): array {
135135
$reflection = new ReflectionClass( static::class );
136136
$command = $container
137-
? self::resolveSharedFromContainer( array( $container, $reflection, $constructorArgs ) )
137+
? self::resolveSharedFromContainer( [ $container, $reflection, $constructorArgs ] )
138138
: new static( ...$constructorArgs );
139139

140140
$command->setApplication( ( $app = $container?->get( Cli::class ) ) instanceof Cli ? $app : null );
@@ -143,7 +143,7 @@ protected static function getInstance( ?ContainerInterface $container, array $co
143143
// Name might already be set using constructor args. Use it if that's the case.
144144
$name = $command->getName() ?? self::commandNameFromClassname( $reflection );
145145

146-
return array( $command->setName( $name ), $reflection );
146+
return [ $command->setName( $name ), $reflection ];
147147
}
148148

149149
$attribute = $attributes[0]->newInstance();
@@ -153,7 +153,7 @@ protected static function getInstance( ?ContainerInterface $container, array $co
153153
->setAliases( $attribute->altNames )
154154
->setHidden( $attribute->isInternal );
155155

156-
return array( $command, $reflection );
156+
return [ $command, $reflection ];
157157
}
158158

159159
/**

Src/Container.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ class Container implements ContainerInterface {
3232
* > $bindings The classname as key with array value of its concrete and whether to make it singleton or not.
3333
*/
3434
public function __construct(
35-
private array $context = array(),
36-
private array $bindings = array(),
35+
private array $context = [],
36+
private array $bindings = [],
3737
) {}
3838

3939
/**
@@ -42,7 +42,7 @@ public function __construct(
4242
* @template T of object
4343
*/
4444
public function set( string $id, string|callable|null $concrete = null ): void {
45-
$this->bindings[ $id ] = array( $concrete ?? $id, false );
45+
$this->bindings[ $id ] = [ $concrete ?? $id, false ];
4646
}
4747

4848
/**
@@ -51,7 +51,7 @@ public function set( string $id, string|callable|null $concrete = null ): void {
5151
* @template T of object
5252
*/
5353
public function setShared( string $id, string|callable|null $concrete = null ): void {
54-
$this->bindings[ $id ] = array( $concrete ?? $id, true );
54+
$this->bindings[ $id ] = [ $concrete ?? $id, true ];
5555
}
5656

5757
/**
@@ -77,7 +77,7 @@ public function resolve( string $id, array $args, ?ReflectionClass $reflector =
7777
return $this->instances[ $id ]; // @phpstan-ignore-line
7878
}
7979

80-
[$concrete, $shared] = $this->bindings[ $id ] ?? array( $id, false );
80+
[$concrete, $shared] = $this->bindings[ $id ] ?? [ $id, false ];
8181

8282
if ( is_callable( $concrete ) ) {
8383
$resolved = $concrete( $this, $args );
@@ -99,7 +99,7 @@ public function resolve( string $id, array $args, ?ReflectionClass $reflector =
9999
}
100100

101101
$resolved = $reflector->newInstanceArgs(
102-
array( ...$args, ...$this->getContextual( $id, ...$constructor->getParameters() ) )
102+
[ ...$args, ...$this->getContextual( $id, ...$constructor->getParameters() ) ]
103103
);
104104

105105
$resolved instanceof $id || $this->unresolvableEntry( $id );
@@ -126,7 +126,7 @@ public function isInstance( string $id ): bool {
126126
* @return T
127127
* @template T of object
128128
*/
129-
public function get( string $id, array $args = array() ): mixed {
129+
public function get( string $id, array $args = [] ): mixed {
130130
try {
131131
return $this->resolve( $id, $args );
132132
} catch ( Exception $e ) {
@@ -158,12 +158,12 @@ public function give( string $concrete ): void {
158158
/** @return array<string,mixed> $resolved */
159159
private function getContextual( string $id, ReflectionParameter ...$params ): array {
160160
if ( ! $contextual = ( $this->context[ $id ] ?? null ) ) {
161-
return array();
161+
return [];
162162
}
163163

164-
$dependencies = array();
164+
$dependencies = [];
165165
$paramTypeHints = array_reduce( $params, $this->toParamTypeByName( ... ), $dependencies );
166-
$resolved = array();
166+
$resolved = [];
167167

168168
foreach ( $paramTypeHints as $paramName => $abstract ) {
169169
( $concrete = ( $contextual[ $abstract ] ?? null ) )
@@ -180,7 +180,7 @@ private function getContextual( string $id, ReflectionParameter ...$params ): ar
180180
private function toParamTypeByName( array $carry, ReflectionParameter $param ): array {
181181
$type = ( $t = $param->getType() ) instanceof ReflectionNamedType ? $t->getName() : '';
182182

183-
return array( ...$carry, ...array( $param->name => $type ) );
183+
return [ ...$carry, ...[ $param->name => $type ] ];
184184
}
185185

186186
private function unresolvableEntry( string $id ): never {

Src/Data/Associative.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static function from( InputOption $input ): self {
6767
isOptional: ! $input->isValueRequired(),
6868
default: $input->getDefault(),
6969
shortcut: $input->getShortcut(),
70-
suggestedValues: Parser::suggestedValuesFrom( $input ) ?? array()
70+
suggestedValues: Parser::suggestedValuesFrom( $input ) ?? []
7171
);
7272
}
7373

@@ -102,8 +102,8 @@ private function normalizeMode(): int {
102102
/** @return null|string|bool|int|float|array{} */
103103
private function normalizeDefault( mixed $value ): null|string|bool|int|float|array {
104104
return match ( true ) {
105-
default => $this->isVariadic ? array() : null,
106-
$this->isOptionalDefault( $value ) => $this->isVariadic ? array() : '',
105+
default => $this->isVariadic ? [] : null,
106+
$this->isOptionalDefault( $value ) => $this->isVariadic ? [] : '',
107107
is_callable( $value ) => $this->normalizeDefault( $value() ),
108108
$this->isVariadic => $this->getVariadicDefault( $value ),
109109
is_string( $value ) => Parser::parseBackedEnumValue( $value ),
@@ -117,6 +117,6 @@ private function isOptionalDefault( mixed $value ): bool {
117117

118118
/** @return array{} */
119119
private function getVariadicDefault( mixed $value ): array {
120-
return is_array( $value ) ? $value : ( $this->variadicFromEnum( $value ) ?? array() );
120+
return is_array( $value ) ? $value : ( $this->variadicFromEnum( $value ) ?? [] );
121121
}
122122
}

Src/Data/Flag.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ public function input(): InputOption {
7272
$this->shortcut,
7373
$this->mode,
7474
$this->desc,
75-
default: null, // Cannot have default value.
76-
suggestedValues: array() // Cannot suggest values.
75+
default: null, // Cannot have default value.
76+
suggestedValues: [] // Cannot suggest values.
7777
);
7878
}
7979

Src/Data/Positional.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static function from( InputArgument $input ): self {
2626
isVariadic: $input->isArray(),
2727
isOptional: ! $input->isRequired(),
2828
default: $input->getDefault(),
29-
suggestedValues: Parser::suggestedValuesFrom( $input ) ?? array()
29+
suggestedValues: Parser::suggestedValuesFrom( $input ) ?? []
3030
);
3131
}
3232

@@ -60,10 +60,10 @@ private function normalizeMode(): int {
6060
/** @return null|string|bool|int|float|array{} */
6161
private function normalizeDefault( mixed $value ): null|string|bool|int|float|array {
6262
return match ( true ) {
63-
default => $this->isVariadic ? array() : null,
63+
default => $this->isVariadic ? [] : null,
6464
! $this->isOptional => null,
6565
is_callable( $value ) => $this->normalizeDefault( $value() ),
66-
$this->isVariadic => is_array( $value ) ? $value : ( $this->variadicFromEnum( $value ) ?? array() ),
66+
$this->isVariadic => is_array( $value ) ? $value : ( $this->variadicFromEnum( $value ) ?? [] ),
6767
is_string( $value ) => Parser::parseBackedEnumValue( $value ),
6868
is_scalar( $value ) => $value
6969
};

Src/Event/CommandSubscriber.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ public static function disableSuggestionValidation( bool $disable = true ): void
2424
}
2525

2626
public static function getSubscribedEvents() {
27-
return array(
28-
ConsoleEvents::COMMAND => array(
29-
array( 'validateWithAutoComplete', -1 ),
30-
),
31-
);
27+
return [
28+
ConsoleEvents::COMMAND => [
29+
[ 'validateWithAutoComplete', -1 ],
30+
],
31+
];
3232
}
3333

3434
public static function suggestionToString( string|int|Suggestion $suggestion ): string|int {
@@ -54,7 +54,7 @@ public static function validateWithAutoComplete( Event $event ): void {
5454

5555
$tokens = ( $argv = $event->getInput() ) instanceof ArgvInput ? $argv->getRawTokens( true ) : null;
5656

57-
foreach ( self::getSuggestions( $event ) ?? array() as $inputName => $suggestions ) {
57+
foreach ( self::getSuggestions( $event ) ?? [] as $inputName => $suggestions ) {
5858
$suggestedValues = self::inputSuggestedValues( $suggestions, $tokens );
5959

6060
if ( ! empty( $suggestedValues ) ) {
@@ -101,15 +101,15 @@ private static function throwInvalidValue( array $suggestions, Event $event, str
101101
$attribute = self::getCommandFrom( $event )?->getInputAttribute()?->getInputBy( $inputName );
102102
$variant = $attribute ? InputVariant::fromAttribute( $attribute::class )?->value : null;
103103
$input = 'input' . ( $variant ? " {$variant}" : '' );
104-
$msg = array(
104+
$msg = [
105105
Console::COMMAND_VALUE_ERROR,
106106
Console::LONG_SEPARATOR,
107107
sprintf( 'Value does not match any of the suggested values provided for %1$s "%2$s".', $input, $inputName ),
108108
Console::LONG_SEPARATOR_LINE,
109109
'Use one of the below suggested values and try again.',
110110
Console::LONG_SEPARATOR_LINE,
111111
implode( ' | ', $suggestions ),
112-
);
112+
];
113113

114114
throw new OutOfBoundsException( implode( separator: PHP_EOL, array: $msg ) );
115115
}

Src/Helper/InputAttribute.php

+13-13
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ public function __invoke( int $mode = self::INFER_AND_UPDATE, InputVariant ...$i
8383
}
8484

8585
public function __debugInfo() {
86-
return array(
86+
return [
8787
'status' => ! $this->isValid(),
88-
'hierarchy' => $this->hierarchy ?? array(),
89-
'target' => array(
88+
'hierarchy' => $this->hierarchy ?? [],
89+
'target' => [
9090
'from' => $this->getTargetReflection()->name,
9191
'till' => $this->lastTarget ?? false,
9292
'base' => $this->getBaseClass(),
93-
),
94-
);
93+
],
94+
];
9595
}
9696

9797
/** @return bool true if attributes not parsed, false otherwise. */
@@ -111,17 +111,17 @@ public function getTargetReflection(): ReflectionClass {
111111

112112
/** @return array<class-string<Pos|Assoc|Flag>,array<string,Pos|Assoc|Flag>> */
113113
public function getCollection(): array {
114-
return $this->collection ?? array();
114+
return $this->collection ?? [];
115115
}
116116

117117
/** @return array<class-string<Console>,array<class-string<Pos|Assoc|Flag>,array<string,array<int|string>>>> */
118118
public function getSource(): array {
119-
return $this->source ?? array();
119+
return $this->source ?? [];
120120
}
121121

122122
/** @return array<string,array<string|int>|(Closure(CompletionInput): list<string|Suggestion>)> */
123123
public function getSuggestion(): array {
124-
return $this->suggestion ?? array();
124+
return $this->suggestion ?? [];
125125
}
126126

127127
/**
@@ -208,7 +208,7 @@ public function toSymfonyInput( ?InputDefinition $definition = null ): array {
208208

209209
/** @return array<Pos|Assoc|Flag> */
210210
public function toFlattenedArray(): array {
211-
return array_reduce( $this->collection, self::toSingleArray( ... ), array() );
211+
return array_reduce( $this->collection, self::toSingleArray( ... ), [] );
212212
}
213213

214214
private function inUpdateMode(): bool {
@@ -259,10 +259,10 @@ private function toCollectionStack( bool $ignoreIfExists = false ): bool {
259259

260260
/** @return array{0:bool,1:null|string|class-string<BackedEnum>|bool|int|float|array{}|(callable(): string|bool|int|float|array{})}*/
261261
private function getCurrentInputDefaultPropertyValue(): array {
262-
return array(
262+
return [
263263
'default' === $this->current['prop'],
264264
$this->suggestibleInput( $this->current['input'] )?->getUserDefault(),
265-
);
265+
];
266266
}
267267

268268
private function currentPropertyInUpdateStack(): bool {
@@ -357,7 +357,7 @@ private function walkUpdateToCollectionStack( array $props, string $name, string
357357
}
358358

359359
private function walkCollectionWithUpdatedInputProperties(): void {
360-
foreach ( $this->update ?? array() as $attributeName => $updates ) {
360+
foreach ( $this->update ?? [] as $attributeName => $updates ) {
361361
array_walk( $updates, $this->walkUpdateToCollectionStack( ... ), $attributeName );
362362
}
363363
}
@@ -397,7 +397,7 @@ private function purge(): self {
397397
* @return array<Pos|Assoc|Flag>
398398
*/
399399
private static function toSingleArray( array $carry, array $inputs ): array {
400-
return array( ...$carry, ...array_values( $inputs ) );
400+
return [ ...$carry, ...array_values( $inputs ) ];
401401
}
402402

403403
/**

Src/Traits/ConstructorAware.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ trait ConstructorAware {
1212
* @param array<TParamNames,mixed> $updates
1313
* @return ($withParamNames is true ? array<TParamNames,mixed> : mixed[])
1414
*/
15-
private function mapConstructor( array $updates = array(), bool $withParamNames = false ): array {
15+
private function mapConstructor( array $updates = [], bool $withParamNames = false ): array {
1616
$map = array_map( fn( string $name ) => $updates[ $name ] ?? $this->{$name}, $this->paramNames );
1717

1818
return $withParamNames ? array_combine( $this->paramNames, $map ) : $map;

Src/Traits/ContainerAware.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ private static function withFirstPartyContainer( array $options, bool $shared =
3131
}
3232

3333
$reflection = $options[1] ?? null;
34-
$args = $options[2] ?? array();
34+
$args = $options[2] ?? [];
3535
$instance = $reflection
3636
? $container->resolve( static::class, $args, reflector: $reflection )
3737
: $container->get( static::class, $args );

Src/Traits/DirectoryScanner.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ trait DirectoryScanner {
1212

1313
private DirectoryIterator $currentScannedItem;
1414
/** @var string[] */
15-
private array $scannedDirectories = array();
15+
private array $scannedDirectories = [];
1616
/** @var array<string,string> */
1717
private array $scannedPaths;
1818

@@ -91,7 +91,7 @@ final protected function scan( ?string $directory = null ): static {
9191
$this->scannedDirectories[] = $directory;
9292

9393
$this->realDirectoryPath( $this->getRootPath() ) === $directory
94-
&& $this->maybeRegisterCurrentDepth( count: 0, parts: array(), item: $scanner );
94+
&& $this->maybeRegisterCurrentDepth( count: 0, parts: [], item: $scanner );
9595

9696
while ( $scanner->valid() ) {
9797
$this->currentScannedItem = $scanner->current();
@@ -110,7 +110,7 @@ final protected function scan( ?string $directory = null ): static {
110110
* @return string[]
111111
*/
112112
protected function getAllowedExtensions(): array {
113-
return array( 'php' );
113+
return [ 'php' ];
114114
}
115115

116116
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found -- May be used by exhibiting class.

Src/Traits/InputProperties.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function __construct(
6363
$this->isOptional = $isOptional ?? $this->isOptional();
6464
$this->mode = $this->normalizeMode();
6565
$this->default = $this->normalizeDefault( $default );
66-
$this->suggestedValues = Parser::parseInputSuggestion( $suggestedValues ?? array() );
66+
$this->suggestedValues = Parser::parseInputSuggestion( $suggestedValues ?? [] );
6767
}
6868

6969
public function __toString(): string {

0 commit comments

Comments
 (0)