Skip to content

Commit

Permalink
Add PHP 8.4, drop PHP 8.1
Browse files Browse the repository at this point in the history
  • Loading branch information
stephank committed Dec 13, 2024
1 parent eba9988 commit 3b4bf95
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 28 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Check

on:
push:
branches: ['3.0']
branches: ['4.0']
pull_request:
branches: ['3.0']
branches: ['4.0']

jobs:

Expand All @@ -14,11 +14,11 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['8.1', '8.2', '8.3']
php: ['8.2', '8.3', '8.4']
steps:

- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -28,10 +28,10 @@ jobs:

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache composer dependencies
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
Expand Down
13 changes: 13 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

$config = new PhpCsFixer\Config();

return $config
->setRules([
'@PSR12' => true,
'@PHP82Migration' => true,
])
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__)
);
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 4.0.0

### PHP support

- Dropped support for PHP `8.1` and lower.
- Added support for PHP `8.4`.
- Removed `DomainObject::propertyIsTraversable`.

## 3.0.0

### PHP support
Expand Down
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
}
},
"require": {
"php": "8.1.* || 8.2.* || 8.3.*"
"php": "8.2 - 8.4"
},
"require-dev": {
"phpstan/phpstan": "1.10.46",
"phpunit/phpunit": "10.4.2",
"squizlabs/php_codesniffer": "3.7.2"
"phpstan/phpstan": "2.0.3",
"phpunit/phpunit": "11.5.1",
"squizlabs/php_codesniffer": "3.11.2",
"friendsofphp/php-cs-fixer": "^3.65"
}
}
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ parameters:
path: tests/AngryBytes/DomainObject/Test/ComposedTest.php

-
message: "#^Parameter \\#2 \\$array of method PHPUnit\\\\Framework\\\\Assert\\:\\:assertArrayHasKey\\(\\) expects array\\|ArrayAccess, mixed given\\.$#"
identifier: argument.type
count: 2
path: tests/AngryBytes/DomainObject/Test/ComposedTest.php

Expand Down
31 changes: 14 additions & 17 deletions src/AngryBytes/DomainObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,37 +116,34 @@ public function toArrayWithProperties(array $properties): array
*/
public function getPropertyValueAsSimple(string $property)
{
if ($this->$property instanceof DomainObject) {
$value = $this->$property;

if ($value instanceof DomainObject) {
// Simple recursion for child DO's
return $this->$property->toArray();
return $value->toArray();
}

if ($this->propertyIsTraversable($property)) {
if ($value instanceof \stdClass) {
$value = (array) $value;
}
if (is_iterable($value)) {
// Property is traversable
$value = [];
$newValue = [];

// Traverse the
foreach ($this->$property as $childKey => $childValue) {
foreach ($value as $childKey => $childValue) {
if ($childValue instanceof DomainObject) {
$value[$childKey] = $childValue->toArray();
$newValue[$childKey] = $childValue->toArray();
} else {
$value[$childKey] = $childValue;
$newValue[$childKey] = $childValue;
}
}

return $value;
return $newValue;
}

// All other properties are returned as is
return $this->$property;
}

/**
* Is a property traversable?
*/
public function propertyIsTraversable(string $property): bool
{
return is_iterable($this->$property) || $this->$property instanceof \stdClass;
return $value;
}

/**
Expand Down

0 comments on commit 3b4bf95

Please sign in to comment.