diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index cda56180f..357279bdf 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -11,7 +11,10 @@ on: jobs: coding-standards: uses: alleyinteractive/.github/.github/workflows/php-coding-standards.yml@main + with: + php: 8.1 code-quality: uses: alleyinteractive/.github/.github/workflows/php-code-quality.yml@main with: command: "validate-monorepo" + 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 a26786f8f..935009eeb 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,8 @@ "symfony/string": "^6.0", "symfony/var-dumper": "^6.0", "vlucas/phpdotenv": "^5.5", - "voku/portable-ascii": "^2.0" + "voku/portable-ascii": "^2.0", + "wp-coding-standards/wpcs": "dev-php-8-1 as 2.3.x-dev" }, "require-dev": { "alleyinteractive/alley-coding-standards": "^1.0", @@ -128,6 +129,12 @@ ], "validate-monorepo": "monorepo-builder validate --ansi" }, + "repositories": [ + { + "type": "vcs", + "url": "https://github.com/alleyinteractive/WordPress-Coding-Standards" + } + ], "minimum-stability": "dev", "prefer-stable": true } diff --git a/src/mantle/database/model/class-model.php b/src/mantle/database/model/class-model.php index e33493923..95f656adc 100644 --- a/src/mantle/database/model/class-model.php +++ b/src/mantle/database/model/class-model.php @@ -573,7 +573,7 @@ public function to_array(): array { * * @return array */ - 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 8a7635182..71470925c 100644 --- a/src/mantle/database/pagination/class-paginator.php +++ b/src/mantle/database/pagination/class-paginator.php @@ -483,7 +483,7 @@ public function to_array(): array { * * @return array */ - public function jsonSerialize() { + public function jsonSerialize(): mixed { return $this->to_array(); } @@ -503,7 +503,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 +513,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 +524,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; } diff --git a/src/mantle/http/class-request.php b/src/mantle/http/class-request.php index 5e27bc167..5a536e3cc 100644 --- a/src/mantle/http/class-request.php +++ b/src/mantle/http/class-request.php @@ -466,10 +466,10 @@ public function offsetExists( mixed $offset ): bool { /** * Get the value at the given offset. * - * @param string $offset + * @param mixed $offset * @return mixed */ - public function offsetGet( $offset ) { + public function offsetGet( mixed $offset ): mixed { return $this->__get( $offset ); } diff --git a/src/mantle/support/class-collection.php b/src/mantle/support/class-collection.php index 7bbbcc1e3..1d3e87b16 100644 --- a/src/mantle/support/class-collection.php +++ b/src/mantle/support/class-collection.php @@ -595,10 +595,10 @@ public function implode( $value, $glue = null ) { $first = $this->first(); if ( is_array( $first ) || is_object( $first ) ) { - return implode( $glue, $this->pluck( $value )->all() ); + return implode( $glue ?? '', $this->pluck( $value )->all() ); } - return implode( $value, $this->items ); + return implode( $value ?? '', $this->items ); } /** diff --git a/src/mantle/support/class-str.php b/src/mantle/support/class-str.php index 987f03b7c..5cbd5bc6e 100644 --- a/src/mantle/support/class-str.php +++ b/src/mantle/support/class-str.php @@ -229,7 +229,7 @@ public static function contains( $haystack, $needles ) { */ public static function ends_with( $haystack, $needles ) { foreach ( (array) $needles as $needle ) { - if ( substr( $haystack, - strlen( $needle ) ) === (string) $needle ) { + if ( '' !== (string) $needle && str_ends_with( $haystack, (string) $needle ) ) { return true; } } diff --git a/src/mantle/support/traits/trait-enumerates-values.php b/src/mantle/support/traits/trait-enumerates-values.php index 72b38933b..703f8cfe3 100644 --- a/src/mantle/support/traits/trait-enumerates-values.php +++ b/src/mantle/support/traits/trait-enumerates-values.php @@ -756,7 +756,7 @@ function ( $value ) { * * @return array */ - 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/helpers/test-helpers-array.php b/tests/helpers/test-helpers-array.php index e68fd9103..9cefe50fa 100644 --- a/tests/helpers/test-helpers-array.php +++ b/tests/helpers/test-helpers-array.php @@ -323,29 +323,29 @@ public function testDataSetWithDoubleStar() { class SupportTestArrayAccess implements ArrayAccess { - protected $attributes = []; + protected array $attributes = []; - public function __construct($attributes = []) + public function __construct(array $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 12e00485a..66d4c0aa4 100644 --- a/tests/support/test-collection.php +++ b/tests/support/test-collection.php @@ -4406,22 +4406,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]); } @@ -4442,14 +4442,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'; }