Skip to content

Commit

Permalink
Adding PHP 8.1 Support (#388)
Browse files Browse the repository at this point in the history
* Starting pass at phpstan on database

* Contd work

* Continued work for database

* Starting work on collection

* Finishing collections

* PHPSTAN on interface

* Wrapping up for now

* Wrapping up phpstan for support

* Enable for scheduling

* PHPStan support for queue

* PHPStan on HTTP

* Adding support for PHP 8.1
  • Loading branch information
srtfisher committed May 19, 2023
1 parent d8a9ff8 commit a2646d5
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 25 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
}
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 @@ -573,7 +573,7 @@ public function to_array(): array {
*
* @return array
*/
public function jsonSerialize() {
public function jsonSerialize(): mixed {
return $this->to_array();
}

Expand Down
8 changes: 4 additions & 4 deletions src/mantle/database/pagination/class-paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ public function to_array(): array {
*
* @return array
*/
public function jsonSerialize() {
public function jsonSerialize(): mixed {
return $this->to_array();
}

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

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

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

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

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

/**
Expand Down
2 changes: 1 addition & 1 deletion src/mantle/support/class-str.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/mantle/support/traits/trait-enumerates-values.php
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,7 @@ function ( $value ) {
*
* @return array<TKey, TValue>
*/
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 ) {
Expand Down
12 changes: 6 additions & 6 deletions tests/helpers/test-helpers-array.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down
12 changes: 6 additions & 6 deletions tests/support/test-collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand All @@ -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';
}
Expand Down

0 comments on commit a2646d5

Please sign in to comment.