Skip to content

Commit

Permalink
Applying Rector Rules: Part 1 (#509)
Browse files Browse the repository at this point in the history
* Applying AddVoidReturnTypeWhereNoReturnRector

* Applying RemoveUselessReturnTagRector and RenameForeachValueVariableToMatchExprVariableRector rules

* Applying RemoveUnusedForeachKeyRector and RemoveDuplicatedArrayKeyRector

* Applying more
RecastingRemovalRector
RemoveAndTrueRector
SimplifyMirrorAssignRector

* Applying rules:
RemoveDeadContinueRector
RemoveUnusedNonEmptyArrayBeforeForeachRector
RemoveNullPropertyInitializationRector
RemoveUselessReturnExprInConstructRector
RemoveTypedPropertyDeadInstanceOfRector

* Applying

* Applying RemoveNonExistingVarAnnotationRector
RemoveUselessVarTagRector
RemovePhpVersionIdCheckRector
RemoveAlwaysTrueIfConditionRector
RemoveUnusedPrivateClassConstantRector
RemoveUnusedPrivatePropertyRector
RemoveDuplicatedCaseInSwitchRector
RemoveDeadInstanceOfRector
RemoveDeadTryCatchRector

* Disabling Squiz.Commenting.VariableComment.MissingVar phpcs rule

* Enabling a few more
  • Loading branch information
srtfisher committed Mar 6, 2024
1 parent 1baf83f commit 316488a
Show file tree
Hide file tree
Showing 86 changed files with 70 additions and 409 deletions.
1 change: 1 addition & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<exclude name="Squiz.Commenting.FunctionComment.IncorrectTypeHint" />
<exclude name="Generic.Commenting.DocComment.SpacingAfterTagGroup" />
<exclude name="Generic.Commenting.DocComment.MissingShort" />
<exclude name="Squiz.Commenting.VariableComment.MissingVar" />
</rule>

<rule ref="Generic.Arrays.DisallowLongArraySyntax" />
Expand Down
67 changes: 33 additions & 34 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,40 +84,38 @@
// Dead Code Set
///////////////////////////////////////////////////
// easy picks
// RemoveUnusedForeachKeyRector::class,
// RemoveDuplicatedArrayKeyRector::class,
// RecastingRemovalRector::class,
// RemoveAndTrueRector::class,
// SimplifyMirrorAssignRector::class,
// RemoveDeadContinueRector::class,
// RemoveUnusedNonEmptyArrayBeforeForeachRector::class,
// RemoveNullPropertyInitializationRector::class,
// RemoveUselessReturnExprInConstructRector::class,
// RemoveTypedPropertyDeadInstanceOfRector::class,
// TernaryToBooleanOrFalseToBooleanAndRector::class,
// RemoveDoubleAssignRector::class,
// RemoveConcatAutocastRector::class,
// SimplifyIfElseWithSameContentRector::class,
// SimplifyUselessVariableRector::class,
// RemoveDeadZeroAndOneOperationRector::class,
RemoveUnusedForeachKeyRector::class,
RemoveDuplicatedArrayKeyRector::class,
RecastingRemovalRector::class,
RemoveAndTrueRector::class,
SimplifyMirrorAssignRector::class,
RemoveDeadContinueRector::class,
RemoveUnusedNonEmptyArrayBeforeForeachRector::class,
RemoveNullPropertyInitializationRector::class,
RemoveUselessReturnExprInConstructRector::class,
RemoveTypedPropertyDeadInstanceOfRector::class,
TernaryToBooleanOrFalseToBooleanAndRector::class,
RemoveDoubleAssignRector::class,
RemoveConcatAutocastRector::class,
SimplifyIfElseWithSameContentRector::class,
SimplifyUselessVariableRector::class,
RemoveDeadZeroAndOneOperationRector::class,
// docblock
// RemoveUselessParamTagRector::class,
// RemoveUselessReturnTagRector::class,
// RemoveNonExistingVarAnnotationRector::class,
// RemoveUselessVarTagRector::class,
// RemovePhpVersionIdCheckRector::class,
// RemoveAlwaysTrueIfConditionRector::class,
// RemoveUnusedPrivateClassConstantRector::class,
// RemoveUnusedPrivatePropertyRector::class,
// RemoveDuplicatedCaseInSwitchRector::class,
// RemoveDeadInstanceOfRector::class,
// RemoveDeadTryCatchRector::class,
// RemoveDeadIfForeachForRector::class,
// RemoveDeadStmtRector::class,
// UnwrapFutureCompatibleIfPhpVersionRector::class,
// RemoveParentCallWithoutParentRector::class,
// RemoveDeadConditionAboveReturnRector::class,
// RemoveDeadLoopRector::class,
RemoveNonExistingVarAnnotationRector::class,
RemoveUselessVarTagRector::class,
RemovePhpVersionIdCheckRector::class,
RemoveAlwaysTrueIfConditionRector::class,
RemoveUnusedPrivateClassConstantRector::class,
RemoveUnusedPrivatePropertyRector::class,
RemoveDuplicatedCaseInSwitchRector::class,
RemoveDeadInstanceOfRector::class,
RemoveDeadTryCatchRector::class,
RemoveDeadIfForeachForRector::class,
RemoveDeadStmtRector::class,
UnwrapFutureCompatibleIfPhpVersionRector::class,
RemoveParentCallWithoutParentRector::class,
RemoveDeadConditionAboveReturnRector::class,
RemoveDeadLoopRector::class,
// // removing methods could be risky if there is some magic loading them
// RemoveUnusedPromotedPropertyRector::class,
// RemoveUnusedPrivateMethodParameterRector::class,
Expand Down Expand Up @@ -145,5 +143,6 @@
AddVoidReturnTypeWhereNoReturnRector::class => [
__DIR__ . '/src/Mantle/testing/concerns/trait-core-shim.php',
__DIR__ . '/tests/Testing/CoreTestShimTest.php',
]
],
RemoveUselessParamTagRector::class,
]);
22 changes: 2 additions & 20 deletions src/mantle/application/class-application.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,36 +43,26 @@ class Application extends Container implements \Mantle\Contracts\Application {

/**
* Bootstrap path of the application.
*
* @var string|null
*/
protected ?string $bootstrap_path = null;

/**
* Storage path of the application.
*
* @var string|null
*/
protected ?string $storage_path = null;

/**
* Root URL of the application.
*
* @var string|null
*/
protected ?string $root_url = null;

/**
* Indicates if the application has been bootstrapped before.
*
* @var bool
*/
protected bool $has_been_bootstrapped = false;

/**
* Indicates if the application has "booted".
*
* @var bool
*/
protected bool $booted = false;

Expand All @@ -99,29 +89,21 @@ class Application extends Container implements \Mantle\Contracts\Application {

/**
* Environment file name.
*
* @var string
*/
protected string $environment_file = '.env';

/**
* The custom environment path defined by the developer.
*
* @var string
*/
protected ?string $environment_path = null;

/**
* Storage of the overridden environment name.
*
* @var string
*/
protected ?string $environment;

/**
* Indicates if the application is running in the console.
*
* @var bool
*/
protected ?bool $is_running_in_console = null;

Expand Down Expand Up @@ -360,7 +342,7 @@ public function get_config_path(): string {
* Determine if the application has been bootstrapped before.
*/
public function has_been_bootstrapped(): bool {
return (bool) $this->has_been_bootstrapped;
return $this->has_been_bootstrapped;
}

/**
Expand Down Expand Up @@ -530,7 +512,7 @@ public function environment(): string {
* @param string|array ...$environments Environments to check.
*/
public function is_environment( ...$environments ): bool {
return in_array( $this->environment(), (array) $environments, true );
return in_array( $this->environment(), $environments, true );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,6 @@ public function register( Service_Provider|string $provider ): static {
$provider = new $provider( $this );
}

if ( ! ( $provider instanceof Service_Provider ) ) {
throw new InvalidArgumentException( "Provider is not instance of Service_Provider: {$provider_name}" );
}

$provider->register();

$this->service_providers[ $provider_name ] = $provider;
Expand Down
8 changes: 1 addition & 7 deletions src/mantle/assets/class-asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,20 @@ class Asset {
*
* @var string
*/
protected $media = null;
protected $media;

/**
* Enqueue on frontend.
*
* @var bool
*/
protected bool $frontend = true;

/**
* Enqueue in the admin area.
*
* @var bool
*/
protected bool $admin = true;

/**
* Enqueue in the block editor area.
*
* @var bool
*/
protected bool $block_editor = false;

Expand Down
28 changes: 0 additions & 28 deletions src/mantle/blocks/class-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,102 +31,74 @@ abstract class Block implements Block_Contract {

/**
* A custom override value for the block's Editor script location.
*
* @var string
*/
protected string $editor_script = '';

/**
* A custom override value for the block's Editor script asset file location.
*
* @var string
*/
protected string $editor_script_asset = '';

/**
* A custom override value for the block's Editor script dependencies.
*
* @var array
*/
protected array $editor_script_dependencies = [];

/**
* A custom override value for the block's Editor script handle.
*
* @var string
*/
protected string $editor_script_handle = '';

/**
* A custom override value for the block's Editor style location.
*
* @var string
*/
protected string $editor_style = '';

/**
* A custom override value for the block's Editor style handle.
*
* @var string
*/
protected string $editor_style_handle = '';

/**
* The block's entry file without the extension.
*
* Generally this is going to be an index file (e.g. index.js, index.jsx)
*
* @var string
*/
protected string $entry_filename = 'index';

/**
* A custom override value for the block's Frontend script location.
*
* @var string
*/
protected string $frontend_script = '';

/**
* A custom override value for the block's Frontend script handle.
*
* @var string
*/
protected string $frontend_script_handle = '';

/**
* A custom override value for the block's Frontend style location.
*
* @var string
*/
protected string $frontend_style = '';

/**
* A custom override value for the block's Frontend style handle.
*
* @var string
*/
protected string $frontend_style_handle = '';

/**
* Whether the block is a dynamic block or not.
* Default is true.
*
* @var bool
*/
protected bool $is_dynamic = true;

/**
* The name of the block.
*
* @var string
*/
protected string $name = '';

/**
* The namespace of the block.
*
* @var string
*/
protected string $namespace = '';

Expand Down
4 changes: 1 addition & 3 deletions src/mantle/blocks/class-discover-blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected static function class_from_file( SplFileInfo $file, string $base_path
DIRECTORY_SEPARATOR,
);

$classname = str_replace(
return str_replace(
[
DIRECTORY_SEPARATOR,
ucfirst( basename( app()->get_app_path() ) ) . '\\',
Expand All @@ -92,7 +92,5 @@ protected static function class_from_file( SplFileInfo $file, string $base_path
],
ucfirst( Str::replace_last( '.php', '', $class ) ),
);

return $classname;
}
}
4 changes: 2 additions & 2 deletions src/mantle/cache/class-array-repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function put( $key, $value, $ttl = null ): bool {
* @return int|bool
*/
public function increment( $key, $value = 1 ) {
$value = (int) $this->get( $key, 0 );
$value = $this->get( $key, 0 );
return $this->set( $key, $value += $value );
}

Expand All @@ -96,7 +96,7 @@ public function increment( $key, $value = 1 ) {
* @return int|bool
*/
public function decrement( $key, $value = 1 ) {
$value = (int) $this->get( $key, 0 );
$value = $this->get( $key, 0 );
return $this->set( $key, $value -= $value );
}

Expand Down
4 changes: 0 additions & 4 deletions src/mantle/console/class-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,11 @@ abstract class Command extends Symfony_Command {

/**
* The command's help text.
*
* @var string
*/
protected string $help;

/**
* Container instance.
*
* @var \Mantle\Contracts\Application
*/
protected \Mantle\Contracts\Application $container;

Expand Down
2 changes: 1 addition & 1 deletion src/mantle/console/class-output-style.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function format_xml( array $headers, array $data ): void {

$xml = new \SimpleXMLElement( '<root/>' );

foreach ( $data as $headers => $row ) {
foreach ( $data as $row ) {
$item = $xml->addChild( 'item' );

foreach ( $row as $key => $value ) {
Expand Down
4 changes: 0 additions & 4 deletions src/mantle/console/concerns/trait-interacts-with-io.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,11 @@
trait Interacts_With_IO {
/**
* The input implementation.
*
* @var InputInterface
*/
protected InputInterface $input;

/**
* Output interface.
*
* @var Output_Style
*/
protected Output_Style $output;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
class Lightweight_Event_Dispatcher extends Dispatcher {
/**
* Event listeners.
*
* @var array
*/
protected array $listeners = [];

Expand Down
Loading

0 comments on commit 316488a

Please sign in to comment.