From 2df8839910842251097f3ecc7e26b2c237e58155 Mon Sep 17 00:00:00 2001 From: Sean Fisher Date: Thu, 5 Jan 2023 22:28:28 -0500 Subject: [PATCH 1/5] Enabling PHP 8.1 for testing --- .github/workflows/coding-standards.yml | 2 ++ .github/workflows/tests.yml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index c3364073..dee306e1 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -11,3 +11,5 @@ on: jobs: coding-standards: uses: alleyinteractive/.github/.github/workflows/php-coding-standards.yml@main + with: + php: 8.1 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index ad4056f0..9f4d0027 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,7 +12,7 @@ jobs: php-tests: strategy: matrix: - php: [8.0] + php: [8.0, 8.1] wordpress: ["latest"] multisite: [true, false] uses: alleyinteractive/.github/.github/workflows/php-tests.yml@main From e8d8ec2279b144b052e74fe539f6f4613c7f7942 Mon Sep 17 00:00:00 2001 From: Sean Fisher Date: Thu, 5 Jan 2023 22:30:59 -0500 Subject: [PATCH 2/5] Switching to 1.0 only for coding standards --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c0f72f30..95372777 100644 --- a/composer.json +++ b/composer.json @@ -42,7 +42,7 @@ "voku/portable-ascii": "^1.4" }, "require-dev": { - "alleyinteractive/alley-coding-standards": "^0.3 || ^0.4 || ^1.0", + "alleyinteractive/alley-coding-standards": "^1.0", "mockery/mockery": "^1.3", "phpunit/phpunit": "^9.3.3", "symplify/monorepo-builder": "^10.1" From 8973d11919bf58adaf09492deb46cc6e8103e4d0 Mon Sep 17 00:00:00 2001 From: Sean Fisher Date: Thu, 5 Jan 2023 22:45:22 -0500 Subject: [PATCH 3/5] Fixes for arrayaccess --- src/mantle/config/class-repository.php | 8 ++++---- src/mantle/database/factory/class-factory.php | 13 +++++-------- src/mantle/database/model/class-model.php | 10 +++++----- .../database/pagination/class-paginator.php | 15 +++++++++++---- src/mantle/support/class-collection.php | 15 ++++++++------- .../testing/class-assertable-json-string.php | 6 +++--- tests/helpers/test-helpers-array.php | 8 ++++---- tests/support/test-collection.php | 8 ++++---- 8 files changed, 44 insertions(+), 39 deletions(-) diff --git a/src/mantle/config/class-repository.php b/src/mantle/config/class-repository.php index aa8e733f..f88de502 100644 --- a/src/mantle/config/class-repository.php +++ b/src/mantle/config/class-repository.php @@ -83,7 +83,7 @@ public function all(): array { * @param mixed $offset Offset to retrieve. * @return bool */ - public function offsetExists( $offset ): bool { + public function offsetExists( mixed $offset ): bool { return $this->has( $offset ); } @@ -93,7 +93,7 @@ public function offsetExists( $offset ): bool { * @param mixed $offset Offset to retrieve. * @return mixed */ - public function offsetGet( $offset ) { + public function offsetGet( mixed $offset ) { return $this->get( $offset ); } @@ -103,7 +103,7 @@ public function offsetGet( $offset ) { * @param mixed $offset Offset to set. * @param mixed $value Value to set. */ - public function offsetSet( $offset, $value ) { + public function offsetSet( mixed $offset, mixed $value ): void { $this->set( $offset, $value ); } @@ -112,7 +112,7 @@ public function offsetSet( $offset, $value ) { * * @param mixed $offset Offset to unset. */ - public function offsetUnset( $offset ) { + public function offsetUnset( mixed $offset ): void { $this->set( $offset, null ); } } diff --git a/src/mantle/database/factory/class-factory.php b/src/mantle/database/factory/class-factory.php index d6079fa6..e84c9d3d 100644 --- a/src/mantle/database/factory/class-factory.php +++ b/src/mantle/database/factory/class-factory.php @@ -249,7 +249,7 @@ public function load( $path ) { * * @return bool */ - public function offsetExists( $offset ) { + public function offsetExists( mixed $offset ): bool { return isset( $this->definitions[ $offset ] ); } @@ -260,7 +260,7 @@ public function offsetExists( $offset ) { * * @return mixed */ - public function offsetGet( $offset ) { + public function offsetGet( mixed $offset ): mixed { return $this->make( $offset ); } @@ -272,11 +272,8 @@ public function offsetGet( $offset ) { * * @return void */ - public function offsetSet( $offset, $value ) { - $this->define( - $offset, // phpcs:ignore - $value - ); + public function offsetSet( mixed $offset, mixed $value ): void { + $this->define( $offset, $value ); } /** @@ -286,7 +283,7 @@ public function offsetSet( $offset, $value ) { * * @return void */ - public function offsetUnset( $offset ) { + public function offsetUnset( mixed $offset ): void { unset( $this->definitions[ $offset ] ); } } diff --git a/src/mantle/database/model/class-model.php b/src/mantle/database/model/class-model.php index 7842e726..651f06ea 100644 --- a/src/mantle/database/model/class-model.php +++ b/src/mantle/database/model/class-model.php @@ -317,7 +317,7 @@ public static function get_object_name(): ?string { * @param string $offset Array offset. * @return bool */ - public function offsetExists( $offset ): bool { + public function offsetExists( mixed $offset ): bool { return null !== $this->get( $offset ); } @@ -327,7 +327,7 @@ public function offsetExists( $offset ): bool { * @param string $offset Array offset. * @return mixed */ - public function offsetGet( $offset ) { + public function offsetGet( mixed $offset ): mixed { return $this->get( $offset ); } @@ -337,8 +337,8 @@ public function offsetGet( $offset ) { * @param string $offset Offset name. * @param mixed $value Value to set. */ - public function offsetSet( $offset, $value ) { - return $this->set( $offset, $value ); + public function offsetSet( mixed $offset, mixed $value ): void { + $this->set( $offset, $value ); } /** @@ -346,7 +346,7 @@ public function offsetSet( $offset, $value ) { * * @param string $offset Offset to unset. */ - public function offsetUnset( $offset ) { + public function offsetUnset( mixed $offset ): void { $this->set( $offset, null ); unset( $this->relations[ $offset ] ); } diff --git a/src/mantle/database/pagination/class-paginator.php b/src/mantle/database/pagination/class-paginator.php index 31d0604c..05060e97 100644 --- a/src/mantle/database/pagination/class-paginator.php +++ b/src/mantle/database/pagination/class-paginator.php @@ -26,6 +26,13 @@ * Paginator for query results. */ class Paginator implements Arrayable, ArrayAccess, Countable, Jsonable, JsonSerializable, Htmlable, PaginatorContract { + /** + * Query parameters to append. + * + * @var array + */ + public $append = []; + /** * Current page number * @@ -503,7 +510,7 @@ public function to_json( $options = 0 ) { * @param mixed $offset Array offset. * @return bool */ - public function offsetExists( $offset ): bool { + public function offsetExists( mixed $offset ): bool { return isset( $this->items[ $offset ] ); } @@ -513,7 +520,7 @@ public function offsetExists( $offset ): bool { * @param mixed $offset Offset to get. * @return mixed */ - public function offsetGet( $offset ) { + public function offsetGet( mixed $offset ): mixed { return $this->items[ $offset ]; } @@ -524,7 +531,7 @@ public function offsetGet( $offset ) { * @param mixed $value Value to set. * @return void */ - public function offsetSet( $offset, $value ): void { + public function offsetSet( mixed $offset, mixed $value ): void { $this->items[ $offset ] = $value; } @@ -534,7 +541,7 @@ public function offsetSet( $offset, $value ): void { * @param mixed $offset Offset to delete. * @return void */ - public function offsetUnset( $offset ): void { + public function offsetUnset( mixed $offset ): void { unset( $this->items[ $offset ] ); } diff --git a/src/mantle/support/class-collection.php b/src/mantle/support/class-collection.php index 0dab3858..8b2a85a3 100644 --- a/src/mantle/support/class-collection.php +++ b/src/mantle/support/class-collection.php @@ -17,6 +17,7 @@ use Mantle\Database\Model; use function Mantle\Support\Helpers\value; use stdClass; +use Traversable; /** * Collection @@ -96,7 +97,7 @@ public function all() { * @return \Mantle\Support\LazyCollection */ public function lazy() { - return new LazyCollection( $this->items ); + throw new \RuntimeException( 'Lazy collections are not supported at this time. '); } /** @@ -1091,7 +1092,7 @@ public function sort( $callback = null ) { $callback && is_callable( $callback ) ? uasort( $items, $callback ) - : asort( $items, $callback ); + : asort( $items, $callback ?? SORT_REGULAR ); return new static( $items ); } @@ -1296,7 +1297,7 @@ public function pad( $size, $value ) { * * @return \ArrayIterator */ - public function getIterator() { + public function getIterator(): Traversable { return new ArrayIterator( $this->items ); } @@ -1305,7 +1306,7 @@ public function getIterator() { * * @return int */ - public function count() { + public function count(): int { return count( $this->items ); } @@ -1336,7 +1337,7 @@ public function to_base() { * @param mixed $key * @return bool */ - public function offsetExists( $key ) { + public function offsetExists( mixed $key ): bool { return array_key_exists( $key, $this->items ); } @@ -1357,7 +1358,7 @@ public function offsetGet( $key ) { * @param mixed $value * @return void */ - public function offsetSet( $key, $value ) { + public function offsetSet( mixed $key, mixed $value ): void { if ( is_null( $key ) ) { $this->items[] = $value; } else { @@ -1371,7 +1372,7 @@ public function offsetSet( $key, $value ) { * @param string $key * @return void */ - public function offsetUnset( $key ) { + public function offsetUnset( $key ): void { unset( $this->items[ $key ] ); } } diff --git a/src/mantle/testing/class-assertable-json-string.php b/src/mantle/testing/class-assertable-json-string.php index 651f7f23..7c6974ec 100644 --- a/src/mantle/testing/class-assertable-json-string.php +++ b/src/mantle/testing/class-assertable-json-string.php @@ -321,7 +321,7 @@ public function count(): int { * @param mixed $offset * @return bool */ - public function offsetExists( $offset ): bool { + public function offsetExists( mixed $offset ): bool { return isset( $this->decoded[ $offset ] ); } @@ -342,7 +342,7 @@ public function offsetGet( $offset ): mixed { * @param mixed $value * @return void */ - public function offsetSet($offset, $value): void { + public function offsetSet( mixed $offset, mixed $value): void { $this->decoded[ $offset ] = $value; } @@ -352,7 +352,7 @@ public function offsetSet($offset, $value): void { * @param string $offset * @return void */ - public function offsetUnset($offset): void { + public function offsetUnset( mixed $offset ): void { unset( $this->decoded[ $offset ] ); } } diff --git a/tests/helpers/test-helpers-array.php b/tests/helpers/test-helpers-array.php index e68fd910..fe3242f7 100644 --- a/tests/helpers/test-helpers-array.php +++ b/tests/helpers/test-helpers-array.php @@ -330,22 +330,22 @@ public function __construct($attributes = []) $this->attributes = $attributes; } - public function offsetExists($offset) + public function offsetExists( mixed $offset ): bool { return array_key_exists($offset, $this->attributes); } - public function offsetGet($offset) + public function offsetGet( mixed $offset ): mixed { return $this->attributes[$offset]; } - public function offsetSet($offset, $value) + public function offsetSet( mixed $offset, mixed $value ): void { $this->attributes[$offset] = $value; } - public function offsetUnset($offset) + public function offsetUnset( mixed $offset ): void { unset($this->attributes[$offset]); } diff --git a/tests/support/test-collection.php b/tests/support/test-collection.php index e4f044c8..63109495 100644 --- a/tests/support/test-collection.php +++ b/tests/support/test-collection.php @@ -4428,22 +4428,22 @@ public function __construct($arr) $this->arr = $arr; } - public function offsetExists($offset) + public function offsetExists( mixed $offset ): bool { return isset($this->arr[$offset]); } - public function offsetGet($offset) + public function offsetGet( mixed $offset ): mixed { return $this->arr[$offset]; } - public function offsetSet($offset, $value) + public function offsetSet( mixed $offset, mixed $value ): void { $this->arr[$offset] = $value; } - public function offsetUnset($offset) + public function offsetUnset( mixed $offset ): void { unset($this->arr[$offset]); } From 42268a7516074ff117129df6ea67b748bbf11c1a Mon Sep 17 00:00:00 2001 From: Sean Fisher Date: Thu, 5 Jan 2023 22:48:39 -0500 Subject: [PATCH 4/5] PHPCS fixes --- src/mantle/database/factory/class-factory.php | 14 +++++--------- src/mantle/database/model/class-model.php | 10 +++++----- src/mantle/support/class-collection.php | 10 ++++------ 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/mantle/database/factory/class-factory.php b/src/mantle/database/factory/class-factory.php index e84c9d3d..477b661c 100644 --- a/src/mantle/database/factory/class-factory.php +++ b/src/mantle/database/factory/class-factory.php @@ -245,8 +245,7 @@ public function load( $path ) { /** * Determine if the given offset exists. * - * @param string $offset - * + * @param mixed $offset Offset to check on. * @return bool */ public function offsetExists( mixed $offset ): bool { @@ -256,8 +255,7 @@ public function offsetExists( mixed $offset ): bool { /** * Get the value of the given offset. * - * @param string $offset - * + * @param mixed $offset Offset to retrieve. * @return mixed */ public function offsetGet( mixed $offset ): mixed { @@ -267,9 +265,8 @@ public function offsetGet( mixed $offset ): mixed { /** * Set the given offset to the given value. * - * @param string $offset - * @param callable $value - * + * @param mixed $offset Offset to assign the value to. + * @param mixed $value Value to set. * @return void */ public function offsetSet( mixed $offset, mixed $value ): void { @@ -279,8 +276,7 @@ public function offsetSet( mixed $offset, mixed $value ): void { /** * Unset the value at the given offset. * - * @param string $offset - * + * @param mixed $offset Offset to unset. * @return void */ public function offsetUnset( mixed $offset ): void { diff --git a/src/mantle/database/model/class-model.php b/src/mantle/database/model/class-model.php index 651f06ea..e40b7a05 100644 --- a/src/mantle/database/model/class-model.php +++ b/src/mantle/database/model/class-model.php @@ -314,7 +314,7 @@ public static function get_object_name(): ?string { /** * Check if an offset exists. * - * @param string $offset Array offset. + * @param mixed $offset Array offset. * @return bool */ public function offsetExists( mixed $offset ): bool { @@ -324,7 +324,7 @@ public function offsetExists( mixed $offset ): bool { /** * Get data by the offset. * - * @param string $offset Array offset. + * @param mixed $offset Array offset. * @return mixed */ public function offsetGet( mixed $offset ): mixed { @@ -334,8 +334,8 @@ public function offsetGet( mixed $offset ): mixed { /** * Set data by offset. * - * @param string $offset Offset name. - * @param mixed $value Value to set. + * @param mixed $offset Offset name. + * @param mixed $value Value to set. */ public function offsetSet( mixed $offset, mixed $value ): void { $this->set( $offset, $value ); @@ -344,7 +344,7 @@ public function offsetSet( mixed $offset, mixed $value ): void { /** * Unset data by offset. * - * @param string $offset Offset to unset. + * @param mixed $offset Offset to unset. */ public function offsetUnset( mixed $offset ): void { $this->set( $offset, null ); diff --git a/src/mantle/support/class-collection.php b/src/mantle/support/class-collection.php index 8b2a85a3..5ba600d4 100644 --- a/src/mantle/support/class-collection.php +++ b/src/mantle/support/class-collection.php @@ -2,13 +2,11 @@ /** * 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; @@ -94,10 +92,10 @@ public function all() { /** * Get a lazy collection for the items in this collection. * - * @return \Mantle\Support\LazyCollection + * @return void */ public function lazy() { - throw new \RuntimeException( 'Lazy collections are not supported at this time. '); + throw new \RuntimeException( 'Lazy collections are not supported at this time. ' ); // phpcs:ignore } /** From 73934b88289941815dd02424ccc0a784267b5bf7 Mon Sep 17 00:00:00 2001 From: Sean Fisher Date: Thu, 5 Jan 2023 23:09:31 -0500 Subject: [PATCH 5/5] Getting all tests to pass (pass as much as we can) --- composer.json | 2 +- src/mantle/config/class-repository.php | 2 +- src/mantle/container/class-container.php | 4 ++-- src/mantle/database/model/class-model.php | 4 ++-- src/mantle/database/pagination/class-paginator.php | 4 ++-- src/mantle/support/class-arr.php | 2 +- src/mantle/support/class-collection.php | 2 +- src/mantle/support/traits/trait-enumerates-values.php | 4 ++-- tests/support/test-collection.php | 4 ++-- 9 files changed, 14 insertions(+), 14 deletions(-) diff --git a/composer.json b/composer.json index 95372777..d5ef4871 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "laravel/serializable-closure": "^1.2", "league/flysystem": "^1.1", "league/flysystem-cached-adapter": "^1.1", - "monolog/monolog": "^2.7 || ^3.0", + "monolog/monolog": "^2.7", "nesbot/carbon": "^2.53", "nette/php-generator": "^3.6", "nunomaduro/termwind": "^1.14", diff --git a/src/mantle/config/class-repository.php b/src/mantle/config/class-repository.php index f88de502..9d1513fc 100644 --- a/src/mantle/config/class-repository.php +++ b/src/mantle/config/class-repository.php @@ -93,7 +93,7 @@ public function offsetExists( mixed $offset ): bool { * @param mixed $offset Offset to retrieve. * @return mixed */ - public function offsetGet( mixed $offset ) { + public function offsetGet( mixed $offset ): mixed { return $this->get( $offset ); } diff --git a/src/mantle/container/class-container.php b/src/mantle/container/class-container.php index b55f2bc5..5f5394dd 100644 --- a/src/mantle/container/class-container.php +++ b/src/mantle/container/class-container.php @@ -1159,8 +1159,8 @@ public function offsetExists( mixed $key ): bool { * @param mixed $key * @return mixed */ - public function offsetGet( mixed $key ) { - return $this->make( $key ); + public function offsetGet( mixed $key ): mixed { + return $this->make( $key ); } /** diff --git a/src/mantle/database/model/class-model.php b/src/mantle/database/model/class-model.php index e40b7a05..03886f1b 100644 --- a/src/mantle/database/model/class-model.php +++ b/src/mantle/database/model/class-model.php @@ -576,9 +576,9 @@ public function to_json( $options = 0 ): string { /** * Convert the object into something JSON serializable. * - * @return array + * @return mixed */ - public function jsonSerialize() { + public function jsonSerialize(): mixed { return $this->to_array(); } } diff --git a/src/mantle/database/pagination/class-paginator.php b/src/mantle/database/pagination/class-paginator.php index 05060e97..5d7ee4e2 100644 --- a/src/mantle/database/pagination/class-paginator.php +++ b/src/mantle/database/pagination/class-paginator.php @@ -488,9 +488,9 @@ public function to_array(): array { /** * Convert the object into something JSON serializable. * - * @return array + * @return mixed */ - public function jsonSerialize() { + public function jsonSerialize(): mixed { return $this->to_array(); } diff --git a/src/mantle/support/class-arr.php b/src/mantle/support/class-arr.php index e32fa0f2..0cce141b 100644 --- a/src/mantle/support/class-arr.php +++ b/src/mantle/support/class-arr.php @@ -606,7 +606,7 @@ public static function sort_recursive( $array ) { * @return string */ public static function query( $array ) { - return http_build_query( $array, null, '&', PHP_QUERY_RFC3986 ); + return http_build_query( $array, '', '&', PHP_QUERY_RFC3986 ); } /** diff --git a/src/mantle/support/class-collection.php b/src/mantle/support/class-collection.php index 5ba600d4..40795f90 100644 --- a/src/mantle/support/class-collection.php +++ b/src/mantle/support/class-collection.php @@ -1345,7 +1345,7 @@ public function offsetExists( mixed $key ): bool { * @param mixed $key * @return mixed */ - public function offsetGet( $key ) { + public function offsetGet( mixed $key ): mixed { return $this->items[ $key ]; } diff --git a/src/mantle/support/traits/trait-enumerates-values.php b/src/mantle/support/traits/trait-enumerates-values.php index 3345fc0a..9ff8ca66 100644 --- a/src/mantle/support/traits/trait-enumerates-values.php +++ b/src/mantle/support/traits/trait-enumerates-values.php @@ -772,9 +772,9 @@ function ( $value ) { /** * Convert the object into something JSON serializable. * - * @return array + * @return mixed */ - public function jsonSerialize() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid + public function jsonSerialize(): mixed { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid return array_map( function ( $value ) { if ( $value instanceof JsonSerializable ) { diff --git a/tests/support/test-collection.php b/tests/support/test-collection.php index 63109495..970c3300 100644 --- a/tests/support/test-collection.php +++ b/tests/support/test-collection.php @@ -4464,14 +4464,14 @@ public function to_json($options = 0) } class TestJsonSerializeObject implements JsonSerializable { - public function jsonSerialize() + public function jsonSerialize(): mixed { return ['foo' => 'bar']; } } class TestJsonSerializeWithScalarValueObject implements JsonSerializable { - public function jsonSerialize() + public function jsonSerialize(): mixed { return 'foo'; }