diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index c3364073f..dee306e13 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 ad4056f02..9f4d00270 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 diff --git a/composer.json b/composer.json index c0f72f30e..d5ef48714 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", @@ -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" diff --git a/src/mantle/config/class-repository.php b/src/mantle/config/class-repository.php index aa8e733fa..9d1513fcb 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 ): mixed { 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/container/class-container.php b/src/mantle/container/class-container.php index b55f2bc50..5f5394ddb 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/factory/class-factory.php b/src/mantle/database/factory/class-factory.php index d6079fa67..477b661cf 100644 --- a/src/mantle/database/factory/class-factory.php +++ b/src/mantle/database/factory/class-factory.php @@ -245,48 +245,41 @@ 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( $offset ) { + public function offsetExists( mixed $offset ): bool { return isset( $this->definitions[ $offset ] ); } /** * Get the value of the given offset. * - * @param string $offset - * + * @param mixed $offset Offset to retrieve. * @return mixed */ - public function offsetGet( $offset ) { + public function offsetGet( mixed $offset ): mixed { return $this->make( $offset ); } /** * 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( $offset, $value ) { - $this->define( - $offset, // phpcs:ignore - $value - ); + public function offsetSet( mixed $offset, mixed $value ): void { + $this->define( $offset, $value ); } /** * Unset the value at the given offset. * - * @param string $offset - * + * @param mixed $offset Offset to unset. * @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 7842e726f..03886f1bc 100644 --- a/src/mantle/database/model/class-model.php +++ b/src/mantle/database/model/class-model.php @@ -314,39 +314,39 @@ 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( $offset ): bool { + public function offsetExists( mixed $offset ): bool { return null !== $this->get( $offset ); } /** * Get data by the offset. * - * @param string $offset Array offset. + * @param mixed $offset Array offset. * @return mixed */ - public function offsetGet( $offset ) { + public function offsetGet( mixed $offset ): mixed { return $this->get( $offset ); } /** * 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( $offset, $value ) { - return $this->set( $offset, $value ); + public function offsetSet( mixed $offset, mixed $value ): void { + $this->set( $offset, $value ); } /** * Unset data by offset. * - * @param string $offset Offset to unset. + * @param mixed $offset Offset to unset. */ - public function offsetUnset( $offset ) { + public function offsetUnset( mixed $offset ): void { $this->set( $offset, null ); unset( $this->relations[ $offset ] ); } @@ -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 31d0604c0..5d7ee4e23 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 * @@ -481,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(); } @@ -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-arr.php b/src/mantle/support/class-arr.php index e32fa0f2c..0cce141b0 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 0dab38588..40795f900 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; @@ -17,6 +15,7 @@ use Mantle\Database\Model; use function Mantle\Support\Helpers\value; use stdClass; +use Traversable; /** * Collection @@ -93,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() { - return new LazyCollection( $this->items ); + throw new \RuntimeException( 'Lazy collections are not supported at this time. ' ); // phpcs:ignore } /** @@ -1091,7 +1090,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 +1295,7 @@ public function pad( $size, $value ) { * * @return \ArrayIterator */ - public function getIterator() { + public function getIterator(): Traversable { return new ArrayIterator( $this->items ); } @@ -1305,7 +1304,7 @@ public function getIterator() { * * @return int */ - public function count() { + public function count(): int { return count( $this->items ); } @@ -1336,7 +1335,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 ); } @@ -1346,7 +1345,7 @@ public function offsetExists( $key ) { * @param mixed $key * @return mixed */ - public function offsetGet( $key ) { + public function offsetGet( mixed $key ): mixed { return $this->items[ $key ]; } @@ -1357,7 +1356,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 +1370,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/support/traits/trait-enumerates-values.php b/src/mantle/support/traits/trait-enumerates-values.php index 3345fc0ac..9ff8ca66a 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/src/mantle/testing/class-assertable-json-string.php b/src/mantle/testing/class-assertable-json-string.php index 651f7f230..7c6974ec4 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 e68fd9103..fe3242f72 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 e4f044c8d..970c33002 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]); } @@ -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'; }