From 994a328b51bf98011e72e3eaa01875715885dbbb Mon Sep 17 00:00:00 2001 From: Sean Fisher Date: Mon, 16 Sep 2024 20:20:22 -0400 Subject: [PATCH] Upgrading to Alley Coding Standards 2.0 (#585) * Starting migration to cs 2.0 * Contd work * PHPCS fixes for database * Contd migration * Fixing testing * Migrating helper * Finishing upgrade of coding standards * Removing some global rule exceptions * Removing some global rule exceptions * Finishing upgrade * Fixing tests --- composer.json | 2 +- monorepo-builder.php | 2 +- phpcs.xml | 12 ++-- rector.php | 2 + src/mantle/application/class-application.php | 12 ++-- .../trait-loads-base-configuration.php | 2 +- .../assets/class-asset-service-provider.php | 2 +- src/mantle/blocks/class-block.php | 4 +- src/mantle/console/class-command.php | 4 +- .../class-lightweight-event-dispatcher.php | 2 +- src/mantle/container/class-container.php | 6 +- .../database/interface-model-meta.php | 3 +- .../filesystem/interface-filesystem.php | 2 +- .../routing/interface-response-factory.php | 4 +- src/mantle/contracts/interface-container.php | 2 +- .../contracts/support/interface-jsonable.php | 19 ++++-- .../database/model/class-attachment.php | 2 +- src/mantle/database/model/class-comment.php | 4 +- .../model/class-model-not-found-exception.php | 42 ++++++------ src/mantle/database/model/class-model.php | 20 +++--- src/mantle/database/model/class-post.php | 18 ++--- src/mantle/database/model/class-term.php | 8 +-- src/mantle/database/model/class-user.php | 4 +- .../model/concerns/trait-has-attributes.php | 13 ++-- .../model/events/trait-post-events.php | 6 +- .../model/events/trait-term-events.php | 2 +- .../database/model/meta/trait-model-meta.php | 3 +- .../registration/trait-register-post-type.php | 2 +- .../model/relations/class-belongs-to-many.php | 4 +- .../model/relations/class-belongs-to.php | 10 +-- .../model/relations/class-has-many.php | 2 +- .../model/relations/class-has-one-or-many.php | 12 ++-- .../model/relations/class-has-one.php | 2 +- .../model/relations/class-relation.php | 2 +- src/mantle/database/query/class-builder.php | 12 ++-- .../database/query/class-collection.php | 2 +- .../query/class-post-query-builder.php | 3 +- .../query/concerns/trait-queries-dates.php | 4 +- .../query/concerns/trait-query-bindings.php | 2 +- .../query/trait-queries-relationships.php | 4 +- src/mantle/events/class-dispatcher.php | 2 +- src/mantle/events/trait-wordpress-action.php | 4 +- .../filesystem/class-filesystem-adapter.php | 2 +- src/mantle/filesystem/class-filesystem.php | 25 ++++--- .../console/class-config-cache-command.php | 6 +- .../console/class-hook-usage-command.php | 7 +- .../console/class-route-list-command.php | 2 +- .../events/class-events-manifest.php | 2 +- .../framework/exceptions/class-handler.php | 4 +- .../manifest/class-model-manifest.php | 2 +- .../manifest/class-package-manifest.php | 6 +- .../class-event-service-provider.php | 2 +- .../class-routing-service-provider.php | 6 +- .../class-asset-service-provider.php | 6 +- .../http-client/class-pending-request.php | 5 +- src/mantle/http/class-request.php | 11 ++-- src/mantle/http/class-uploaded-file.php | 3 +- .../trait-interacts-with-content-types.php | 2 +- .../http/routing/class-entity-router.php | 2 +- .../routing/class-implicit-route-binding.php | 2 +- .../routing/class-rest-route-registrar.php | 6 +- .../http/routing/class-route-binding.php | 2 +- .../routing/class-route-file-registrar.php | 4 +- .../http/routing/class-route-registrar.php | 6 +- src/mantle/http/routing/class-router.php | 8 +-- src/mantle/http/view/class-factory.php | 9 ++- src/mantle/http/view/class-view-finder.php | 7 +- src/mantle/http/view/class-view.php | 2 +- src/mantle/log/class-log-manager.php | 3 +- src/mantle/log/class-log-service-provider.php | 2 +- .../collector/class-log-collector.php | 2 +- .../queue/console/class-run-command.php | 8 +-- .../admin/class-service-provider.php | 1 - .../providers/wordpress/class-provider.php | 4 +- .../providers/wordpress/class-scheduler.php | 8 +-- src/mantle/scheduling/class-event.php | 5 +- src/mantle/support/class-collection.php | 26 ++++---- .../class-higher-order-collection-proxy.php | 2 +- src/mantle/support/class-pipeline.php | 66 +++++++++---------- src/mantle/support/class-pluralizer.php | 4 +- src/mantle/support/class-service-provider.php | 2 +- src/mantle/support/class-str.php | 12 ++-- src/mantle/support/class-stringable.php | 4 +- src/mantle/support/helpers/helpers-array.php | 2 +- .../support/helpers/helpers-general.php | 30 ++++++--- src/mantle/support/interface-enumerable.php | 66 +++++++++---------- src/mantle/support/trait-forward-calls.php | 2 +- .../traits/trait-enumerates-values.php | 53 +++++++-------- src/mantle/support/traits/trait-hookable.php | 4 +- .../testing/class-assertable-json-string.php | 31 +++++---- .../testing/class-mock-http-response.php | 3 +- .../class-pending-testable-request.php | 8 +-- src/mantle/testing/class-test-case.php | 36 +++++----- src/mantle/testing/class-test-command.php | 8 +-- src/mantle/testing/class-test-response.php | 25 +------ src/mantle/testing/class-utils.php | 2 +- .../testing/concerns/trait-assertions.php | 16 +++-- .../concerns/trait-create-application.php | 2 +- .../concerns/trait-dependency-assertions.php | 1 - .../testing/concerns/trait-deprecations.php | 3 +- .../concerns/trait-incorrect-usage.php | 3 +- .../trait-interacts-with-container.php | 2 + .../concerns/trait-interacts-with-hooks.php | 2 +- .../trait-interacts-with-requests.php | 2 +- .../concerns/trait-makes-http-requests.php | 2 +- .../concerns/trait-refresh-database.php | 2 +- .../concerns/trait-rsync-installation.php | 2 + .../concerns/trait-snapshot-testing.php | 2 +- .../testing/exceptions/class-exception.php | 2 +- .../testing/expectation/class-expectation.php | 4 +- src/mantle/testing/mail/class-mock-mailer.php | 6 +- src/mantle/testing/preload.php | 6 +- .../testing/snapshots/class-html-driver.php | 2 +- src/mantle/testkit/class-application.php | 2 +- .../concerns/trait-create-application.php | 2 +- .../view/class-view-service-provider.php | 4 +- tests/Console/generators/PrinterTest.php | 5 +- 117 files changed, 452 insertions(+), 447 deletions(-) diff --git a/composer.json b/composer.json index 014aa006f..d9d836978 100644 --- a/composer.json +++ b/composer.json @@ -46,7 +46,7 @@ "voku/portable-ascii": "^2.0.1" }, "require-dev": { - "alleyinteractive/alley-coding-standards": "^1.0.1", + "alleyinteractive/alley-coding-standards": "^2.0", "alleyinteractive/wp-match-blocks": "^1.0 || ^2.0 || ^3.0", "guzzlehttp/guzzle": "^7.7", "league/flysystem-aws-s3-v3": "^3.15", diff --git a/monorepo-builder.php b/monorepo-builder.php index 4cf4ac275..fefd1b91e 100644 --- a/monorepo-builder.php +++ b/monorepo-builder.php @@ -53,7 +53,7 @@ 'php' => '^8.1', ], ComposerJsonSection::REQUIRE_DEV => [ - 'alleyinteractive/alley-coding-standards' => '^1.0', + 'alleyinteractive/alley-coding-standards' => '^2.0', 'phpunit/phpunit' => '^9.3.3 || ^10.0.7 || ^11.0', ], ], diff --git a/phpcs.xml b/phpcs.xml index 800712150..a3fbf02ed 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -14,23 +14,21 @@ - - + bin/ tests/ - - - - + + - + + diff --git a/rector.php b/rector.php index da0e7c9c1..01d76dfa8 100644 --- a/rector.php +++ b/rector.php @@ -1,5 +1,7 @@ $_ENV['MANTLE_BASE_PATH'], + isset( $_ENV['MANTLE_BASE_PATH'] ) => $_ENV['MANTLE_BASE_PATH'], // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized defined( 'MANTLE_BASE_DIR' ) => MANTLE_BASE_DIR, default => '', }; diff --git a/src/mantle/application/concerns/trait-loads-base-configuration.php b/src/mantle/application/concerns/trait-loads-base-configuration.php index 8abd948b5..95a798410 100644 --- a/src/mantle/application/concerns/trait-loads-base-configuration.php +++ b/src/mantle/application/concerns/trait-loads-base-configuration.php @@ -23,7 +23,7 @@ public function load_base_configuration(): void { // Check if a cached configuration file exists. If found, load it. if ( is_file( $cached ) ) { - $items = require $cached; + $items = require $cached; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable $loaded_from_cache = true; } else { diff --git a/src/mantle/assets/class-asset-service-provider.php b/src/mantle/assets/class-asset-service-provider.php index 31f245721..f0d79801f 100644 --- a/src/mantle/assets/class-asset-service-provider.php +++ b/src/mantle/assets/class-asset-service-provider.php @@ -41,7 +41,7 @@ public function register(): void { protected function load_blocks(): void { foreach ( $this->app['asset.loader']->blocks() as $file ) { if ( file_exists( $file ) && 0 === validate_file( $file ) ) { - require_once $file; + require_once $file; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable } } } diff --git a/src/mantle/blocks/class-block.php b/src/mantle/blocks/class-block.php index f464436de..8aa68e8b1 100644 --- a/src/mantle/blocks/class-block.php +++ b/src/mantle/blocks/class-block.php @@ -123,7 +123,7 @@ public function register(): void { add_action( 'enqueue_block_editor_assets', - function(): void { + function (): void { $this->register_editor_assets(); $this->register_frontend_assets(); } @@ -131,7 +131,7 @@ function(): void { add_action( 'init', - function(): void { + function (): void { $args = wp_parse_args( [ 'attributes' => $this->get_attributes(), diff --git a/src/mantle/console/class-command.php b/src/mantle/console/class-command.php index f279b4bdc..180181501 100644 --- a/src/mantle/console/class-command.php +++ b/src/mantle/console/class-command.php @@ -19,8 +19,8 @@ * CLI Command for Service Providers */ abstract class Command extends Symfony_Command { - use Concerns\Interacts_With_IO, - Macroable; + use Concerns\Interacts_With_IO; + use Macroable; /** * Prefix for the command. diff --git a/src/mantle/console/events/class-lightweight-event-dispatcher.php b/src/mantle/console/events/class-lightweight-event-dispatcher.php index 1b6cf7759..24fdd83e2 100644 --- a/src/mantle/console/events/class-lightweight-event-dispatcher.php +++ b/src/mantle/console/events/class-lightweight-event-dispatcher.php @@ -105,7 +105,7 @@ public function forget( $event, $listener = null, int $priority = 10 ): void { } else { $this->listeners[ $event ][ $priority ] = array_filter( $this->listeners[ $event ][ $priority ], - fn ( $value) => $value !== $listener + fn ( $value ) => $value !== $listener ); } } diff --git a/src/mantle/container/class-container.php b/src/mantle/container/class-container.php index 83b69f7f5..144b0fcb8 100644 --- a/src/mantle/container/class-container.php +++ b/src/mantle/container/class-container.php @@ -235,7 +235,7 @@ public function bind( $abstract, $concrete = null, $shared = false ): void { */ protected function get_closure( $abstract, $concrete ) { return function ( $container, $parameters = [] ) use ( $abstract, $concrete ) { - if ( $abstract == $concrete ) { + if ( $abstract === $concrete ) { return $container->build( $concrete ); } @@ -390,7 +390,7 @@ protected function remove_abstract_alias( $searched ) { foreach ( $this->abstract_aliases as $abstract => $aliases ) { foreach ( $aliases as $index => $alias ) { - if ( $alias == $searched ) { + if ( $alias === $searched ) { unset( $this->abstract_aliases[ $abstract ][ $index ] ); } } @@ -870,7 +870,7 @@ protected function resolve_variadic_class( ReflectionParameter $parameter ) { } return array_map( - fn ( $abstract) => $this->resolve( $abstract ), + fn ( $abstract ) => $this->resolve( $abstract ), $concrete ); } diff --git a/src/mantle/contracts/database/interface-model-meta.php b/src/mantle/contracts/database/interface-model-meta.php index b35e05d6e..164d40b29 100644 --- a/src/mantle/contracts/database/interface-model-meta.php +++ b/src/mantle/contracts/database/interface-model-meta.php @@ -26,9 +26,8 @@ public function get_meta( string $meta_key, bool $single = true ): mixed; * * @param string $meta_key Meta key. * @param mixed $meta_value Meta value to store. - * @param string $prev_value Optional, previous meta value. */ - public function add_meta( string $meta_key, mixed $meta_value, mixed $prev_value = '' ): void; + public function add_meta( string $meta_key, mixed $meta_value ): void; /** * Update meta value for the object. diff --git a/src/mantle/contracts/filesystem/interface-filesystem.php b/src/mantle/contracts/filesystem/interface-filesystem.php index 55a9f6b66..3ccad67c1 100644 --- a/src/mantle/contracts/filesystem/interface-filesystem.php +++ b/src/mantle/contracts/filesystem/interface-filesystem.php @@ -177,7 +177,7 @@ public function prepend( string $path, string $data, string $separator = PHP_EOL * @param string $separator Separator from existing data. * @return bool */ - public function append( $path, $data, $separator = PHP_EOL); + public function append( $path, $data, $separator = PHP_EOL ); /** * Retrieve a file's visibility. diff --git a/src/mantle/contracts/http/routing/interface-response-factory.php b/src/mantle/contracts/http/routing/interface-response-factory.php index 9a00d2d8e..570f61739 100644 --- a/src/mantle/contracts/http/routing/interface-response-factory.php +++ b/src/mantle/contracts/http/routing/interface-response-factory.php @@ -76,7 +76,7 @@ public function jsonp( $callback, $data = [], $status = 200, array $headers = [] * @param array $headers * @return \Symfony\Component\HttpFoundation\StreamedResponse */ - public function stream( $callback, $status = 200, array $headers = []); + public function stream( $callback, $status = 200, array $headers = [] ); /** * Create a new streamed response instance as a file download. @@ -107,7 +107,7 @@ public function download( $file, $name = null, array $headers = [], $disposition * @param array $headers * @return \Symfony\Component\HttpFoundation\BinaryFileResponse */ - public function file( $file, array $headers = []); + public function file( $file, array $headers = [] ); /** * Create a new redirect response to the given path. diff --git a/src/mantle/contracts/interface-container.php b/src/mantle/contracts/interface-container.php index 1e378ae61..c6945d2d4 100644 --- a/src/mantle/contracts/interface-container.php +++ b/src/mantle/contracts/interface-container.php @@ -70,7 +70,7 @@ public function singleton_if( $abstract, $concrete = null ); * @param string $abstract Abstract name. * @param \Closure $closure Closure callback. */ - public function extend( $abstract, Closure $closure); + public function extend( $abstract, Closure $closure ); /** * Register an existing instance as shared in the container. diff --git a/src/mantle/contracts/support/interface-jsonable.php b/src/mantle/contracts/support/interface-jsonable.php index cf4e3f982..8f24e00f0 100644 --- a/src/mantle/contracts/support/interface-jsonable.php +++ b/src/mantle/contracts/support/interface-jsonable.php @@ -1,13 +1,18 @@ get_error_message() ); } diff --git a/src/mantle/database/model/class-comment.php b/src/mantle/database/model/class-comment.php index 7ad354d98..c69e1adf2 100644 --- a/src/mantle/database/model/class-comment.php +++ b/src/mantle/database/model/class-comment.php @@ -16,8 +16,8 @@ * @method static \Mantle\Database\Factory\Post_Factory factory( array|callable|null $state = null ) */ class Comment extends Model implements Contracts\Database\Core_Object, Contracts\Database\Model_Meta, Contracts\Database\Updatable { - use Meta\Model_Meta, - Meta\Comment_Meta; + use Meta\Model_Meta; + use Meta\Comment_Meta; /** * Attributes for the model from the object diff --git a/src/mantle/database/model/class-model-not-found-exception.php b/src/mantle/database/model/class-model-not-found-exception.php index 8ca698640..f316d0193 100644 --- a/src/mantle/database/model/class-model-not-found-exception.php +++ b/src/mantle/database/model/class-model-not-found-exception.php @@ -14,37 +14,26 @@ */ class Model_Not_Found_Exception extends Model_Exception { /** - * Name of the affected Eloquent model. + * Constructor. * - * @var string + * @param array|string $model Name of the affected Eloquent model(s). + * @param array $ids Model ID(s). */ - protected $model; - - /** - * The affected model IDs. - * - * @var int|array - */ - protected $ids; + public function __construct( public array|string $model, public array $ids = [] ) { + $this->set_message(); + } /** * Set the affected Eloquent model and instance ids. * * @param string $model Model name. * @param int|array $ids Model ID(s). - * @return static */ - public function set_model( string $model, $ids = [] ) { + public function set_model( string $model, $ids = [] ): static { $this->model = $model; $this->ids = Arr::wrap( $ids ); - $this->message = "No query results for model [{$model}]"; - - if ( count( $this->ids ) > 0 ) { - $this->message .= ' ' . implode( ', ', $this->ids ); - } else { - $this->message .= '.'; - } + $this->set_message(); return $this; } @@ -64,4 +53,19 @@ public function get_model(): string { public function get_ids() { return $this->ids; } + + /** + * Set the exception message. + */ + protected function set_message(): void { + $model = is_array( $this->model ) ? implode( ', ', $this->model ) : $this->model; + + $this->message = "No query results for model [{$model}]"; + + if ( count( $this->ids ) > 0 ) { + $this->message .= ' ' . implode( ', ', $this->ids ); + } else { + $this->message .= '.'; + } + } } diff --git a/src/mantle/database/model/class-model.php b/src/mantle/database/model/class-model.php index 0ba8aca44..d9c4b7e28 100644 --- a/src/mantle/database/model/class-model.php +++ b/src/mantle/database/model/class-model.php @@ -39,14 +39,14 @@ * @method static \Mantle\Contracts\Paginator\Paginator paginate(int $per_page = 20, int $current_page = null) */ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializable, Url_Routable { - use Forward_Calls, - Concerns\Has_Aliases, - Concerns\Has_Attributes, - Concerns\Has_Events, - /** @use Concerns\Has_Factory */ - Concerns\Has_Factory, - Concerns\Has_Global_Scopes, - Concerns\Has_Relationships; + use Forward_Calls; + use Concerns\Has_Aliases; + use Concerns\Has_Attributes; + use Concerns\Has_Events; + /** @use Concerns\Has_Factory */ + use Concerns\Has_Factory; + use Concerns\Has_Global_Scopes; + use Concerns\Has_Relationships; /** * The array of booted models. @@ -131,7 +131,7 @@ public static function find_or_fail( $object ) { return $find; } - throw ( new Model_Not_Found_Exception() )->set_model( self::class, $object ); + throw new Model_Not_Found_Exception( static::class, [ $object ] ); } /** @@ -294,7 +294,7 @@ protected static function boot_traits() { $trait_method = strtolower( class_basename( $trait ) ); $method = 'boot_' . $trait_method; - if ( method_exists( $class, $method ) && ! in_array( $method, $booted ) ) { + if ( method_exists( $class, $method ) && ! in_array( $method, $booted, true ) ) { forward_static_call( [ $class, $method ] ); $booted[] = $method; diff --git a/src/mantle/database/model/class-post.php b/src/mantle/database/model/class-post.php index 6e4ec5308..319a9ce79 100644 --- a/src/mantle/database/model/class-post.php +++ b/src/mantle/database/model/class-post.php @@ -88,11 +88,11 @@ * @method static \Mantle\Database\Query\Post_Query_Builder newer_than_or_equal_to( DateTimeInterface|int $date, string $column = 'post_date' ) */ class Post extends Model implements Contracts\Database\Core_Object, Contracts\Database\Model_Meta, Contracts\Database\Updatable { - use Dates\Has_Dates, - Events\Post_Events, - Meta\Model_Meta, - Meta\Post_Meta, - Term\Model_Term; + use Dates\Has_Dates; + use Events\Post_Events; + use Meta\Model_Meta; + use Meta\Post_Meta; + use Term\Model_Term; /** * Attributes for the model from the object @@ -195,7 +195,7 @@ public function __construct() {} * Retrieve the object name. */ public static function get_object_name(): ?string { - return static::$for_object_name; + return self::$for_object_name; } /** @@ -204,7 +204,7 @@ public static function get_object_name(): ?string { * Prevent booting the model unless the object name is set. */ public static function boot_if_not_booted(): void { - if ( empty( static::$for_object_name ) ) { + if ( empty( self::$for_object_name ) ) { return; } @@ -305,7 +305,7 @@ public function core_object(): ?\WP_Post { /** * Publish a post. */ - public function publish() : bool { + public function publish(): bool { return $this->save( [ 'status' => 'publish' ] ); } @@ -314,7 +314,7 @@ public function publish() : bool { * * @param string|DateTime $date Date to schedule the post for. */ - public function schedule( $date ) : bool { + public function schedule( $date ): bool { if ( $date instanceof DateTime ) { $date = $date->format( 'Y-m-d H:i:s' ); } else { diff --git a/src/mantle/database/model/class-term.php b/src/mantle/database/model/class-term.php index cd92a8ec7..30d09c23f 100644 --- a/src/mantle/database/model/class-term.php +++ b/src/mantle/database/model/class-term.php @@ -37,9 +37,9 @@ * @method static \Mantle\Database\Query\Term_Query_Builder or_where_raw( array|string $column, ?string $operator = null, mixed $value = null, string $boolean = 'AND' ) */ class Term extends Model implements Core_Object, Model_Meta, Updatable { - use Events\Term_Events, - Meta\Model_Meta, - Meta\Term_Meta; + use Events\Term_Events; + use Meta\Model_Meta; + use Meta\Term_Meta; /** * Attributes for the model from the object @@ -126,7 +126,7 @@ public function __construct() {} * Prevent booting the model unless the object name is set. */ public static function boot_if_not_booted(): void { - if ( empty( static::$object_name ) ) { + if ( empty( self::$object_name ) ) { return; } diff --git a/src/mantle/database/model/class-user.php b/src/mantle/database/model/class-user.php index dbe8e613b..55d14bd53 100644 --- a/src/mantle/database/model/class-user.php +++ b/src/mantle/database/model/class-user.php @@ -16,8 +16,8 @@ * @method static \Mantle\Database\Factory\User_Factory factory( array|callable|null $state = null ) */ class User extends Model implements Contracts\Database\Core_Object, Contracts\Database\Model_Meta, Contracts\Database\Updatable { - use Meta\Model_Meta, - Meta\User_Meta; + use Meta\Model_Meta; + use Meta\User_Meta; /** * Attributes for the model from the object diff --git a/src/mantle/database/model/concerns/trait-has-attributes.php b/src/mantle/database/model/concerns/trait-has-attributes.php index a1f1afdbe..55ed7b04c 100644 --- a/src/mantle/database/model/concerns/trait-has-attributes.php +++ b/src/mantle/database/model/concerns/trait-has-attributes.php @@ -18,7 +18,8 @@ * Model Attributes */ trait Has_Attributes { - use Has_Guarded_Attributes, Hides_Attributes; + use Has_Guarded_Attributes; + use Hides_Attributes; /** * Attributes for the model from the object @@ -141,7 +142,7 @@ protected function get_relationship_from_method( string $method ) { return tap( $relation->get_results(), - function( $relation ) use ( $method ): void { + function ( $relation ) use ( $method ): void { $this->set_relation( $method, $relation ); } ); @@ -214,7 +215,7 @@ public function attributes_to_array(): array { // Retrieve all attributes, passing them through the mutators. $attributes = collect( $this->get_arrayable_attributes() ) ->map( - fn ( $value, string $attribute) => $this->get_attribute( $attribute ) + fn ( $value, string $attribute ) => $this->get_attribute( $attribute ) ) ->merge( $this->get_arrayable_appends() ); @@ -318,7 +319,7 @@ protected function reset_modified_attributes() { * @return mixed */ protected function cast_attribute( $value, string $cast_type ) { - return match ($cast_type) { + return match ( $cast_type ) { 'int', 'integer' => (int) $value, 'real', 'float', 'double' => $this->from_float( $value ), 'string' => (string) $value, @@ -335,7 +336,7 @@ protected function cast_attribute( $value, string $cast_type ) { * @param mixed $value Value to decode. */ public function from_float( $value ): float { - return match ( (string) $value) { + return match ( (string) $value ) { 'Infinity' => INF, '-Infinity' => -INF, 'NaN' => NAN, @@ -467,7 +468,7 @@ public function get_arrayable_appends(): array { collect( $this->appends ) ->combine( collect( $this->appends )->map( - fn ( string $attribute) => $this->get_attribute( $attribute ) + fn ( string $attribute ) => $this->get_attribute( $attribute ) ) ) ->to_array() diff --git a/src/mantle/database/model/events/trait-post-events.php b/src/mantle/database/model/events/trait-post-events.php index 190304a16..6e11a5f10 100644 --- a/src/mantle/database/model/events/trait-post-events.php +++ b/src/mantle/database/model/events/trait-post-events.php @@ -29,7 +29,7 @@ protected static function subscribe_to_core_events() { add_filter_side_effect( 'wp_insert_post_data', - function( $data, $postarr ) use ( $post_type ): void { + function ( $data, $postarr ) use ( $post_type ): void { // Skip if the ID isn't found or the post type is incorrect. if ( empty( $postarr['ID'] ) || empty( $data['post_type'] ) || $post_type !== $data['post_type'] ) { return; @@ -50,7 +50,7 @@ function( $data, $postarr ) use ( $post_type ): void { \add_action( 'save_post', - function( $post_id, \WP_Post $post, $update ) use ( $post_type ): void { + function ( $post_id, \WP_Post $post, $update ) use ( $post_type ): void { if ( $post_type !== $post->post_type ) { return; } @@ -82,7 +82,7 @@ function( $post_id, \WP_Post $post, $update ) use ( $post_type ): void { * @param string $post_type Post type to limit to. */ protected static function get_post_event_callback( string $event, string $post_type ): Closure { - return function( $post_id ) use ( $event, $post_type ): void { + return function ( $post_id ) use ( $event, $post_type ): void { $post = \get_post( $post_id ); if ( empty( $post ) || $post_type !== $post->post_type ) { return; diff --git a/src/mantle/database/model/events/trait-term-events.php b/src/mantle/database/model/events/trait-term-events.php index 484daf3c3..3c45911a4 100644 --- a/src/mantle/database/model/events/trait-term-events.php +++ b/src/mantle/database/model/events/trait-term-events.php @@ -40,7 +40,7 @@ protected static function subscribe_to_core_events() { * @param string $taxonomy Taxonomy to limit to. */ protected static function get_term_event_callback( string $event, string $taxonomy ): Closure { - return function( $term_id, $tt_id, $term_taxonomy = null, $term = null ) use ( $event, $taxonomy ): void { + return function ( $term_id, $tt_id, $term_taxonomy = null, $term = null ) use ( $event, $taxonomy ): void { // Account for actions that have taxonomy as the second argument. if ( ( empty( $term_taxonomy ) || ! is_string( $term_taxonomy ) ) && is_string( $tt_id ) ) { $term_taxonomy = $tt_id; diff --git a/src/mantle/database/model/meta/trait-model-meta.php b/src/mantle/database/model/meta/trait-model-meta.php index aa0d44954..efa9c8411 100644 --- a/src/mantle/database/model/meta/trait-model-meta.php +++ b/src/mantle/database/model/meta/trait-model-meta.php @@ -39,9 +39,8 @@ public function get_meta( string $meta_key, bool $single = true ): mixed { * * @param string $meta_key Meta key. * @param mixed $meta_value Meta value to store. - * @param string $prev_value Optional, previous meta value. */ - public function add_meta( string $meta_key, mixed $meta_value, mixed $prev_value = '' ): void { + public function add_meta( string $meta_key, mixed $meta_value ): void { if ( ! $this->id() ) { $this->queue_meta_attribute( $meta_key, $meta_value, false ); return; diff --git a/src/mantle/database/model/registration/trait-register-post-type.php b/src/mantle/database/model/registration/trait-register-post-type.php index 28961345f..b20f66d4f 100644 --- a/src/mantle/database/model/registration/trait-register-post-type.php +++ b/src/mantle/database/model/registration/trait-register-post-type.php @@ -35,7 +35,7 @@ public static function register_object(): void { throw new Model_Exception( 'Unable to register post type (post type already exists): ' . $post_type ); } - $register = \register_post_type( $post_type, static::get_registration_args() ); + $register = \register_post_type( $post_type, static::get_registration_args() ); // phpcs:ignore WordPress.NamingConventions.ValidPostTypeSlug.NotStringLiteral if ( is_wp_error( $register ) ) { throw new Model_Exception( 'Error registering post type: ' . $register->get_error_message() ); diff --git a/src/mantle/database/model/relations/class-belongs-to-many.php b/src/mantle/database/model/relations/class-belongs-to-many.php index 469dc1b5d..211584b0e 100644 --- a/src/mantle/database/model/relations/class-belongs-to-many.php +++ b/src/mantle/database/model/relations/class-belongs-to-many.php @@ -36,7 +36,7 @@ public function match( Collection $models, Collection $results ): Collection { $dictionary = $this->build_dictionary( $results, $models ); return $models->each( - function( $model ) use ( $dictionary ): void { + function ( $model ) use ( $dictionary ): void { $key = $model->{$this->foreign_key}; $model->set_relation( $this->relationship, $dictionary[ $key ] ?? null ); @@ -60,7 +60,7 @@ protected function build_dictionary( Collection $results, Collection $models ): return $dictionary ->map( - fn ( $child_ids) => $results->only( $child_ids )->values()->all() + fn ( $child_ids ) => $results->only( $child_ids )->values()->all() ) ->filter() ->all(); diff --git a/src/mantle/database/model/relations/class-belongs-to.php b/src/mantle/database/model/relations/class-belongs-to.php index da1099f2c..fbe8523ea 100644 --- a/src/mantle/database/model/relations/class-belongs-to.php +++ b/src/mantle/database/model/relations/class-belongs-to.php @@ -111,7 +111,7 @@ public function add_eager_constraints( Collection $models ): void { $meta_values = $models ->map( - fn ( $model) => $model->get_meta( $this->local_key, ! $append ) + fn ( $model ) => $model->get_meta( $this->local_key, ! $append ) ) ->filter(); @@ -305,7 +305,7 @@ protected function get_term_ids_for_relationship( bool $return_term_ids = false return collect( $object_terms ) ->filter( - function( WP_Term $term ): bool { + function ( WP_Term $term ): bool { $key = Str::before_last( $term->slug, Has_One_Or_Many::DELIMITER ); $id = Str::after_last( $term->slug, Has_One_Or_Many::DELIMITER ); @@ -313,7 +313,7 @@ function( WP_Term $term ): bool { } ) ->map( - function( WP_Term $term ) use ( $return_term_ids ) { + function ( WP_Term $term ) use ( $return_term_ids ) { if ( $return_term_ids ) { return $term->term_id; } @@ -335,7 +335,7 @@ public function match( Collection $models, Collection $results ): Collection { $dictionary = $this->build_dictionary( $results, $models ); return $models->each( - function( $model ) use ( $dictionary ): void { + function ( $model ) use ( $dictionary ): void { $key = $model->meta->{$this->local_key}; $model->set_relation( $this->relationship, $dictionary[ $key ][0] ?? null ); @@ -352,7 +352,7 @@ function( $model ) use ( $dictionary ): void { protected function build_dictionary( Collection $results, Collection $models ): array { return $results ->map_to_dictionary( - fn ( $result) => [ (string) $result[ $this->foreign_key ] => $result ] + fn ( $result ) => [ (string) $result[ $this->foreign_key ] => $result ] ) ->all(); } diff --git a/src/mantle/database/model/relations/class-has-many.php b/src/mantle/database/model/relations/class-has-many.php index c58ffd867..0b9c087ff 100644 --- a/src/mantle/database/model/relations/class-has-many.php +++ b/src/mantle/database/model/relations/class-has-many.php @@ -34,7 +34,7 @@ public function match( Collection $models, Collection $results ): Collection { $dictionary = $this->build_dictionary( $results, $models ); return $models->each( - function( $model ) use ( $dictionary ): void { + function ( $model ) use ( $dictionary ): void { $key = $model[ $this->local_key ]; $model->set_relation( $this->relationship, $dictionary[ $key ] ?? null ); } diff --git a/src/mantle/database/model/relations/class-has-one-or-many.php b/src/mantle/database/model/relations/class-has-one-or-many.php index 04cf38937..dc4214203 100644 --- a/src/mantle/database/model/relations/class-has-one-or-many.php +++ b/src/mantle/database/model/relations/class-has-one-or-many.php @@ -173,15 +173,11 @@ public function save( array|Model $model ): Model { if ( $model instanceof Post ) { $model->set_terms( $this->parent, $this->parent::get_object_name(), $append ); } - } else { + } elseif ( $this->uses_terms && $model instanceof Core_Object ) { // Set meta or use a hidden taxonomy if using terms. - if ( $this->uses_terms && $model instanceof Core_Object ) { - wp_set_object_terms( $model->id(), [ $this->get_term_for_relationship() ], static::RELATION_TAXONOMY, $append ); - } else { - if ( $model instanceof Model_Meta ) { - $model->set_meta( $this->foreign_key, $this->parent->get( $this->local_key ) ); - } - } + wp_set_object_terms( $model->id(), [ $this->get_term_for_relationship() ], static::RELATION_TAXONOMY, $append ); + } elseif ( $model instanceof Model_Meta ) { + $model->set_meta( $this->foreign_key, $this->parent->get( $this->local_key ) ); } if ( $this->relationship ) { diff --git a/src/mantle/database/model/relations/class-has-one.php b/src/mantle/database/model/relations/class-has-one.php index 75934a0a7..b19ab5396 100644 --- a/src/mantle/database/model/relations/class-has-one.php +++ b/src/mantle/database/model/relations/class-has-one.php @@ -34,7 +34,7 @@ public function match( Collection $models, Collection $results ): Collection { $dictionary = $this->build_dictionary( $results, $models ); return $models->each( - function( $model ) use ( $dictionary ): void { + function ( $model ) use ( $dictionary ): void { $key = $model[ $this->local_key ]; $model->set_relation( $this->relationship, $dictionary[ $key ][0] ?? null ); } diff --git a/src/mantle/database/model/relations/class-relation.php b/src/mantle/database/model/relations/class-relation.php index 1ca839fad..c0c40cd64 100644 --- a/src/mantle/database/model/relations/class-relation.php +++ b/src/mantle/database/model/relations/class-relation.php @@ -185,7 +185,7 @@ public function uses_terms( bool $uses = true ) { /** * Guess the name of the relationship. */ - protected function guess_relationship() : ?string { + protected function guess_relationship(): ?string { $trace = debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS, 5 ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_debug_backtrace foreach ( $trace as $item ) { diff --git a/src/mantle/database/query/class-builder.php b/src/mantle/database/query/class-builder.php index bf5930bff..a37a55bc1 100644 --- a/src/mantle/database/query/class-builder.php +++ b/src/mantle/database/query/class-builder.php @@ -33,9 +33,9 @@ * @template TModel of \Mantle\Database\Model\Model */ abstract class Builder { - use Conditionable, - Query_Bindings, - Query_Clauses; + use Conditionable; + use Query_Bindings; + use Query_Clauses; /** * Result limit per-page. @@ -522,7 +522,7 @@ protected function call_scope( callable $scope, array $parameters = [] ) { */ protected function call_named_scope( string $scope, array $parameters = [] ) { return $this->call_scope( - fn ( ...$parameters) => $this->get_model_instance()->call_named_scope( $scope, $parameters ), + fn ( ...$parameters ) => $this->get_model_instance()->call_named_scope( $scope, $parameters ), $parameters ); } @@ -540,7 +540,7 @@ protected function apply_scopes() { foreach ( $this->scopes as $scope ) { $this->call_scope( - function( self $builder ) use ( $scope ) { + function ( self $builder ) use ( $scope ) { if ( $scope instanceof Closure ) { return $scope( $builder ); } @@ -642,7 +642,7 @@ public function firstOrFail() { $model = $this->first(); if ( ! $model ) { - throw ( new Model_Not_Found_Exception() )->set_model( $this->model ); + throw new Model_Not_Found_Exception( $this->model ); } return $model; diff --git a/src/mantle/database/query/class-collection.php b/src/mantle/database/query/class-collection.php index 6374e4c11..12f257fe8 100644 --- a/src/mantle/database/query/class-collection.php +++ b/src/mantle/database/query/class-collection.php @@ -2,7 +2,7 @@ /** * Collection class file * - * phpcs:disable Generic.Functions.OpeningFunctionBraceKernighanRitchie.ContentAfterBrace + * phpcs:disable Squiz.Functions.MultiLineFunctionDeclaration.ContentAfterBrace * * @package Mantle */ diff --git a/src/mantle/database/query/class-post-query-builder.php b/src/mantle/database/query/class-post-query-builder.php index 51580df3c..2fd99c781 100644 --- a/src/mantle/database/query/class-post-query-builder.php +++ b/src/mantle/database/query/class-post-query-builder.php @@ -32,7 +32,8 @@ * @method \Mantle\Database\Query\Post_Query_Builder whereType( string $type ) */ class Post_Query_Builder extends Builder { - use Queries_Dates, Queries_Relationships; + use Queries_Dates; + use Queries_Relationships; /** * Query Variable Aliases diff --git a/src/mantle/database/query/concerns/trait-queries-dates.php b/src/mantle/database/query/concerns/trait-queries-dates.php index 49c05f53d..23cd88680 100644 --- a/src/mantle/database/query/concerns/trait-queries-dates.php +++ b/src/mantle/database/query/concerns/trait-queries-dates.php @@ -53,9 +53,9 @@ trait Queries_Dates { * @param string $compare Comparison operator, defaults to '='. * @param string $column Column to compare against, defaults to 'post_date'. */ - public function whereDate( DateTimeInterface|int|string $date, string $compare = '=', string $column = 'post_date' ): static { + public function whereDate( DateTimeInterface|int|string $date, string $compare = '=', string $column = 'post_date' ): static { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed if ( ! in_array( $compare, $this->date_operators, true ) ) { - throw new InvalidArgumentException( 'Invalid date comparison operator: ' . $compare ); + throw new InvalidArgumentException( esc_html( 'Invalid date comparison operator: ' . $compare ) ); } $this->date_constraints[] = compact( 'date', 'compare', 'column' ); diff --git a/src/mantle/database/query/concerns/trait-query-bindings.php b/src/mantle/database/query/concerns/trait-query-bindings.php index fadb1160f..d36fe50f5 100644 --- a/src/mantle/database/query/concerns/trait-query-bindings.php +++ b/src/mantle/database/query/concerns/trait-query-bindings.php @@ -185,7 +185,7 @@ protected function get_where_clause( string $table, array $binding ): string { $value = $binding['value']; if ( ! in_array( $operator, $this->operators, true ) ) { - throw new InvalidArgumentException( "Invalid operator for raw query binding: {$operator}" ); + throw new InvalidArgumentException( esc_html( "Invalid operator for raw query binding: {$operator}" ) ); } // Handle an array of values, commonly used with IN/NOT IN. diff --git a/src/mantle/database/query/trait-queries-relationships.php b/src/mantle/database/query/trait-queries-relationships.php index 18017abec..31d3d6800 100644 --- a/src/mantle/database/query/trait-queries-relationships.php +++ b/src/mantle/database/query/trait-queries-relationships.php @@ -94,11 +94,11 @@ protected function eager_load_relations( Collection $models ): Collection { * @param string $name Relation name to eager load. * @return Collection */ - protected function eager_load_relation( Collection $models, string $name ) : Collection { + protected function eager_load_relation( Collection $models, string $name ): Collection { $relation = $this->get_relation( $name ); $results = Relation::no_constraints( - function() use ( $models, $relation ) { + function () use ( $models, $relation ) { // Add the eager constraints from the relation to the query. $relation->add_eager_constraints( $models ); diff --git a/src/mantle/events/class-dispatcher.php b/src/mantle/events/class-dispatcher.php index a299d6393..54a2e9e5d 100644 --- a/src/mantle/events/class-dispatcher.php +++ b/src/mantle/events/class-dispatcher.php @@ -179,7 +179,7 @@ public function make_listener( $listener ): Closure { return $this->create_class_listener( $listener ); } - return fn ( ...$payload) => $this->create_action_callback( + return fn ( ...$payload ) => $this->create_action_callback( $listener, )( ...array_values( $payload ) ); } diff --git a/src/mantle/events/trait-wordpress-action.php b/src/mantle/events/trait-wordpress-action.php index f6237560d..316cc3aa3 100644 --- a/src/mantle/events/trait-wordpress-action.php +++ b/src/mantle/events/trait-wordpress-action.php @@ -72,7 +72,7 @@ public function filter( string $action, callable $callback, int $priority = 10 ) * @param callable $callback */ protected function create_action_callback( callable $callback ): Closure { - return function( ...$args ) use ( $callback ) { + return function ( ...$args ) use ( $callback ) { if ( is_array( $callback ) ) { try { $class = new ReflectionClass( $callback[0] ); @@ -140,7 +140,7 @@ protected function validate_argument_type( $argument, ReflectionParameter $param $class_name = Reflector::get_parameter_class_name( $parameter ); if ( $class_name - && ( is_object( $argument ) && $argument::class === $class_name || is_subclass_of( $argument, $class_name ) ) + && ( is_object( $argument ) && ( $argument::class === $class_name || is_subclass_of( $argument, $class_name ) ) ) // @phpstan-ignore-line always true ) { return $argument; } diff --git a/src/mantle/filesystem/class-filesystem-adapter.php b/src/mantle/filesystem/class-filesystem-adapter.php index 83ad22ee8..f23cde004 100644 --- a/src/mantle/filesystem/class-filesystem-adapter.php +++ b/src/mantle/filesystem/class-filesystem-adapter.php @@ -436,7 +436,7 @@ public function put_file( string $path, $file, $options = [] ): string|bool { * @return string|false */ public function put_file_as( string $path, $file, string $name, $options = [] ): string|bool { - $stream = fopen( is_string( $file ) ? $file : $file->getRealPath(), 'r' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fopen + $stream = fopen( is_string( $file ) ? $file : $file->getRealPath(), 'r' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen $path = trim( $path . '/' . $name, '/' ); // Next, we will format the path of the file and store the file using a stream since diff --git a/src/mantle/filesystem/class-filesystem.php b/src/mantle/filesystem/class-filesystem.php index 5bd999f0a..aecdd01ad 100644 --- a/src/mantle/filesystem/class-filesystem.php +++ b/src/mantle/filesystem/class-filesystem.php @@ -68,14 +68,14 @@ public function get( string $path, bool $lock = false ): string { public function shared_get( $path ) { $contents = ''; - $handle = fopen( $path, 'rb' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fopen + $handle = fopen( $path, 'rb' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fopen if ( $handle ) { try { if ( flock( $handle, LOCK_SH ) ) { clearstatcache( true, $path ); - $contents = fread( $handle, $this->size( $path ) ?: 1 ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_fread + $contents = fread( $handle, $this->size( $path ) ?: 1 ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_fread flock( $handle, LOCK_UN ); } @@ -102,9 +102,9 @@ public function get_require( $path, array $data = [] ) { $__data = $data; return ( static function () use ( $__path, $__data ) { - extract( $__data, EXTR_SKIP ); + extract( $__data, EXTR_SKIP ); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract, WordPress.PHP.DiscouragedPHPFunctions.extract_extract - return require $__path; + return require $__path; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable } )(); } @@ -126,9 +126,9 @@ public function require_once( $path, array $data = [] ) { $__data = $data; return ( static function () use ( $__path, $__data ) { - extract( $__data, EXTR_SKIP ); + extract( $__data, EXTR_SKIP ); // phpcs:ignore WordPress.PHP.DontExtract.extract_extract, WordPress.PHP.DiscouragedPHPFunctions.extract_extract - return require_once $__path; + return require_once $__path; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable } )(); } @@ -233,7 +233,7 @@ public function delete( $paths ) { foreach ( $paths as $path ) { try { - if ( ! @unlink( $path ) ) { // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged + if ( ! @unlink( $path ) ) { // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, Generic.PHP.NoSilencedErrors.Forbidden $success = false; } } catch ( ErrorException ) { @@ -524,7 +524,7 @@ public function move_directory( $from, $to, $overwrite = false ): bool { return false; } - return @rename( $from, $to ) === true; // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged + return @rename( $from, $to ) === true; // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, Generic.PHP.NoSilencedErrors.Forbidden } /** @@ -560,14 +560,11 @@ public function copy_directory( $directory, $destination, $options = null ): boo if ( ! $this->copy_directory( $path, $target, $options ) ) { return false; } - } else { - + } elseif ( ! $this->copy( $item->getPathname(), $target ) ) { // If the current items is just a regular file, we will just copy this to the new // location and keep looping. If for some reason the copy fails we'll bail out // and return false, so the developer is aware that the copy process failed. - if ( ! $this->copy( $item->getPathname(), $target ) ) { - return false; - } + return false; } } @@ -605,7 +602,7 @@ public function delete_directory( $directory, $preserve = false ): bool { } if ( ! $preserve ) { - @rmdir( $directory ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged + @rmdir( $directory ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, Generic.PHP.NoSilencedErrors.Forbidden } return true; diff --git a/src/mantle/framework/console/class-config-cache-command.php b/src/mantle/framework/console/class-config-cache-command.php index 48d825429..3239bcdad 100644 --- a/src/mantle/framework/console/class-config-cache-command.php +++ b/src/mantle/framework/console/class-config-cache-command.php @@ -60,7 +60,7 @@ public function handle( Filesystem $filesystem ): void { ); try { - require $path; + require $path; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable } catch ( Throwable $e ) { $this->files->delete( $path ); @@ -75,8 +75,8 @@ public function handle( Filesystem $filesystem ): void { /** * Boot a fresh copy of the application configuration. */ - protected function get_fresh_configuration() : array { - $app = require $this->container->get_bootstrap_path( '/app.php' ); + protected function get_fresh_configuration(): array { + $app = require $this->container->get_bootstrap_path( '/app.php' ); // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable $app->set_base_path( $this->container->get_base_path() ); $app->make( Kernel::class )->bootstrap(); diff --git a/src/mantle/framework/console/class-hook-usage-command.php b/src/mantle/framework/console/class-hook-usage-command.php index 737710760..3d7dd02e7 100644 --- a/src/mantle/framework/console/class-hook-usage-command.php +++ b/src/mantle/framework/console/class-hook-usage-command.php @@ -144,7 +144,7 @@ protected function read_path( string $path ): Collection { $dir = new RecursiveDirectoryIterator( $path ); $files = new RecursiveCallbackFilterIterator( $dir, - function( \SplFileInfo $current, $key, RecursiveDirectoryIterator $iterator ) use ( $paths_to_ignore ): bool { + function ( \SplFileInfo $current, $key, RecursiveDirectoryIterator $iterator ) use ( $paths_to_ignore ): bool { if ( Str::is( $paths_to_ignore, $current->getRealPath() ) ) { return false; } @@ -237,11 +237,12 @@ protected function get_cache_for_path( string $path ): ?Collection { // Check if the file is stale (older than today). if ( filemtime( $file ) < ( time() - DAY_IN_SECONDS ) ) { // Delete the cached file if it is stale. - @unlink( $file ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_unlink + @unlink( $file ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_unlink, Generic.PHP.NoSilencedErrors.Forbidden return null; } - $files = require_once $file; + $files = require_once $file; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable + return collect( $files ); } diff --git a/src/mantle/framework/console/class-route-list-command.php b/src/mantle/framework/console/class-route-list-command.php index 17fd5ecb5..a9aba50e2 100644 --- a/src/mantle/framework/console/class-route-list-command.php +++ b/src/mantle/framework/console/class-route-list-command.php @@ -77,7 +77,7 @@ protected function collect_routes(): Collection { return collect( $routes ) ->map( - fn ( Route $route, string $name) => [ + fn ( Route $route, string $name ) => [ implode( '|', $route->getMethods() ), $route->getPath(), $name, diff --git a/src/mantle/framework/events/class-events-manifest.php b/src/mantle/framework/events/class-events-manifest.php index d2c148ea1..143951060 100644 --- a/src/mantle/framework/events/class-events-manifest.php +++ b/src/mantle/framework/events/class-events-manifest.php @@ -80,7 +80,7 @@ protected function get_manifest(): array { return (array) $this->manifest; } - $this->manifest = include $this->manifest_path; + $this->manifest = include $this->manifest_path; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable return (array) $this->manifest; } diff --git a/src/mantle/framework/exceptions/class-handler.php b/src/mantle/framework/exceptions/class-handler.php index 23a673765..a13ee5cec 100644 --- a/src/mantle/framework/exceptions/class-handler.php +++ b/src/mantle/framework/exceptions/class-handler.php @@ -323,7 +323,7 @@ protected function get_http_exception_view( Throwable $e ): array { * @param Request $request * @param Throwable|HttpException $e */ - protected function prepare_json_response( $request, Throwable | HttpException $e ): JsonResponse { + protected function prepare_json_response( $request, Throwable|HttpException $e ): JsonResponse { return new JsonResponse( $this->convert_exception_to_array( $e ), $e instanceof HttpException ? $e->getStatusCode() : 500, @@ -343,7 +343,7 @@ protected function convert_exception_to_array( Throwable $e ): array { 'file' => $e->getFile(), 'line' => $e->getLine(), 'trace' => collect( $e->getTrace() )->map( - fn ( $trace) => Arr::except( $trace, [ 'args' ] ) + fn ( $trace ) => Arr::except( $trace, [ 'args' ] ) )->all(), ] : [ 'message' => $e instanceof HttpException ? $e->getMessage() : __( 'Server Error', 'mantle' ), diff --git a/src/mantle/framework/manifest/class-model-manifest.php b/src/mantle/framework/manifest/class-model-manifest.php index 9a933d70b..032d784ea 100644 --- a/src/mantle/framework/manifest/class-model-manifest.php +++ b/src/mantle/framework/manifest/class-model-manifest.php @@ -64,7 +64,7 @@ protected function get_manifest(): array { return $this->manifest; } - $this->manifest = include $this->manifest_path; + $this->manifest = include $this->manifest_path; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable return (array) $this->manifest; } diff --git a/src/mantle/framework/manifest/class-package-manifest.php b/src/mantle/framework/manifest/class-package-manifest.php index b2f981537..4e6e857b1 100644 --- a/src/mantle/framework/manifest/class-package-manifest.php +++ b/src/mantle/framework/manifest/class-package-manifest.php @@ -85,7 +85,7 @@ public function aliases() { public function config( string $key ) { return collect( $this->get_manifest() ) ->flat_map( - fn ( $configuration) => (array) ( $configuration[ $key ] ?? [] ) + fn ( $configuration ) => (array) ( $configuration[ $key ] ?? [] ) ) ->filter() ->all(); @@ -106,7 +106,7 @@ public function get_manifest(): array { return (array) $this->manifest; } - $this->manifest = include $this->manifest_path; + $this->manifest = include $this->manifest_path; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable return (array) $this->manifest; } @@ -143,7 +143,7 @@ public function build(): void { */ $installed = collect( $installed ) ->map_with_keys( - fn ( $package) => [ + fn ( $package ) => [ $this->format( $package['name'] ) => $package['extra']['mantle'] ?? [], ] ) diff --git a/src/mantle/framework/providers/class-event-service-provider.php b/src/mantle/framework/providers/class-event-service-provider.php index d79db5456..bcb49c248 100644 --- a/src/mantle/framework/providers/class-event-service-provider.php +++ b/src/mantle/framework/providers/class-event-service-provider.php @@ -40,7 +40,7 @@ public function register(): void { ); $this->app->booting( - function(): void { + function (): void { $events = $this->get_events(); foreach ( $events as $event => $listeners ) { foreach ( $listeners as $listener ) { diff --git a/src/mantle/framework/providers/class-routing-service-provider.php b/src/mantle/framework/providers/class-routing-service-provider.php index 05f0909e7..7a4cb43ae 100644 --- a/src/mantle/framework/providers/class-routing-service-provider.php +++ b/src/mantle/framework/providers/class-routing-service-provider.php @@ -63,7 +63,7 @@ protected function register_router() { protected function register_url_generator() { $this->app->singleton( 'url', - function( $app ) { + function ( $app ) { $routes = $app['router']->get_routes(); $routes = $app->instance( 'routes', $routes ); @@ -83,7 +83,7 @@ function( $app ) { protected function register_redirector() { $this->app->singleton( 'redirect', - fn ( $app) => new Redirector( $app['url'] ) + fn ( $app ) => new Redirector( $app['url'] ) ); } @@ -93,7 +93,7 @@ protected function register_redirector() { protected function register_response_factory() { $this->app->singleton( Response_Factory_Contract::class, - fn ( $app) => new Response_Factory( $app['redirect'], $app['view'] ) + fn ( $app ) => new Response_Factory( $app['redirect'], $app['view'] ) ); } } diff --git a/src/mantle/framework/resources/application-structure/providers/class-asset-service-provider.php b/src/mantle/framework/resources/application-structure/providers/class-asset-service-provider.php index 19b257892..e74760a29 100644 --- a/src/mantle/framework/resources/application-structure/providers/class-asset-service-provider.php +++ b/src/mantle/framework/resources/application-structure/providers/class-asset-service-provider.php @@ -43,12 +43,12 @@ public function boot(): void { | | Enqueue a raw asset using the asset() helper: | - | asset()->script( 'example-entry' )->async()->src( asset_loader( '/app.js' ) ); - | asset()->style( 'example-entry' )->condition( 'single' )->src( asset_loader( '/app.css' ) ); + | asset()->script( 'example-entry' )->async()->src( asset_loader( '/app.js' ) ); + | asset()->style( 'example-entry' )->condition( 'single' )->src( asset_loader( '/app.css' ) ); | | Enqueue an asset with dependencies from @wordpress/dependency-extraction-webpack-plugin: | - | asset()->script( 'example-block' )->src( asset_loader( '/example-block.js' ) )->dependencies( asset_loader()->dependencies( '/example-block.js' ) ); + | asset()->script( 'example-block' )->src( asset_loader( '/example-block.js' ) )->dependencies( asset_loader()->dependencies( '/example-block.js' ) ); | | Get cookin'! | diff --git a/src/mantle/http-client/class-pending-request.php b/src/mantle/http-client/class-pending-request.php index cebbbb92f..e655f1100 100644 --- a/src/mantle/http-client/class-pending-request.php +++ b/src/mantle/http-client/class-pending-request.php @@ -18,7 +18,8 @@ * Pending Request to be made with the Http Client. */ class Pending_Request { - use Conditionable, Macroable; + use Conditionable; + use Macroable; /** * Base URL for the request. @@ -578,7 +579,7 @@ public function send( string $method, string $url, array $options = [] ) { return retry( $this->options['retry'], - function( int $attempts ) { + function ( int $attempts ) { $response = ( new Pipeline() ) ->send( $this ) ->through( $this->middleware ) diff --git a/src/mantle/http/class-request.php b/src/mantle/http/class-request.php index 8d9330a54..314ca204f 100644 --- a/src/mantle/http/class-request.php +++ b/src/mantle/http/class-request.php @@ -23,8 +23,8 @@ * Request Object */ class Request extends SymfonyRequest implements ArrayAccess, Arrayable { - use Interacts_With_Input, - Concerns\Interacts_With_Content_Types; + use Interacts_With_Input; + use Concerns\Interacts_With_Content_Types; /** * Route parameters. @@ -175,7 +175,7 @@ public function segments() { return array_values( array_filter( $segments, - fn ( $value) => '' !== $value + fn ( $value ) => '' !== $value ) ); } @@ -227,7 +227,7 @@ public function ajax() { * Determine if the request is the result of an PJAX call. */ public function pjax(): bool { - return $this->headers->get( 'X-PJAX' ) == true; + return (bool) $this->headers->get( 'X-PJAX' ); } /** @@ -347,7 +347,7 @@ protected function get_input_source() { return $this->json(); } - return in_array( $this->getRealMethod(), [ 'GET', 'HEAD' ] ) ? $this->query : $this->request; + return in_array( $this->getRealMethod(), [ 'GET', 'HEAD' ], true ) ? $this->query : $this->request; } /** @@ -497,5 +497,4 @@ public function __get( $key ) { fn () => $this->get_route_parameters()->get( $key ) ); } - } diff --git a/src/mantle/http/class-uploaded-file.php b/src/mantle/http/class-uploaded-file.php index b1d7f0b7e..6354e6e08 100644 --- a/src/mantle/http/class-uploaded-file.php +++ b/src/mantle/http/class-uploaded-file.php @@ -24,7 +24,8 @@ * Handles Uploaded Files */ class Uploaded_File extends SymfonyUploadedFile { - use File_Helpers, Macroable; + use File_Helpers; + use Macroable; /** * Store the uploaded file on a filesystem disk. diff --git a/src/mantle/http/concerns/trait-interacts-with-content-types.php b/src/mantle/http/concerns/trait-interacts-with-content-types.php index bd40a1a59..7aefc7df8 100644 --- a/src/mantle/http/concerns/trait-interacts-with-content-types.php +++ b/src/mantle/http/concerns/trait-interacts-with-content-types.php @@ -106,7 +106,7 @@ public function prefers( $content_types ) { $content_types = (array) $content_types; foreach ( $accepts as $accept ) { - if ( in_array( $accept, [ '*/*', '*' ] ) ) { + if ( in_array( $accept, [ '*/*', '*' ], true ) ) { return $content_types[0]; } diff --git a/src/mantle/http/routing/class-entity-router.php b/src/mantle/http/routing/class-entity-router.php index 57e44a6d2..138bb8d65 100644 --- a/src/mantle/http/routing/class-entity-router.php +++ b/src/mantle/http/routing/class-entity-router.php @@ -68,7 +68,7 @@ public function add( Router_Contract $router, string $entity, string $controller throw new InvalidArgumentException( "Unknown entity type: [{$entity}]" ); } - if ( ! in_array( Url_Routable::class, class_implements( $entity ) ) ) { + if ( ! in_array( Url_Routable::class, class_implements( $entity ), true ) ) { throw new InvalidArgumentException( "Unroutable entity: [{$entity}]" ); } diff --git a/src/mantle/http/routing/class-implicit-route-binding.php b/src/mantle/http/routing/class-implicit-route-binding.php index 26889a920..5969a9066 100644 --- a/src/mantle/http/routing/class-implicit-route-binding.php +++ b/src/mantle/http/routing/class-implicit-route-binding.php @@ -49,7 +49,7 @@ public static function resolve_for_route( Container $container, Request $request $model = $instance->resolve_route_binding( $parameter_value ); if ( ! $model ) { - throw ( new Model_Not_Found_Exception() )->set_model( $instance::class, [ $parameter_value ] ); + throw new Model_Not_Found_Exception( $instance::class, [ $parameter_value ] ); } $request->set_route_parameter( $parameter_name, $model ); diff --git a/src/mantle/http/routing/class-rest-route-registrar.php b/src/mantle/http/routing/class-rest-route-registrar.php index 4e536a26f..f90644ea8 100644 --- a/src/mantle/http/routing/class-rest-route-registrar.php +++ b/src/mantle/http/routing/class-rest-route-registrar.php @@ -105,7 +105,7 @@ protected function normalize_args( $args, string $route ): array { protected function wrap_callback( mixed $callback, string $route ): callable { $callback = $this->parse_route_action( $callback, $route ); - return function( WP_REST_Request $request ) use ( $callback, $route ) { + return function ( WP_REST_Request $request ) use ( $callback, $route ) { $middleware = $request->get_attributes()['middleware'] ?? []; if ( empty( $middleware ) ) { @@ -143,7 +143,7 @@ protected function wrap_callback( mixed $callback, string $route ): callable { public function gather_route_middleware( array $middleware ): array { return collect( $middleware ) ->map( - fn ( $name) => (array) Middleware_Name_Resolver::resolve( + fn ( $name ) => (array) Middleware_Name_Resolver::resolve( $name, $this->router->get_middleware(), $this->router->get_middleware_groups() @@ -174,7 +174,7 @@ public function register_routes(): void { * was already fired. */ protected function should_register_now(): bool { - return function_exists( 'did_action' ) && ! ! did_action( 'rest_api_init' ); + return function_exists( 'did_action' ) && (bool) did_action( 'rest_api_init' ); } /** diff --git a/src/mantle/http/routing/class-route-binding.php b/src/mantle/http/routing/class-route-binding.php index 1555a6af8..bea153f71 100644 --- a/src/mantle/http/routing/class-route-binding.php +++ b/src/mantle/http/routing/class-route-binding.php @@ -84,7 +84,7 @@ public static function for_model( Container $container, $class, $callback = null return $callback( $value ); } - throw ( new Model_Not_Found_Exception() )->set_model( $class ); + throw new Model_Not_Found_Exception( $class, [ $value ] ); }; } } diff --git a/src/mantle/http/routing/class-route-file-registrar.php b/src/mantle/http/routing/class-route-file-registrar.php index 1b43029bc..8b70b7752 100644 --- a/src/mantle/http/routing/class-route-file-registrar.php +++ b/src/mantle/http/routing/class-route-file-registrar.php @@ -33,8 +33,8 @@ public function __construct( Router $router ) { * * @param string $routes Routes to register. */ - public function register( $routes ): void { + public function register( string $routes ): void { $router = $this->router; - require $routes; + require $routes; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable } } diff --git a/src/mantle/http/routing/class-route-registrar.php b/src/mantle/http/routing/class-route-registrar.php index 29ebbdf06..1fc6790b1 100644 --- a/src/mantle/http/routing/class-route-registrar.php +++ b/src/mantle/http/routing/class-route-registrar.php @@ -90,7 +90,7 @@ public function __construct( protected ?Router $router ) { * @throws InvalidArgumentException Thrown on unknown attribute. */ public function attribute( $key, $value ) { - if ( ! in_array( $key, $this->allowed_attributes ) ) { + if ( ! in_array( $key, $this->allowed_attributes, true ) ) { throw new InvalidArgumentException( "Attribute [{$key}] does not exist." ); } @@ -175,11 +175,11 @@ public function rest_api( string $namespace, $route, $args = [] ): Rest_Route_Re * @throws BadMethodCallException Thrown on missing method. */ public function __call( $method, $parameters ) { - if ( in_array( $method, $this->passthru ) ) { + if ( in_array( $method, $this->passthru, true ) ) { return $this->register_route( $method, ...$parameters ); } - if ( in_array( $method, $this->allowed_attributes ) ) { + if ( in_array( $method, $this->allowed_attributes, true ) ) { if ( 'middleware' === $method ) { return $this->attribute( $method, is_array( $parameters[0] ) ? $parameters[0] : $parameters ); } diff --git a/src/mantle/http/routing/class-router.php b/src/mantle/http/routing/class-router.php index ff284492a..ba18b3f7a 100644 --- a/src/mantle/http/routing/class-router.php +++ b/src/mantle/http/routing/class-router.php @@ -168,7 +168,7 @@ public function any( string $uri, $action = '' ): ?Route { * @param \Closure|string $routes * @return void */ - protected function load_routes( $routes ) { + protected function load_routes( \Closure|string $routes ) { if ( $routes instanceof \Closure ) { $routes( $this ); } else { @@ -315,7 +315,7 @@ protected function execute_route_match( $match, Request $request ): ?Symfony_Res ->send( $this->container['request'] ) ->through( $middleware ) ->then( - function( Request $request ) use ( $route ) { + function ( Request $request ) use ( $route ) { // Refresh the request object in the container with modifications from the middleware. $this->container['request'] = $request; @@ -391,7 +391,7 @@ public function middleware_group( string $name, array $middleware ): static { * @return static */ public function prepend_middleware_to_group( $group, $middleware ) { - if ( isset( $this->middleware_groups[ $group ] ) && ! in_array( $middleware, $this->middleware_groups[ $group ] ) ) { + if ( isset( $this->middleware_groups[ $group ] ) && ! in_array( $middleware, $this->middleware_groups[ $group ], true ) ) { array_unshift( $this->middleware_groups[ $group ], $middleware ); } @@ -412,7 +412,7 @@ public function push_middleware_to_group( $group, $middleware ) { $this->middleware_groups[ $group ] = []; } - if ( ! in_array( $middleware, $this->middleware_groups[ $group ] ) ) { + if ( ! in_array( $middleware, $this->middleware_groups[ $group ], true ) ) { $this->middleware_groups[ $group ][] = $middleware; } diff --git a/src/mantle/http/view/class-factory.php b/src/mantle/http/view/class-factory.php index ca4ff547d..bf27ffebc 100644 --- a/src/mantle/http/view/class-factory.php +++ b/src/mantle/http/view/class-factory.php @@ -24,9 +24,9 @@ * View Factory */ class Factory implements ViewFactory { - use ManagesLayouts, - ManagesLoops, - ManagesStacks; + use ManagesLayouts; + use ManagesLoops; + use ManagesStacks; /** * The IoC container instance. @@ -331,7 +331,6 @@ public function get_engine_from_path( string $path ) { } return $this->engines->resolve( $this->extensions[ $extension ] ); - } /** @@ -344,7 +343,7 @@ protected function get_extension( string $path ): ?string { return Arr::first( $extensions, - fn ( $value) => Str::ends_with( $path, '.' . $value ) + fn ( $value ) => Str::ends_with( $path, '.' . $value ) ); } } diff --git a/src/mantle/http/view/class-view-finder.php b/src/mantle/http/view/class-view-finder.php index c552df973..d3ea05787 100644 --- a/src/mantle/http/view/class-view-finder.php +++ b/src/mantle/http/view/class-view-finder.php @@ -67,7 +67,8 @@ public function __construct( string $base_path ) { * @return static */ public function add_extension( $extension ) { - $index = array_search( $extension, $this->extensions ); + $index = array_search( $extension, $this->extensions, true ); + if ( false !== $index ) { unset( $this->extensions[ $index ] ); } @@ -214,7 +215,7 @@ public function locate_template( array $templates, string $alias = null ): strin if ( $alias ) { $paths = array_filter( $paths, - fn ( $path_alias) => $alias === $path_alias, + fn ( $path_alias ) => $alias === $path_alias, ARRAY_FILTER_USE_KEY ); } @@ -244,7 +245,7 @@ public function locate_template( array $templates, string $alias = null ): strin */ public function get_possible_view_files( string $name ): array { return array_map( - fn ( $extension) => "{$name}.{$extension}", + fn ( $extension ) => "{$name}.{$extension}", $this->extensions ); } diff --git a/src/mantle/http/view/class-view.php b/src/mantle/http/view/class-view.php index cfbafa877..407de13f7 100644 --- a/src/mantle/http/view/class-view.php +++ b/src/mantle/http/view/class-view.php @@ -144,7 +144,7 @@ public function get_cache_key(): string { } $filtered_data = array_map( - function( $value, $key ) { + function ( $value, $key ) { // Internal class references do not serialize well. if ( '__env' === $key ) { return 'app'; diff --git a/src/mantle/log/class-log-manager.php b/src/mantle/log/class-log-manager.php index 0a27c1627..fee3286aa 100644 --- a/src/mantle/log/class-log-manager.php +++ b/src/mantle/log/class-log-manager.php @@ -216,7 +216,7 @@ public function driver(): Logger { * @phpstan-return Level * @throws \InvalidArgumentException Thrown for unknown log. */ - protected function level( array $config ):int { + protected function level( array $config ): int { $level = strtoupper( $config['level'] ?? 'debug' ); $levels = Logger::getLevels(); @@ -336,7 +336,6 @@ public function debug( $message, array $context = [] ): void { * @param string $message Log message. * @param mixed[] $context Log context. * - * * @throws \Psr\Log\InvalidArgumentException Thrown on invalid arguments. */ public function log( $level, $message, array $context = [] ): void { diff --git a/src/mantle/log/class-log-service-provider.php b/src/mantle/log/class-log-service-provider.php index ae9aca618..cf0cf7c9e 100644 --- a/src/mantle/log/class-log-service-provider.php +++ b/src/mantle/log/class-log-service-provider.php @@ -19,7 +19,7 @@ class Log_Service_Provider extends Service_Provider { public function register(): void { $this->app->singleton( 'log', - fn ( $app) => new Log_Manager( $app, $app['events'] ) + fn ( $app ) => new Log_Manager( $app, $app['events'] ) ); } } diff --git a/src/mantle/query-monitor/collector/class-log-collector.php b/src/mantle/query-monitor/collector/class-log-collector.php index 673a853a7..6d0a4c819 100644 --- a/src/mantle/query-monitor/collector/class-log-collector.php +++ b/src/mantle/query-monitor/collector/class-log-collector.php @@ -39,7 +39,7 @@ public function __construct( Application $app ) { $this->app = $app; $this->app['log']->listen( - function( Message_Logged $event ): void { + function ( Message_Logged $event ): void { $trace = new \QM_Backtrace( [ 'ignore_frames' => 6, diff --git a/src/mantle/queue/console/class-run-command.php b/src/mantle/queue/console/class-run-command.php index 2c09155d2..9017a1517 100644 --- a/src/mantle/queue/console/class-run-command.php +++ b/src/mantle/queue/console/class-run-command.php @@ -47,28 +47,28 @@ public function handle(): void { // Register the event listeners to pipe the events back to the console. $this->container['events']->listen( Run_Start::class, - function( Run_Start $event ): void { + function ( Run_Start $event ): void { $this->log( 'Run started: ' . $event->queue ); } ); $this->container['events']->listen( Job_Processing::class, - function( Job_Processing $job ): void { + function ( Job_Processing $job ): void { $this->log( 'Queue item started: ' . $job->get_id() ); } ); $this->container['events']->listen( Job_Processed::class, - function( Job_Processed $job ): void { + function ( Job_Processed $job ): void { $this->log( 'Queue item complete: ' . $job->get_id() ); } ); $this->container['events']->listen( Run_Complete::class, - function( Run_Complete $event ): void { + function ( Run_Complete $event ): void { $this->log( 'Run complete: ' . $event->queue ); } ); diff --git a/src/mantle/queue/providers/wordpress/admin/class-service-provider.php b/src/mantle/queue/providers/wordpress/admin/class-service-provider.php index 07ac8ddcf..1b067fcbb 100644 --- a/src/mantle/queue/providers/wordpress/admin/class-service-provider.php +++ b/src/mantle/queue/providers/wordpress/admin/class-service-provider.php @@ -20,7 +20,6 @@ class Service_Provider extends Base_Service_Provider { * Register the service provider. */ public function register() { - } /** diff --git a/src/mantle/queue/providers/wordpress/class-provider.php b/src/mantle/queue/providers/wordpress/class-provider.php index 4e7e09d83..7286b9307 100644 --- a/src/mantle/queue/providers/wordpress/class-provider.php +++ b/src/mantle/queue/providers/wordpress/class-provider.php @@ -41,7 +41,7 @@ class Provider implements Provider_Contract { * Register the data types on 'init'. */ public static function register_data_types(): void { - \register_post_type( + \register_post_type( // phpcs:ignore WordPress.NamingConventions.ValidPostTypeSlug.NotStringLiteral static::OBJECT_NAME, [ 'public' => false, @@ -177,7 +177,7 @@ public function pop( string $queue = null, int $count = 1 ): Collection { fn ( Queue_Record $record ) => tap( new Queue_Worker_Job( $record ), // Lock the job until the configured timeout or 10 minutes. - fn ( Queue_Worker_Job $job ) => $record->set_lock_until( + fn ( Queue_Worker_Job $job ) => $record->set_lock_until( // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable $job->get_job()->timeout ?? 600 ), ), diff --git a/src/mantle/queue/providers/wordpress/class-scheduler.php b/src/mantle/queue/providers/wordpress/class-scheduler.php index 0dd56564d..3fa806f14 100644 --- a/src/mantle/queue/providers/wordpress/class-scheduler.php +++ b/src/mantle/queue/providers/wordpress/class-scheduler.php @@ -223,13 +223,13 @@ protected static function get_configuration_value( string $key, string $queue = $config = config(); // Check for a queue-specific configuration value. - if ( $queue && $config->has( "queue.wordpress.queues.{$queue}.{$key}" ) ) { - return $config->get( "queue.wordpress.queues.{$queue}.{$key}" ); + if ( $queue && $config->has( "queue.WordPress.queues.{$queue}.{$key}" ) ) { + return $config->get( "queue.WordPress.queues.{$queue}.{$key}" ); } // Check for a default configuration for the queue provider. - if ( $config->has( "queue.wordpress.{$key}" ) ) { - return $config->get( "queue.wordpress.{$key}" ); + if ( $config->has( "queue.WordPress.{$key}" ) ) { + return $config->get( "queue.WordPress.{$key}" ); } // Check for a default configuration for the queue configuration. diff --git a/src/mantle/scheduling/class-event.php b/src/mantle/scheduling/class-event.php index cfaadff1c..e9a4917d1 100644 --- a/src/mantle/scheduling/class-event.php +++ b/src/mantle/scheduling/class-event.php @@ -25,7 +25,8 @@ * Schedule-able Event */ class Event { - use Macroable, Manages_Frequencies; + use Macroable; + use Manages_Frequencies; /** * The cron expression representing the event's frequency. @@ -179,7 +180,7 @@ protected function expression_passes(): bool { * @param string $environment Environment to check against. */ public function runs_in_environment( $environment ): bool { - return empty( $this->environments ) || in_array( $environment, $this->environments ); + return empty( $this->environments ) || in_array( $environment, $this->environments, true ); } /** diff --git a/src/mantle/support/class-collection.php b/src/mantle/support/class-collection.php index 0483c7a4b..f59b158b2 100644 --- a/src/mantle/support/class-collection.php +++ b/src/mantle/support/class-collection.php @@ -2,25 +2,23 @@ /** * Collections class file. * + * phpcs:disable Squiz.Commenting.FunctionComment.MissingParamComment, Squiz.Commenting.FunctionComment.MissingParamTag + * * @package Mantle */ -// phpcs:disable Squiz.Commenting.FunctionComment.MissingParamComment - -// phpcs:disable Squiz.Commenting.FunctionComment.MissingParamTag - namespace Mantle\Support; use ArrayAccess; use ArrayIterator; use Mantle\Contracts\Support\Arrayable; -use Mantle\Support\Traits\Enumerates_Values; use Mantle\Database\Model; +use Mantle\Support\Traits\Enumerates_Values; +use stdClass; +use Traversable; use function Mantle\Support\Helpers\data_get; use function Mantle\Support\Helpers\value; -use stdClass; -use Traversable; /** * Collection @@ -144,7 +142,7 @@ public function avg( $callback = null ) { public function median( $key = null ) { $values = ( isset( $key ) ? $this->pluck( $key ) : $this ) ->filter( - fn ( $item) => ! is_null( $item ) + fn ( $item ) => ! is_null( $item ) )->sort()->values(); @@ -194,7 +192,7 @@ function ( $value ) use ( $counts ): void { $highest_value = $sorted->last(); return $sorted->filter( - fn ( $value) => $value == $highest_value + fn ( $value ) => $value == $highest_value // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison, Universal.Operators.StrictComparisons.LooseEqual )->sort()->keys()->all(); } @@ -223,7 +221,7 @@ public function contains( $key, $operator = null, $value = null ) { return $this->first( $key, $placeholder ) !== $placeholder; } - return in_array( $key, $this->items ); + return in_array( $key, $this->items ); // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict } return $this->contains( $this->operator_for_where( ...func_get_args() ) ); @@ -238,7 +236,7 @@ public function contains( $key, $operator = null, $value = null ) { */ public function contains_strict( $key, $value = null ) { if ( func_num_args() === 2 ) { - return $this->contains( fn ( $item) => data_get( $item, $key ) === $value ); + return $this->contains( fn ( $item ) => data_get( $item, $key ) === $value ); } if ( $this->use_as_callable( $key ) ) { @@ -386,10 +384,10 @@ public function duplicates_strict( $callback = null ) { */ protected function duplicate_comparator( $strict ) { if ( $strict ) { - return fn ( $a, $b) => $a === $b; + return fn ( $a, $b ) => $a == $b; // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison, Universal.Operators.StrictComparisons.LooseEqual } - return fn ( $a, $b) => $a == $b; + return fn ( $a, $b ) => $a === $b; } /** @@ -1057,7 +1055,7 @@ public function reverse() { */ public function search( $value, $strict = false ) { if ( ! $this->use_as_callable( $value ) ) { - return array_search( $value, $this->items, $strict ); + return array_search( $value, $this->items, $strict ); // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict } foreach ( $this->items as $key => $item ) { diff --git a/src/mantle/support/class-higher-order-collection-proxy.php b/src/mantle/support/class-higher-order-collection-proxy.php index baf660f7f..9f70fa968 100644 --- a/src/mantle/support/class-higher-order-collection-proxy.php +++ b/src/mantle/support/class-higher-order-collection-proxy.php @@ -41,7 +41,7 @@ public function __get( string $key ): mixed { */ public function __call( string $method, array $parameters ): mixed { return $this->collection->{ $this->method }( - fn ( $value) => $value->{ $method }( ...$parameters ) + fn ( $value ) => $value->{ $method }( ...$parameters ) ); } } diff --git a/src/mantle/support/class-pipeline.php b/src/mantle/support/class-pipeline.php index 20366a005..41bda0756 100644 --- a/src/mantle/support/class-pipeline.php +++ b/src/mantle/support/class-pipeline.php @@ -107,9 +107,7 @@ public function then( Closure $destination ) { * @return mixed */ public function thenReturn() { - return $this->then( - fn ( $passable) => $passable - ); + return $this->then( fn ( $passable ) => $passable ); } /** @@ -134,38 +132,38 @@ protected function prepare_destination( Closure $destination ) { * @return \Closure */ protected function carry() { - return fn ( $stack, $pipe) => function ( $passable ) use ( $stack, $pipe ) { - try { - if ( is_callable( $pipe ) ) { - // If the pipe is a callable, then we will call it directly, but otherwise we - // will resolve the pipes out of the dependency container and call it with - // the appropriate method and arguments, returning the results back out. - return $pipe( $passable, $stack ); - } elseif ( ! is_object( $pipe ) ) { - [$name, $parameters] = $this->parse_pipe_string( $pipe ); - - // If the pipe is a string we will parse the string and resolve the class out - // of the dependency injection container. We can then build a callable and - // execute the pipe function giving in the parameters that are required. - $pipe = $this->get_container()->make( $name ); - - $parameters = array_merge( [ $passable, $stack ], $parameters ); - } else { - // If the pipe is already an object we'll just make a callable and pass it to - // the pipe as-is. There is no need to do any extra parsing and formatting - // since the object we're given was already a fully instantiated object. - $parameters = [ $passable, $stack ]; - } - - $carry = method_exists( $pipe, $this->method ) - ? $pipe->{$this->method}( ...$parameters ) - : $pipe( ...$parameters ); - - return $this->handle_carry( $carry ); - } catch ( Throwable $e ) { - return $this->handle_exception( $passable, $e ); + return fn ( $stack, $pipe ) => function ( $passable ) use ( $stack, $pipe ) { + try { + if ( is_callable( $pipe ) ) { + // If the pipe is a callable, then we will call it directly, but otherwise we + // will resolve the pipes out of the dependency container and call it with + // the appropriate method and arguments, returning the results back out. + return $pipe( $passable, $stack ); + } elseif ( ! is_object( $pipe ) ) { + [ $name, $parameters] = $this->parse_pipe_string( $pipe ); + + // If the pipe is a string we will parse the string and resolve the class out + // of the dependency injection container. We can then build a callable and + // execute the pipe function giving in the parameters that are required. + $pipe = $this->get_container()->make( $name ); + + $parameters = array_merge( [ $passable, $stack ], $parameters ); + } else { + // If the pipe is already an object we'll just make a callable and pass it to + // the pipe as-is. There is no need to do any extra parsing and formatting + // since the object we're given was already a fully instantiated object. + $parameters = [ $passable, $stack ]; } - }; + + $carry = method_exists( $pipe, $this->method ) + ? $pipe->{$this->method}( ...$parameters ) + : $pipe( ...$parameters ); + + return $this->handle_carry( $carry ); + } catch ( Throwable $e ) { + return $this->handle_exception( $passable, $e ); + } + }; // phpcs:ignore Generic.CodeAnalysis.EmptyPHPStatement.SemicolonWithoutCodeDetected } /** diff --git a/src/mantle/support/class-pluralizer.php b/src/mantle/support/class-pluralizer.php index 3b630b075..b2eb64920 100755 --- a/src/mantle/support/class-pluralizer.php +++ b/src/mantle/support/class-pluralizer.php @@ -50,7 +50,7 @@ public static function plural( string $value, int|array|\Countable $count = 2 ): $count = count( $count ); } - if ( abs( $count ) === 1 || static::uncountable( $value ) || preg_match( '/^(.*)[A-Za-z0-9\x{0080}-\x{FFFF}]$/u', $value ) == 0 ) { + if ( abs( $count ) === 1 || static::uncountable( $value ) || preg_match( '/^(.*)[A-Za-z0-9\x{0080}-\x{FFFF}]$/u', $value ) === 0 ) { return $value; } @@ -77,7 +77,7 @@ public static function singular( string $value ): string { * @return bool */ protected static function uncountable( $value ) { - return in_array( strtolower( $value ), static::$uncountable ); + return in_array( strtolower( $value ), static::$uncountable, true ); } /** diff --git a/src/mantle/support/class-service-provider.php b/src/mantle/support/class-service-provider.php index 160672871..176dc661e 100644 --- a/src/mantle/support/class-service-provider.php +++ b/src/mantle/support/class-service-provider.php @@ -156,7 +156,7 @@ public static function publishable_tags(): array { * @param string $path Path to routes file. */ public function load_routes_from( string $path ): void { - require $path; + require $path; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable } /** diff --git a/src/mantle/support/class-str.php b/src/mantle/support/class-str.php index 799527966..fcafa3c39 100644 --- a/src/mantle/support/class-str.php +++ b/src/mantle/support/class-str.php @@ -771,7 +771,7 @@ public static function password( $length = 32, $letters = true, $numbers = true, ) ->when( $numbers, - fn ( $c) => $c->merge( + fn ( $c ) => $c->merge( [ '0', '1', @@ -788,7 +788,7 @@ public static function password( $length = 32, $letters = true, $numbers = true, ) ->when( $symbols, - fn ( $c) => $c->merge( + fn ( $c ) => $c->merge( [ '~', '!', @@ -819,8 +819,8 @@ public static function password( $length = 32, $letters = true, $numbers = true, ] ) ) - ->when( $spaces, fn ( $c) => $c->merge( [ ' ' ] ) ) - ->pipe( fn ( $c) => Collection::times( $length, fn () => $c[ random_int( 0, $c->count() - 1 ) ] ) ) + ->when( $spaces, fn ( $c ) => $c->merge( [ ' ' ] ) ) + ->pipe( fn ( $c ) => Collection::times( $length, fn () => $c[ random_int( 0, $c->count() - 1 ) ] ) ) // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable, Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition ->implode( '' ); } @@ -834,7 +834,7 @@ public static function random( $length = 16 ) { return ( static::$random_string_factory ?? function ( $length ) { $string = ''; - while ( ( $len = strlen( $string ) ) < $length ) { // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition, Squiz.PHP.DisallowSizeFunctionsInLoops.Found + while ( ( $len = strlen( $string ) ) < $length ) { // phpcs:ignore WordPress.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition, Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition, Squiz.PHP.DisallowSizeFunctionsInLoops.Found $size = $length - $len; $bytes_size = (int) ceil( $size / 3 ) * 3; @@ -1193,7 +1193,7 @@ public static function studly( $value ) { $words = explode( ' ', static::replace( [ '-', '_' ], ' ', $value ) ); - $study_words = array_map( fn ( $word) => static::ucfirst( $word ), $words ); + $study_words = array_map( fn ( $word ) => static::ucfirst( $word ), $words ); return static::$studly_cache[ $key ] = implode( '', $study_words ); } diff --git a/src/mantle/support/class-stringable.php b/src/mantle/support/class-stringable.php index 010708ee4..934d36e0b 100644 --- a/src/mantle/support/class-stringable.php +++ b/src/mantle/support/class-stringable.php @@ -25,7 +25,9 @@ */ class Stringable implements ArrayAccess, JsonSerializable, \Stringable { - use Conditionable, Macroable, Tappable; + use Conditionable; + use Macroable; + use Tappable; /** * The underlying string value. diff --git a/src/mantle/support/helpers/helpers-array.php b/src/mantle/support/helpers/helpers-array.php index 5c9c5661b..ca23170b9 100644 --- a/src/mantle/support/helpers/helpers-array.php +++ b/src/mantle/support/helpers/helpers-array.php @@ -54,7 +54,7 @@ function data_get( $target, $key, $default = null ) { $result[] = data_get( $item, $key ); } - return in_array( '*', $key ) ? Support\Arr::collapse( $result ) : $result; + return in_array( '*', $key, true ) ? Support\Arr::collapse( $result ) : $result; } if ( Support\Arr::accessible( $target ) && Support\Arr::exists( $target, $segment ) ) { diff --git a/src/mantle/support/helpers/helpers-general.php b/src/mantle/support/helpers/helpers-general.php index 92c511a4c..c9d72c05c 100644 --- a/src/mantle/support/helpers/helpers-general.php +++ b/src/mantle/support/helpers/helpers-general.php @@ -163,7 +163,7 @@ function filled( mixed $value ): bool { * @return mixed */ function object_get( $object, $key, $default = null ) { - if ( is_null( $key ) || trim( $key ) == '' ) { + if ( is_null( $key ) || trim( $key ) === '' ) { return $object; } @@ -218,8 +218,8 @@ function retry( $times, callable $callback, $sleep = 0, $when = null ) { // phpcs:ignore Generic.PHP.DiscourageGoto.Found beginning: - $attempts ++; - $times --; + $attempts++; + $times--; try { return $callback( $attempts ); @@ -280,9 +280,9 @@ function tap( $value, $callback = null ) { /** * Throw the given exception if the given condition is true. * - * @param mixed $condition Condition to check. - * @param \Throwable|string $exception Exception to throw. - * @param array ...$parameters Params to pass to a new $exception if + * @param mixed $condition Condition to check. + * @param \Throwable|class-string<\Throwable> $exception Exception to throw. + * @param array ...$parameters Params to pass to a new $exception if * $exception is a string (classname). * * @return mixed @@ -290,7 +290,13 @@ function tap( $value, $callback = null ) { */ function throw_if( $condition, $exception, ...$parameters ) { if ( $condition ) { - throw ( is_string( $exception ) ? new $exception( ...$parameters ) : $exception ); + if ( is_string( $exception ) ) { + $e = new $exception( ...$parameters ); + } else { + $e = $exception; + } + + throw $e; } return $condition; @@ -300,7 +306,7 @@ function throw_if( $condition, $exception, ...$parameters ) { * Throw the given exception unless the given condition is true. * * @param mixed $condition Condition to check. - * @param \Throwable|string $exception Exception to throw. + * @param \Throwable|class-string<\Throwable> $exception Exception to throw. * @param array ...$parameters Params to pass to a new $exception if * $exception is a string (classname). * @@ -309,7 +315,13 @@ function throw_if( $condition, $exception, ...$parameters ) { */ function throw_unless( $condition, $exception, ...$parameters ) { if ( ! $condition ) { - throw ( is_string( $exception ) ? new $exception( ...$parameters ) : $exception ); + if ( is_string( $exception ) ) { + $e = new $exception( ...$parameters ); + } else { + $e = $exception; + } + + throw $e; } return $condition; diff --git a/src/mantle/support/interface-enumerable.php b/src/mantle/support/interface-enumerable.php index f338d8356..97f16d592 100644 --- a/src/mantle/support/interface-enumerable.php +++ b/src/mantle/support/interface-enumerable.php @@ -36,7 +36,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable, * @param \Mantle\Contracts\Support\Arrayable|iterable|null $items * @return static */ - public static function make( $items = []); + public static function make( $items = [] ); /** * Create a new instance by invoking the callback a given amount of times. @@ -55,7 +55,7 @@ public static function times( $number, callable $callback = null ); * @param iterable|TWrapValue $value * @return static */ - public static function wrap( $value); + public static function wrap( $value ); /** * Get the underlying items from the given collection if applicable. @@ -66,7 +66,7 @@ public static function wrap( $value); * @param array|static $value * @return array */ - public static function unwrap( $value); + public static function unwrap( $value ); /** * Get all items in the enumerable. @@ -173,7 +173,7 @@ public function diff( $items ); * @param callable(TValue, TValue): int $callback * @return static */ - public function diff_using( $items, callable $callback); + public function diff_using( $items, callable $callback ); /** * Get the items whose keys and values are not present in the given items. @@ -190,7 +190,7 @@ public function diff_assoc( $items ); * @param callable(TValue, TValue): int $callback * @return static */ - public function diff_assoc_using( $items, callable $callback); + public function diff_assoc_using( $items, callable $callback ); /** * Get the items whose keys are not present in the given items. @@ -207,7 +207,7 @@ public function diff_keys( $items ); * @param callable $callback * @return static */ - public function diff_keys_using( $items, callable $callback); + public function diff_keys_using( $items, callable $callback ); /** * Retrieve duplicate items. @@ -232,7 +232,7 @@ public function duplicates_strict( $callback = null ); * @param callable(TValue, TKey): mixed $callback * @return $this */ - public function each( callable $callback); + public function each( callable $callback ); /** * Execute a callback over each nested chunk of items. @@ -240,7 +240,7 @@ public function each( callable $callback); * @param callable $callback * @return static */ - public function each_spread( callable $callback); + public function each_spread( callable $callback ); /** * Determine if all items pass the given truth test. @@ -355,7 +355,7 @@ public function where( $key, $operator = null, $value = null ); * @param mixed $value * @return static */ - public function where_strict( $key, $value); + public function where_strict( $key, $value ); /** * Filter items by the given key value pair. @@ -473,7 +473,7 @@ public function group_by( $group_by, $preserve_keys = false ); * @param (callable(TValue, TKey): array-key)|array|string $keyBy * @return static */ - public function key_by( $key_by); + public function key_by( $key_by ); /** * Determine if an item exists in the collection by key. @@ -481,7 +481,7 @@ public function key_by( $key_by); * @param TKey|array $key * @return bool */ - public function has( $key); + public function has( $key ); /** * Concatenate values of a given key as a string. @@ -529,7 +529,7 @@ public function is_not_empty(); * @param string $final_glue * @return string */ - public function join( $glue, $final_glue = ''); + public function join( $glue, $final_glue = '' ); /** * Get the keys of the collection items. @@ -557,7 +557,7 @@ public function last( callable $callback = null, $default = null ); * @param callable(TValue, TKey): TMapValue $callback * @return static */ - public function map( callable $callback); + public function map( callable $callback ); /** * Run a map over each nested chunk of items. @@ -565,7 +565,7 @@ public function map( callable $callback); * @param callable $callback * @return static */ - public function map_spread( callable $callback); + public function map_spread( callable $callback ); /** * Run a dictionary map over the items. @@ -578,14 +578,14 @@ public function map_spread( callable $callback); * @param callable(TValue, TKey): array $callback * @return static> */ - public function map_to_dictionary( callable $callback); + public function map_to_dictionary( callable $callback ); /** * Run a grouping map over the items. * * The callback should return an associative array with a single key/value pair. */ - public function map_to_groups( callable $callback); + public function map_to_groups( callable $callback ); /** * Run an associative map over each of the items. @@ -598,7 +598,7 @@ public function map_to_groups( callable $callback); * @param callable(TValue, TKey): array $callback * @return static */ - public function map_with_keys( callable $callback); + public function map_with_keys( callable $callback ); /** * Map a collection and flatten the result by a single level. @@ -609,7 +609,7 @@ public function map_with_keys( callable $callback); * @param callable(TValue, TKey): (\Illuminate\Support\Collection|array) $callback * @return static */ - public function flat_map( callable $callback); + public function flat_map( callable $callback ); /** * Map the values into a new class. @@ -680,7 +680,7 @@ public function max( $callback = null ); * @param int $offset * @return static */ - public function nth( $step, $offset = 0); + public function nth( $step, $offset = 0 ); /** * Get the items with the specified keys. @@ -697,7 +697,7 @@ public function only( $keys ); * @param int $per_page * @return static */ - public function for_page( $page, $per_page); + public function for_page( $page, $per_page ); /** * Partition the collection into two arrays using the given callback or key.\ @@ -710,7 +710,7 @@ public function partition( $key, $operator = null, $value = null ); * @param iterable $source * @return static */ - public function concat( $source); + public function concat( $source ); /** * Get one or a specified number of items randomly from the collection. @@ -780,7 +780,7 @@ public function shuffle( $seed = null ); * @param int $count * @return static */ - public function skip( $count); + public function skip( $count ); /** * Get a slice of items from the enumerable. @@ -805,7 +805,7 @@ public function split( $number_of_groups ); * @param int $size * @return static */ - public function chunk( $size); + public function chunk( $size ); /** * Sort through each item with a callback. @@ -821,7 +821,7 @@ public function sort( $callback = null ); * @param int $options * @return static */ - public function sort_desc( $options = SORT_REGULAR); + public function sort_desc( $options = SORT_REGULAR ); /** * Sort the collection using the given callback. @@ -840,7 +840,7 @@ public function sort_by( $callback, $options = SORT_REGULAR, $descending = false * @param int $options * @return static */ - public function sort_by_desc( $callback, $options = SORT_REGULAR); + public function sort_by_desc( $callback, $options = SORT_REGULAR ); /** * Sort the collection keys. @@ -857,7 +857,7 @@ public function sort_keys( $options = SORT_REGULAR, $descending = false ); * @param int $options * @return static */ - public function sort_keys_desc( $options = SORT_REGULAR); + public function sort_keys_desc( $options = SORT_REGULAR ); /** * Get the sum of the given values. @@ -873,7 +873,7 @@ public function sum( $callback = null ); * @param int $limit * @return static */ - public function take( $limit); + public function take( $limit ); /** * Pass the collection to the given callback and then return it. @@ -881,7 +881,7 @@ public function take( $limit); * @param callable(TValue): mixed $callback * @return $this */ - public function tap( callable $callback); + public function tap( callable $callback ); /** * Pass the enumerable to the given callback and return the result. @@ -891,7 +891,7 @@ public function tap( callable $callback); * @param callable($this): TPipeReturnType $callback * @return TPipeReturnType */ - public function pipe( callable $callback); + public function pipe( callable $callback ); /** * Get the values of a given key. @@ -908,7 +908,7 @@ public function pluck( $value, $key = null ); * @param (callable(TValue, TKey): bool)|bool|TValue $callback * @return static */ - public function reject( $callback = true); + public function reject( $callback = true ); /** * Return only unique items from the collection array. @@ -943,7 +943,7 @@ public function values(); * @param TPadValue $value * @return static */ - public function pad( $size, $value); + public function pad( $size, $value ); /** * Count the number of items in the collection using a given truth test. @@ -973,7 +973,7 @@ public function __toString(); * @param string $method * @return void */ - public static function proxy( $method); + public static function proxy( $method ); /** * Dynamically access collection proxies. @@ -983,5 +983,5 @@ public static function proxy( $method); * * @throws \Exception */ - public function __get( $key); + public function __get( $key ); } diff --git a/src/mantle/support/trait-forward-calls.php b/src/mantle/support/trait-forward-calls.php index 58bc14455..14b32bc63 100644 --- a/src/mantle/support/trait-forward-calls.php +++ b/src/mantle/support/trait-forward-calls.php @@ -37,7 +37,7 @@ protected function forward_call_to( $object, $method, $parameters ) { if ( $object::class !== $matches['class'] - || $matches['method'] != $method + || $matches['method'] !== $method ) { throw $e; } diff --git a/src/mantle/support/traits/trait-enumerates-values.php b/src/mantle/support/traits/trait-enumerates-values.php index 81bd60fb8..a038d7c70 100644 --- a/src/mantle/support/traits/trait-enumerates-values.php +++ b/src/mantle/support/traits/trait-enumerates-values.php @@ -2,22 +2,21 @@ /** * Enumerates_Values trait file. * + * phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed + * phpcs:disable Squiz.Commenting.FunctionComment.MissingParamComment + * phpcs:disable Squiz.Commenting.FunctionComment.ParamNameNoMatch + * phpcs:disable Squiz.Commenting.FunctionComment.MissingParamTag + * phpcs:disable WordPress.PHP.StrictInArray.MissingTrueStrict + * * @package Mantle */ -// phpcs:disable Squiz.Commenting.FunctionComment.MissingParamComment - -// phpcs:disable Squiz.Commenting.FunctionComment.ParamNameNoMatch - -// phpcs:disable Squiz.Commenting.FunctionComment.MissingParamTag - namespace Mantle\Support\Traits; use Closure; use Exception; use Mantle\Contracts\Support\Arrayable; use Mantle\Contracts\Support\Jsonable; -use function Mantle\Support\Helpers\data_get; use Mantle\Support\Arr; use Mantle\Support\Collection; use Mantle\Support\Enumerable; @@ -26,6 +25,8 @@ use Symfony\Component\VarDumper\VarDumper; use Traversable; +use function Mantle\Support\Helpers\data_get; + /** * Enumerate_Values trait. * @@ -162,7 +163,7 @@ public function some( $key, $operator = null, $value = null ) { public function contains_strict( $key, $value = null ) { if ( func_num_args() === 2 ) { return $this->contains( - fn ( $item) => data_get( $item, $key ) === $value + fn ( $item ) => data_get( $item, $key ) === $value ); } @@ -338,7 +339,7 @@ public function flat_map( callable $callback ) { */ public function map_into( $class ) { return $this->map( - fn ( $value, $key) => new $class( $value, $key ) + fn ( $value, $key ) => new $class( $value, $key ) ); } @@ -352,11 +353,11 @@ public function min( $callback = null ) { $callback = $this->value_retriever( $callback ); return $this->map( - fn ( $value) => $callback( $value ) + fn ( $value ) => $callback( $value ) )->filter( - fn ( $value) => ! is_null( $value ) + fn ( $value ) => ! is_null( $value ) )->reduce( - fn ( $result, $value) => is_null( $result ) || $value < $result ? $value : $result + fn ( $result, $value ) => is_null( $result ) || $value < $result ? $value : $result ); } @@ -370,7 +371,7 @@ public function max( $callback = null ) { $callback = $this->value_retriever( $callback ); return $this->filter( - fn ( $value) => ! is_null( $value ) + fn ( $value ) => ! is_null( $value ) )->reduce( function ( $result, $item ) use ( $callback ) { $value = $callback( $item ); @@ -428,13 +429,13 @@ public function partition( $key, $operator = null, $value = null ) { */ public function sum( $callback = null ) { if ( is_null( $callback ) ) { - $callback = fn ( $value) => $value; + $callback = fn ( $value ) => $value; } else { $callback = $this->value_retriever( $callback ); } return $this->reduce( - fn ( $result, $item) => $result + $callback( $item ), + fn ( $result, $item ) => $result + $callback( $item ), 0 ); } @@ -546,7 +547,7 @@ public function where_in( $key, $values, $strict = false ) { $values = $this->get_arrayable_items( $values ); return $this->filter( - fn ( $item) => in_array( data_get( $item, $key ), $values, $strict ) + fn ( $item ) => in_array( data_get( $item, $key ), $values, $strict ) // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict ); } @@ -581,7 +582,7 @@ public function where_between( $key, $values ) { */ public function where_not_between( $key, $values ) { return $this->filter( - fn ( $item) => data_get( $item, $key ) < reset( $values ) || data_get( $item, $key ) > end( $values ) + fn ( $item ) => data_get( $item, $key ) < reset( $values ) || data_get( $item, $key ) > end( $values ) ); } @@ -597,7 +598,7 @@ public function where_not_in( $key, $values, $strict = false ) { $values = $this->get_arrayable_items( $values ); return $this->reject( - fn ( $item) => in_array( data_get( $item, $key ), $values, $strict ) + fn ( $item ) => in_array( data_get( $item, $key ), $values, $strict ) // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict ); } @@ -660,9 +661,9 @@ public function reject( $callback = true ) { $use_as_callable = $this->use_as_callable( $callback ); return $this->filter( - fn ( $value, $key) => $use_as_callable + fn ( $value, $key ) => $use_as_callable ? ! $callback( $value, $key ) - : $value != $callback + : $value != $callback // phpcs:ignore Universal.Operators.StrictComparisons.LooseNotEqual, WordPress.PHP.StrictComparisons.LooseComparison ); } @@ -769,12 +770,12 @@ public function to_json( $options = 0 ) { */ public function count_by( $callback = null ) { if ( is_null( $callback ) ) { - $callback = fn ( $value) => $value; + $callback = fn ( $value ) => $value; } return new static( $this->group_by( $callback )->map( - fn ( $value) => $value->count() + fn ( $value ) => $value->count() ) ); } @@ -863,10 +864,10 @@ protected function operator_for_where( $key, $operator = null, $value = null ) { $strings = array_filter( [ $retrieved, $value ], - fn ( $value) => is_string( $value ) || ( is_object( $value ) && method_exists( $value, '__toString' ) ) + fn ( $value ) => is_string( $value ) || ( is_object( $value ) && method_exists( $value, '__toString' ) ) ); - if ( count( $strings ) < 2 && count( array_filter( [ $retrieved, $value ], 'is_object' ) ) == 1 ) { + if ( count( $strings ) < 2 && count( array_filter( [ $retrieved, $value ], 'is_object' ) ) === 1 ) { return in_array( $operator, [ '!=', '<>', '!==' ] ); } @@ -874,10 +875,10 @@ protected function operator_for_where( $key, $operator = null, $value = null ) { default: case '=': case '==': - return $retrieved == $value; + return $retrieved == $value; // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual case '!=': case '<>': - return $retrieved != $value; + return $retrieved !== $value; case '<': return $retrieved < $value; case '>': diff --git a/src/mantle/support/traits/trait-hookable.php b/src/mantle/support/traits/trait-hookable.php index 7255cf63b..b31f746c8 100644 --- a/src/mantle/support/traits/trait-hookable.php +++ b/src/mantle/support/traits/trait-hookable.php @@ -44,7 +44,7 @@ function ( array $item ): void { } else { \Mantle\Support\Helpers\add_filter( $item['hook'], [ $this, $item['method'] ], $item['priority'] ); } - } else { + } else { // phpcs:ignore Universal.ControlStructures.DisallowLonelyIf.Found // Use the default WordPress action/filter methods. if ( 'action' === $item['type'] ) { \add_action( $item['hook'], [ $this, $item['method'] ], $item['priority'], 999 ); @@ -67,7 +67,7 @@ protected function collect_action_methods(): Collection { fn ( string $method ) => Str::starts_with( $method, [ 'on_', 'action__', 'filter__' ] ) ) ->map( - function( string $method ) { + function ( string $method ) { $type = match ( true ) { Str::starts_with( $method, 'filter__' ) => 'filter', default => 'action', diff --git a/src/mantle/testing/class-assertable-json-string.php b/src/mantle/testing/class-assertable-json-string.php index 94d5727e9..26907436e 100644 --- a/src/mantle/testing/class-assertable-json-string.php +++ b/src/mantle/testing/class-assertable-json-string.php @@ -2,6 +2,8 @@ /** * Assertable_Json_String class file * + * phpcs:disable WordPress.WP.AlternativeFunctions.json_encode_json_encode + * * @package Mantle */ @@ -29,12 +31,9 @@ class Assertable_Json_String implements ArrayAccess, Countable { /** * Constructor. * - * @param string|array|Jsonable|JsonSerializable $json - */ - public function __construct( /** - * The original encoded JSON. + * @param string|array|Jsonable|JsonSerializable $json The original encoded JSON. */ - public $json ) { + public function __construct( public $json ) { if ( $this->json instanceof JsonSerializable ) { $this->decoded = $this->json->jsonSerialize(); } elseif ( $this->json instanceof Jsonable ) { @@ -107,7 +106,7 @@ public function assertPathMissing( string $path ) { /** * Assert that the response has the similar JSON as given. * - * @param array $data + * @param array $data * @return $this */ public function assertSimilar( array $data ) { @@ -123,8 +122,8 @@ public function assertSimilar( array $data ) { /** * Assert that the response has a given JSON structure. * - * @param array|null $structure - * @param array|null $response_data + * @param array|null $structure + * @param array|null $response_data * @return $this */ public function assertStructure( array $structure = null, $response_data = null ) { @@ -138,13 +137,13 @@ public function assertStructure( array $structure = null, $response_data = null foreach ( $structure as $key => $value ) { if ( is_array( $value ) && '*' === $key ) { - PHPUnit::assertIsArray($this->decoded); + PHPUnit::assertIsArray( $this->decoded ); foreach ( $this->decoded as $item ) { $this->assertStructure( $structure['*'], $item ); } } elseif ( is_array( $value ) ) { - PHPUnit::assertArrayHasKey($key, $this->decoded); + PHPUnit::assertArrayHasKey( $key, $this->decoded ); $this->assertStructure( $structure[ $key ], $this->decoded[ $key ] ); } else { @@ -317,7 +316,7 @@ public function count(): int { /** * Determine whether an offset exists. * - * @param mixed $offset + * @param mixed $offset */ public function offsetExists( $offset ): bool { return isset( $this->decoded[ $offset ] ); @@ -326,7 +325,7 @@ public function offsetExists( $offset ): bool { /** * Get the value at the given offset. * - * @param string $offset + * @param string $offset */ public function offsetGet( $offset ): mixed { return $this->decoded[ $offset ]; @@ -335,19 +334,19 @@ public function offsetGet( $offset ): mixed { /** * Set the value at the given offset. * - * @param string $offset + * @param string $offset * @param mixed $value */ - public function offsetSet($offset, $value): void { + public function offsetSet( $offset, $value ): void { $this->decoded[ $offset ] = $value; } /** * Unset the value at the given offset. * - * @param string $offset + * @param string $offset */ - public function offsetUnset($offset): void { + public function offsetUnset( $offset ): void { unset( $this->decoded[ $offset ] ); } } diff --git a/src/mantle/testing/class-mock-http-response.php b/src/mantle/testing/class-mock-http-response.php index 9df9a472f..b97f65952 100644 --- a/src/mantle/testing/class-mock-http-response.php +++ b/src/mantle/testing/class-mock-http-response.php @@ -23,7 +23,8 @@ * ->with_header( 'Content-Type', 'application/json' ); */ class Mock_Http_Response implements Arrayable { - use Conditionable, Macroable; + use Conditionable; + use Macroable; /** * Response data. diff --git a/src/mantle/testing/class-pending-testable-request.php b/src/mantle/testing/class-pending-testable-request.php index 590de854d..374678125 100644 --- a/src/mantle/testing/class-pending-testable-request.php +++ b/src/mantle/testing/class-pending-testable-request.php @@ -237,19 +237,19 @@ public function call( string $method, mixed $uri, array $parameters = [], array $response_status = null; $response_headers = []; - $intercept_status = function( $status_header, $code ) use ( &$response_status ): int { + $intercept_status = function ( $status_header, $code ) use ( &$response_status ): int { $response_status = $code; return $code; }; - $intercept_headers = function( $send_headers ) use ( &$response_headers ): array { + $intercept_headers = function ( $send_headers ) use ( &$response_headers ): array { $response_headers = $send_headers; return $send_headers; }; - $intercept_redirect = function( $location, $status ) use ( &$response_status, &$response_headers ): void { + $intercept_redirect = function ( $location, $status ) use ( &$response_status, &$response_headers ): void { $response_status = $status; $response_headers['Location'] = $location; throw new WP_Redirect_Exception(); @@ -278,7 +278,7 @@ public function call( string $method, mixed $uri, array $parameters = [], array // Mirror the logic from Request::createFromGlobals(). if ( str_starts_with( (string) $request->headers->get( 'CONTENT_TYPE', '' ), 'application/x-www-form-urlencoded' ) - && \in_array( strtoupper( (string) $request->server->get( 'REQUEST_METHOD', 'GET' ) ), [ 'PUT', 'DELETE', 'PATCH' ] ) + && \in_array( strtoupper( (string) $request->server->get( 'REQUEST_METHOD', 'GET' ) ), [ 'PUT', 'DELETE', 'PATCH' ], true ) ) { parse_str( $request->getContent(), $data ); diff --git a/src/mantle/testing/class-test-case.php b/src/mantle/testing/class-test-case.php index aec71c635..c3bff6deb 100644 --- a/src/mantle/testing/class-test-case.php +++ b/src/mantle/testing/class-test-case.php @@ -48,21 +48,21 @@ * @property-read Application|null $app */ abstract class Test_Case extends BaseTestCase { - use Assertions, - Core_Shim, - Deprecations, - Hooks, - Incorrect_Usage, - Interacts_With_Console, - Interacts_With_Container, - Interacts_With_Cron, - Interacts_With_Hooks, - Interacts_With_Mail, - Interacts_With_Requests, - Makes_Http_Requests, - MatchesSnapshots, - WordPress_State, - WordPress_Authentication; + use Assertions; + use Core_Shim; + use Deprecations; + use Hooks; + use Incorrect_Usage; + use Interacts_With_Console; + use Interacts_With_Container; + use Interacts_With_Cron; + use Interacts_With_Hooks; + use Interacts_With_Mail; + use Interacts_With_Requests; + use Makes_Http_Requests; + use MatchesSnapshots; + use WordPress_State; + use WordPress_Authentication; /** * Array of traits that this class uses, with trait names as keys. @@ -95,7 +95,7 @@ public static function setUpBeforeClass(): void { if ( ! empty( static::$test_uses ) ) { static::get_test_case_traits() ->each( - function( $trait ): void { + function ( $trait ): void { $method = strtolower( class_basename( $trait ) ) . '_set_up_before_class'; if ( method_exists( static::class, $method ) ) { @@ -155,7 +155,7 @@ protected function setUp(): void { // Boot traits on the test case. static::get_test_case_traits() ->each( - function( $trait ): void { + function ( $trait ): void { $method = strtolower( class_basename( $trait ) ) . '_set_up'; if ( method_exists( $this, $method ) ) { @@ -189,7 +189,7 @@ protected function tearDown(): void { // Tearing down requires performing priority traits in opposite order. ->reverse() ->each( - function( $trait ): void { + function ( $trait ): void { $method = strtolower( class_basename( $trait ) ) . '_tear_down'; if ( method_exists( $this, $method ) ) { diff --git a/src/mantle/testing/class-test-command.php b/src/mantle/testing/class-test-command.php index f789f5ab0..88a5523a7 100644 --- a/src/mantle/testing/class-test-command.php +++ b/src/mantle/testing/class-test-command.php @@ -230,11 +230,11 @@ protected function verify_expectations(): void { // todo: add output substring assertions. // if ( ! empty( $this->expected_output_substrings ) ) { - // $output = $this->tester->getDisplay(); + // $output = $this->tester->getDisplay(); - // foreach ( $this->expected_output_substrings as $expected_output_substring ) { - // $this->test->assertStringContainsString( $expected_output_substring, $output ); - // } + // foreach ( $this->expected_output_substrings as $expected_output_substring ) { + // $this->test->assertStringContainsString( $expected_output_substring, $output ); + // } // } } diff --git a/src/mantle/testing/class-test-response.php b/src/mantle/testing/class-test-response.php index 9f6066a5c..64a3b464e 100644 --- a/src/mantle/testing/class-test-response.php +++ b/src/mantle/testing/class-test-response.php @@ -17,9 +17,9 @@ * Faux "Response" class for unit testing. */ class Test_Response { - use Concerns\Element_Assertions, - Concerns\Snapshot_Testing, - Macroable; + use Concerns\Element_Assertions; + use Concerns\Snapshot_Testing; + use Macroable; /** * Application instance. @@ -174,8 +174,6 @@ public function get_header( string $key, string $default = null ): ?string { /** * Assert that the response has a successful status code. - * - * @return static */ public function assertSuccessful(): static { $actual = $this->get_status_code(); @@ -190,8 +188,6 @@ public function assertSuccessful(): static { /** * Assert that the response has a 200 status code. - * - * @return static */ public function assertOk(): static { return $this->assertStatus( 200 ); @@ -201,7 +197,6 @@ public function assertOk(): static { * Assert that the response has the given status code. * * @param int $status Status code to assert. - * @return static */ public function assertStatus( $status ): static { $actual = $this->get_status_code(); @@ -217,8 +212,6 @@ public function assertStatus( $status ): static { /** * Assert that the response has a 201 status code. - * - * @return static */ public function assertCreated(): static { return $this->assertStatus( 201 ); @@ -228,7 +221,6 @@ public function assertCreated(): static { * Assert that the response has the given status code and no content. * * @param int $status Status code to assert. Defaults to 204. - * @return static */ public function assertNoContent( $status = 204 ): static { $this->assertStatus( $status ); @@ -240,8 +232,6 @@ public function assertNoContent( $status = 204 ): static { /** * Assert that the response has a not found status code. - * - * @return static */ public function assertNotFound(): static { return $this->assertStatus( 404 ); @@ -249,8 +239,6 @@ public function assertNotFound(): static { /** * Assert that the response has a forbidden status code. - * - * @return static */ public function assertForbidden(): static { return $this->assertStatus( 403 ); @@ -258,8 +246,6 @@ public function assertForbidden(): static { /** * Assert that the response has an unauthorized status code. - * - * @return static */ public function assertUnauthorized(): static { return $this->assertStatus( 401 ); @@ -267,8 +253,6 @@ public function assertUnauthorized(): static { /** * Assert that the response has a client error status code. - * - * @return static */ public function assertClientError(): static { $status = $this->get_status_code(); @@ -283,8 +267,6 @@ public function assertClientError(): static { /** * Assert that the response has a server error status code. - * - * @return static */ public function assertServerError(): static { $status = $this->get_status_code(); @@ -301,7 +283,6 @@ public function assertServerError(): static { * Assert whether the response is redirecting to a given URI. * * @param string|null $uri URI to assert redirection to. - * @return static */ public function assertRedirect( ?string $uri = null ): static { PHPUnit::assertTrue( diff --git a/src/mantle/testing/class-utils.php b/src/mantle/testing/class-utils.php index 7892dfedc..56e5d2586 100644 --- a/src/mantle/testing/class-utils.php +++ b/src/mantle/testing/class-utils.php @@ -484,7 +484,7 @@ public static function ensure_composer_loaded(): void { foreach ( $paths as $path ) { if ( ! is_dir( $path ) && file_exists( $path ) ) { - require_once $path; + require_once $path; // phpcs:ignore WordPressVIPMinimum.Files.IncludingFile.UsingVariable return; } diff --git a/src/mantle/testing/concerns/trait-assertions.php b/src/mantle/testing/concerns/trait-assertions.php index c2aa034de..7bdd772c6 100644 --- a/src/mantle/testing/concerns/trait-assertions.php +++ b/src/mantle/testing/concerns/trait-assertions.php @@ -2,7 +2,7 @@ /** * This file contains the Assertions trait * - * phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_print_r + * phpcs:disable WordPress.PHP.DevelopmentFunctions.error_log_print_r, WordPressVIPMinimum.Functions.RestrictedFunctions.get_posts_get_posts * * @package Mantle */ @@ -25,8 +25,8 @@ * Assorted Test_Cast assertions. */ trait Assertions { - use Asset_Assertions, - Block_Assertions; + use Asset_Assertions; + use Block_Assertions; /** * Asserts that the given value is an instance of WP_Error. @@ -305,8 +305,9 @@ public function assertPostExists( array $arguments ): void { $arguments = $this->serialize_arguments( $arguments, [ - 'fields' => 'ids', - 'posts_per_page' => 1, + 'fields' => 'ids', + 'posts_per_page' => 1, + 'suppress_filters' => false, ], ); @@ -325,8 +326,9 @@ public function assertPostDoesNotExists( array $arguments ): void { $arguments = $this->serialize_arguments( $arguments, [ - 'fields' => 'ids', - 'posts_per_page' => 1, + 'fields' => 'ids', + 'posts_per_page' => 1, + 'suppress_filters' => false, ], ); diff --git a/src/mantle/testing/concerns/trait-create-application.php b/src/mantle/testing/concerns/trait-create-application.php index d1b4b2dcf..645022571 100644 --- a/src/mantle/testing/concerns/trait-create-application.php +++ b/src/mantle/testing/concerns/trait-create-application.php @@ -117,7 +117,7 @@ final protected function resolve_application_providers( $app ): array { if ( ! empty( $overrides ) ) { $providers->transform( - static fn ( $provider) => $overrides[ $provider ] ?? $provider + static fn ( $provider ) => $overrides[ $provider ] ?? $provider ); } diff --git a/src/mantle/testing/concerns/trait-dependency-assertions.php b/src/mantle/testing/concerns/trait-dependency-assertions.php index 0ea9160fe..51a504819 100644 --- a/src/mantle/testing/concerns/trait-dependency-assertions.php +++ b/src/mantle/testing/concerns/trait-dependency-assertions.php @@ -64,5 +64,4 @@ public static function assertDependencyLoaded( string $dependency ): void { ) ); } - } diff --git a/src/mantle/testing/concerns/trait-deprecations.php b/src/mantle/testing/concerns/trait-deprecations.php index 8d5714706..8d741269f 100644 --- a/src/mantle/testing/concerns/trait-deprecations.php +++ b/src/mantle/testing/concerns/trait-deprecations.php @@ -16,7 +16,8 @@ use function Mantle\Support\Helpers\collect; trait Deprecations { - use Output_Messages, Reads_Annotations; + use Output_Messages; + use Reads_Annotations; /** * Expected deprecation calls. diff --git a/src/mantle/testing/concerns/trait-incorrect-usage.php b/src/mantle/testing/concerns/trait-incorrect-usage.php index e999f3d56..7d7b6c0c4 100644 --- a/src/mantle/testing/concerns/trait-incorrect-usage.php +++ b/src/mantle/testing/concerns/trait-incorrect-usage.php @@ -22,7 +22,8 @@ * as expected or ignored. */ trait Incorrect_Usage { - use Output_Messages, Reads_Annotations; + use Output_Messages; + use Reads_Annotations; /** * Expected "doing it wrong" calls. diff --git a/src/mantle/testing/concerns/trait-interacts-with-container.php b/src/mantle/testing/concerns/trait-interacts-with-container.php index 476ad7eea..4f71543c0 100644 --- a/src/mantle/testing/concerns/trait-interacts-with-container.php +++ b/src/mantle/testing/concerns/trait-interacts-with-container.php @@ -2,6 +2,8 @@ /** * Interacts_With_Container trait file. * + * phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed + * * @package Mantle */ diff --git a/src/mantle/testing/concerns/trait-interacts-with-hooks.php b/src/mantle/testing/concerns/trait-interacts-with-hooks.php index 5315cd016..a91568c56 100644 --- a/src/mantle/testing/concerns/trait-interacts-with-hooks.php +++ b/src/mantle/testing/concerns/trait-interacts-with-hooks.php @@ -37,7 +37,7 @@ public function interacts_with_hooks_set_up(): void { \add_filter( 'all', - function( $value ) { + function ( $value ) { $filter = current_filter(); if ( ! isset( $this->hooks_fired[ $filter ] ) ) { diff --git a/src/mantle/testing/concerns/trait-interacts-with-requests.php b/src/mantle/testing/concerns/trait-interacts-with-requests.php index 10d3a628a..e116088dc 100644 --- a/src/mantle/testing/concerns/trait-interacts-with-requests.php +++ b/src/mantle/testing/concerns/trait-interacts-with-requests.php @@ -356,7 +356,7 @@ protected function store_streamed_response( string $url, array $response, array * @param string $method Request method, optional. */ protected function create_stub_request_callback( string $url, Mock_Http_Response|callable $response, ?string $method = null ): callable { - return function( string $request_url, array $request_args ) use ( $url, $response, $method ) { + return function ( string $request_url, array $request_args ) use ( $url, $response, $method ) { if ( ! Str::is( Str::start( $url, '*' ), $request_url ) ) { return; } diff --git a/src/mantle/testing/concerns/trait-makes-http-requests.php b/src/mantle/testing/concerns/trait-makes-http-requests.php index 362a6328b..3557fba5d 100644 --- a/src/mantle/testing/concerns/trait-makes-http-requests.php +++ b/src/mantle/testing/concerns/trait-makes-http-requests.php @@ -249,7 +249,7 @@ public function post( string $uri, array $data = [], array $headers = [] ): Test * @param int $options JSON encoding options. */ public function post_json( string $uri, array $data = [], array $headers = [], int $options = 0 ): Test_Response { - return $this->create_pending_request()->json( 'POST', $uri, $data, $headers ); + return $this->create_pending_request()->json( 'POST', $uri, $data, $headers, $options ); } /** diff --git a/src/mantle/testing/concerns/trait-refresh-database.php b/src/mantle/testing/concerns/trait-refresh-database.php index 0dd342e6c..c7afdf7a5 100644 --- a/src/mantle/testing/concerns/trait-refresh-database.php +++ b/src/mantle/testing/concerns/trait-refresh-database.php @@ -21,7 +21,7 @@ public static function refresh_database_setup_before_class(): void { $wpdb->show_errors = true; $wpdb->db_connect(); - ini_set( 'display_errors', '1' ); // phpcs:ignore WordPress.PHP.IniSet.display_errors_Blacklisted + ini_set( 'display_errors', '1' ); // phpcs:ignore WordPress.PHP.IniSet.display_errors_Disallowed } /** diff --git a/src/mantle/testing/concerns/trait-rsync-installation.php b/src/mantle/testing/concerns/trait-rsync-installation.php index 17b5418ab..db51c4d1a 100644 --- a/src/mantle/testing/concerns/trait-rsync-installation.php +++ b/src/mantle/testing/concerns/trait-rsync-installation.php @@ -417,6 +417,8 @@ protected function perform_rsync_testsuite() { exit( 1 ); } + $retval = -1; + // Rsync the from folder to the destination. $output = Utils::command( [ diff --git a/src/mantle/testing/concerns/trait-snapshot-testing.php b/src/mantle/testing/concerns/trait-snapshot-testing.php index 7f8ffc1bf..e0504fc70 100644 --- a/src/mantle/testing/concerns/trait-snapshot-testing.php +++ b/src/mantle/testing/concerns/trait-snapshot-testing.php @@ -91,7 +91,7 @@ public function assertMatchesSnapshotHtml( array|string $selectors = null ): sta $document->formatOutput = true; // To ignore HTML5 errors. - @$document->loadHTML( $this->get_content(), LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged + @$document->loadHTML( $this->get_content(), LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, Generic.PHP.NoSilencedErrors.Forbidden $nodes = ( new \DOMXPath( $document ) )->query( implode( '|', $selectors ) ); diff --git a/src/mantle/testing/exceptions/class-exception.php b/src/mantle/testing/exceptions/class-exception.php index 073e590b8..b977553ea 100644 --- a/src/mantle/testing/exceptions/class-exception.php +++ b/src/mantle/testing/exceptions/class-exception.php @@ -7,7 +7,7 @@ namespace Mantle\Testing\Exceptions; -use \Exception as Base_Exception; +use Exception as Base_Exception; /** * General exception for wp_die(). diff --git a/src/mantle/testing/expectation/class-expectation.php b/src/mantle/testing/expectation/class-expectation.php index 47f9fb136..59a6b5ecc 100644 --- a/src/mantle/testing/expectation/class-expectation.php +++ b/src/mantle/testing/expectation/class-expectation.php @@ -186,7 +186,7 @@ public function validate(): void { // Asset if the action was added. if ( Expectation_Container::ACTION_ADDED === $this->action ) { PHPUnit::assertTrue( - ! ! has_action( $this->hook, $this->args ?? false ), + (bool) has_action( $this->hook, $this->args ?? false ), "Expected that hook [{$this->hook}] would have action added." ); } @@ -286,7 +286,7 @@ public function andReturnTrue(): static { * Specify that the filter returns a truthy value. */ public function andReturnTruthy(): static { - return $this->returnComparison( fn ( $value ) => ! ! $value ); + return $this->returnComparison( fn ( $value ) => (bool) $value ); } /** diff --git a/src/mantle/testing/mail/class-mock-mailer.php b/src/mantle/testing/mail/class-mock-mailer.php index e6b308d12..bf94433f7 100644 --- a/src/mantle/testing/mail/class-mock-mailer.php +++ b/src/mantle/testing/mail/class-mock-mailer.php @@ -23,7 +23,11 @@ * @package Mantle */ class Mock_Mailer extends \PHPMailer\PHPMailer\PHPMailer { - /** @var Mail_Message[] */ + /** + * Mock sent emails. + * + * @var Mail_Message[] + */ public array $mock_sent = []; /** diff --git a/src/mantle/testing/preload.php b/src/mantle/testing/preload.php index 45973e413..40d87f3a9 100644 --- a/src/mantle/testing/preload.php +++ b/src/mantle/testing/preload.php @@ -28,7 +28,7 @@ function tests_add_filter( $tag, $function_to_add, $priority = 10, $accepted_arg if ( function_exists( 'add_filter' ) ) { add_filter( $tag, $function_to_add, $priority, $accepted_args ); } else { - $idx = _test_filter_build_unique_id( $tag, $function_to_add, $priority ); + $idx = _test_filter_build_unique_id( $tag, $function_to_add ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride $wp_filter[ $tag ][ $priority ][ $idx ] = [ @@ -46,11 +46,9 @@ function tests_add_filter( $tag, $function_to_add, $priority = 10, $accepted_arg * * @param string $tag Unused. The name of the filter to build ID for. * @param callable $function The function to generate ID for. - * @param int $priority Unused. The order in which the functions - * associated with a particular action are executed. * @return string Unique function ID for usage as array key. */ -function _test_filter_build_unique_id( $tag, $function, $priority ) { +function _test_filter_build_unique_id( $tag, $function ) { if ( is_string( $function ) ) { return $function; } diff --git a/src/mantle/testing/snapshots/class-html-driver.php b/src/mantle/testing/snapshots/class-html-driver.php index fce17f2ab..172cef793 100644 --- a/src/mantle/testing/snapshots/class-html-driver.php +++ b/src/mantle/testing/snapshots/class-html-driver.php @@ -37,7 +37,7 @@ public function serialize( mixed $data ): string { $document->preserveWhiteSpace = false; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase $document->formatOutput = true; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase - @$document->loadHTML( $data, LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged + @$document->loadHTML( $data, LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED ); // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, Generic.PHP.NoSilencedErrors.Forbidden $value = $document->saveHTML(); diff --git a/src/mantle/testkit/class-application.php b/src/mantle/testkit/class-application.php index 9601650e9..ccee4a9f4 100644 --- a/src/mantle/testkit/class-application.php +++ b/src/mantle/testkit/class-application.php @@ -293,7 +293,7 @@ protected function register_base_service_providers() { $this->singleton( Generator::class, - function() { + function () { $factory = Factory::create(); $factory->unique( true ); diff --git a/src/mantle/testkit/concerns/trait-create-application.php b/src/mantle/testkit/concerns/trait-create-application.php index e52f7a1f5..078e18c37 100644 --- a/src/mantle/testkit/concerns/trait-create-application.php +++ b/src/mantle/testkit/concerns/trait-create-application.php @@ -165,7 +165,7 @@ final protected function resolve_application_providers( $app ): array { if ( ! empty( $overrides ) ) { $providers->transform( - static fn ( $provider) => $overrides[ $provider ] ?? $provider + static fn ( $provider ) => $overrides[ $provider ] ?? $provider ); } diff --git a/src/mantle/view/class-view-service-provider.php b/src/mantle/view/class-view-service-provider.php index a2b4eab50..c5727a97c 100644 --- a/src/mantle/view/class-view-service-provider.php +++ b/src/mantle/view/class-view-service-provider.php @@ -52,7 +52,7 @@ protected function register_engine_resolver() { 'view.engine.resolver', fn () => tap( new Engine_Resolver(), - function( Engine_Resolver $resolver ): void { + function ( Engine_Resolver $resolver ): void { // Register the various view engines. $this->register_php_engine( $resolver ); $this->register_file_engine( $resolver ); @@ -120,7 +120,7 @@ function ( View_Finder $loader ): void { protected function register_factory() { $this->app->singleton( 'view', - function( $app ) { + function ( $app ) { $factory = new Factory( $app, $app['view.engine.resolver'], diff --git a/tests/Console/generators/PrinterTest.php b/tests/Console/generators/PrinterTest.php index 4b9b8bf5e..9e5d91dc3 100644 --- a/tests/Console/generators/PrinterTest.php +++ b/tests/Console/generators/PrinterTest.php @@ -72,7 +72,7 @@ public function test_make_function() { ->addComment( '' ) // For some reason these rules need to be disabled by the generated code // doesn't have any issues. - ->addComment( 'phpcs:disable WordPress.WhiteSpace.PrecisionAlignment.Found' ) + ->addComment( 'phpcs:disable WordPress.WhiteSpace.PrecisionAlignment.Found, Universal.WhiteSpace.PrecisionAlignment.Found' ) ->addComment( 'phpcs:disable Generic.WhiteSpace.ScopeIndent.Incorrect' ) ->addComment( '' ) ->addComment( '@package App' ) @@ -112,9 +112,10 @@ protected function lint_code( PhpFile $file, string $file_name ) { if ( 0 !== $exit_code ) { echo "Output from phpcs:\n"; dump( $output ); + echo "File output:\n"; + dump( $code ); } $this->assertEquals( 0, $exit_code, 'phpcs exit code should be 0 for no errors.' ); - } }