Skip to content

Commit

Permalink
Fix PHP 8.1 compatibility (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
spawnia authored Feb 2, 2022
1 parent e60fa0d commit f522bc6
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 40 deletions.
26 changes: 25 additions & 1 deletion .github/workflows/autoformat.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
name: "Autoformat"

on:
push:
branches:
- '*'

jobs:
composer-normalize:
Expand All @@ -22,3 +23,26 @@ jobs:
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Normalize composer.json

php-cs-fixer:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}

- uses: shivammathur/setup-php@v2
with:
coverage: none
extensions: mbstring
php-version: 7.4

- run: composer install --no-interaction --no-progress --no-suggest

- run: vendor/bin/php-cs-fixer fix

- run: git pull

- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Apply php-cs-fixer changes
37 changes: 3 additions & 34 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ on:
name: "Continuous Integration"

jobs:
coding-standards:
name: "Coding Standards"
composer-validate:
name: "Composer Validate"

runs-on: ubuntu-latest

Expand All @@ -21,38 +21,6 @@ jobs:
- name: "Validate composer.json and composer.lock"
run: php7.4 /usr/bin/composer validate

- name: "Install locked dependencies with composer"
run: php7.4 /usr/bin/composer install --no-interaction --no-progress

php-cs-fixer:
name: "Fix PHP codestyle with php-cs-fixer"

runs-on: ubuntu-latest

steps:
- name: "Checkout"
uses: actions/checkout@v2
with:
ref: ${{ github.head_ref }}

- name: "Install PHP with extensions"
uses: shivammathur/setup-php@v2
with:
coverage: none
extensions: mbstring
php-version: 7.4

- name: "Install locked dependencies with composer"
run: composer install --no-interaction --no-progress --no-suggest

- name: "Run php-cs-fixer"
run: vendor/bin/php-cs-fixer fix

- name: "Commit fixes"
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Apply php-cs-fixer changes

static-code-analysis:
name: "Static Code Analysis"

Expand All @@ -78,6 +46,7 @@ jobs:
php-version:
- 7.4
- 8.0
- 8.1

dependencies:
- lowest
Expand Down
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
"mockery/mockery": "Used in Operation::mock()"
},
"config": {
"allow-plugins": {
"ergebnis/composer-normalize": true,
"phpstan/extension-installer": true,
"infection/extension-installer": true
},
"platform": {
"php": "7.4.15"
},
Expand Down
10 changes: 5 additions & 5 deletions src/ObjectLike.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ abstract protected function converters(): array;
*/
public static function fromStdClass(stdClass $data): self
{
static $instance;
$instance ??= new static();

return $instance->fromGraphQL($data);
return (new static())->fromGraphQL($data);

This comment has been minimized.

Copy link
@simPod

simPod Feb 16, 2022

Collaborator

I just stumbled upon this. Why did it stop working? Can you explain pls?

This comment has been minimized.

Copy link
@spawnia

spawnia Feb 17, 2022

Author Owner

It always returned the instance that was cached in the first call to the method from a child class. Apparently static variables are now bound lexically and not to inheriting classes.

}

/**
Expand Down Expand Up @@ -87,7 +84,10 @@ public function toGraphQL($value): stdClass
return $serializable;
}

public function fromGraphQL($value)
/**
* @return static
*/
public function fromGraphQL($value): self
{
if (! $value instanceof stdClass) {
throw new InvalidArgumentException('Expected stdClass, got: ' . gettype($value));
Expand Down

0 comments on commit f522bc6

Please sign in to comment.