Skip to content

Commit

Permalink
Finishing upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
srtfisher committed Sep 13, 2024
1 parent 9a26392 commit 8382e09
Show file tree
Hide file tree
Showing 35 changed files with 70 additions and 62 deletions.
1 change: 1 addition & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<exclude name="Generic.Commenting.DocComment.MissingShort" />
<exclude name="Squiz.Commenting.VariableComment.MissingVar" />
<exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.Found" />
<exclude name="Generic.CodeAnalysis.AssignmentInCondition.Found" />
</rule>

<rule ref="Generic.Arrays.DisallowLongArraySyntax" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/mantle/assets/class-asset-service-provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/mantle/container/class-container.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand Down Expand Up @@ -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 ] );
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/mantle/database/model/class-model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand Down
14 changes: 7 additions & 7 deletions src/mantle/filesystem/class-filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
} )();
}

Expand All @@ -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
} )();
}

Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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
}

/**
Expand Down Expand Up @@ -602,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;
Expand Down
4 changes: 2 additions & 2 deletions src/mantle/framework/console/class-config-cache-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand All @@ -76,7 +76,7 @@ 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' );
$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();

Expand Down
5 changes: 3 additions & 2 deletions src/mantle/framework/console/class-hook-usage-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand Down
2 changes: 1 addition & 1 deletion src/mantle/framework/events/class-events-manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/mantle/framework/manifest/class-model-manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/mantle/framework/manifest/class-package-manifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/mantle/http/class-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
}

/**
Expand Down Expand Up @@ -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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}

Expand Down
2 changes: 1 addition & 1 deletion src/mantle/http/routing/class-entity-router.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}]" );
}

Expand Down
6 changes: 3 additions & 3 deletions src/mantle/http/routing/class-route-registrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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." );
}

Expand Down Expand Up @@ -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 );
}
Expand Down
4 changes: 2 additions & 2 deletions src/mantle/http/routing/class-router.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand All @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion src/mantle/http/view/class-view-finder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ] );
}
Expand Down
4 changes: 2 additions & 2 deletions src/mantle/queue/providers/wordpress/class-provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
),
),
Expand Down
2 changes: 1 addition & 1 deletion src/mantle/scheduling/class-event.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,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 );
}

/**
Expand Down
10 changes: 5 additions & 5 deletions src/mantle/support/class-collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,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();
}

Expand Down Expand Up @@ -221,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() ) );
Expand Down Expand Up @@ -384,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;
}

/**
Expand Down Expand Up @@ -1055,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 ) {
Expand Down
2 changes: 1 addition & 1 deletion src/mantle/support/class-pipeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ protected function carry() {
} catch ( Throwable $e ) {
return $this->handle_exception( $passable, $e );
}
}; // phpcs:disable Generic.CodeAnalysis.EmptyPHPStatement.SemicolonWithoutCodeDetected
}; // phpcs:ignore Generic.CodeAnalysis.EmptyPHPStatement.SemicolonWithoutCodeDetected
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/mantle/support/class-pluralizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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 );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/mantle/support/class-service-provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/mantle/support/class-str.php
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ 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 ) ] ) )
->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( '' );
}

Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/mantle/support/helpers/helpers-array.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) {
Expand Down
2 changes: 1 addition & 1 deletion src/mantle/support/helpers/helpers-general.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Loading

0 comments on commit 8382e09

Please sign in to comment.