Skip to content

Commit

Permalink
Merge pull request #44 from compwright/php-84
Browse files Browse the repository at this point in the history
Support PHP 8.4
  • Loading branch information
harikt authored Feb 7, 2025
2 parents 93e5a65 + 4553ae6 commit bd33dc5
Show file tree
Hide file tree
Showing 33 changed files with 362 additions and 228 deletions.
1 change: 1 addition & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ jobs:
- '8.1'
- '8.2'
- '8.3'
- '8.4'
steps:
- name: Checkout
uses: actions/checkout@v1
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"php": "^7.2 || ^8.0"
},
"require-dev": {
"phpstan/phpstan": "^1.0 || ^2.0",
"yoast/phpunit-polyfills": "^1.0.0"
},
"autoload": {
Expand All @@ -28,6 +29,7 @@
}
},
"scripts": {
"analyze": "vendor/bin/phpstan analyse -c phpstan.neon",
"test": "vendor/bin/phpunit"
}
}
12 changes: 12 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
parameters:
level: 8
paths:
- src
- tests
universalObjectCratesClasses:
- Aura\Marshal\Manager
- Aura\Marshal\Entity\GenericEntity
inferPrivatePropertyTypeFromConstructor: true
checkFunctionNameCase: true
checkInternalClassCaseSensitivity: true
treatPhpDocTypesAsCertain: false
4 changes: 2 additions & 2 deletions src/Collection/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Builder implements BuilderInterface
*
* The class to use for new instances.
*
* @var string
* @var class-string<GenericCollection>
*
*/
protected $class = 'Aura\Marshal\Collection\GenericCollection';
Expand All @@ -32,7 +32,7 @@ class Builder implements BuilderInterface
*
* Creates a new collection object.
*
* @param array $data Data to load into the collection.
* @param array<int|string, mixed> $data Data to load into the collection.
*
* @return GenericCollection
*
Expand Down
6 changes: 3 additions & 3 deletions src/Collection/BuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
*/
namespace Aura\Marshal\Collection;

use Aura\Marshal\Type\GenericType;

/**
*
* An interface for collection builder objects.
Expand All @@ -25,7 +23,9 @@ interface BuilderInterface
*
* Creates a new collection object.
*
* @param array $data Data to load into the collection.
* @param array<int|string, mixed> $data Data to load into the collection.
*
* @return GenericCollection
*
*/
public function newInstance(array $data);
Expand Down
2 changes: 1 addition & 1 deletion src/Collection/GenericCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class GenericCollection extends Data implements ToArrayInterface
*
* @param string $field The field name to retrieve values for.
*
* @return array
* @return array<int|string, mixed>
*
*/
public function getFieldValues($field)
Expand Down
7 changes: 5 additions & 2 deletions src/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
* entities.
*
* @package Aura.Marshal
*
* @implements \ArrayAccess<int|string, mixed>
* @implements \IteratorAggregate<int|string, mixed>
*
*/
class Data implements \ArrayAccess, \Countable, \IteratorAggregate
Expand All @@ -32,7 +35,7 @@ class Data implements \ArrayAccess, \Countable, \IteratorAggregate
*
* Key-value pairs of data.
*
* @var array
* @var array<int|string, GenericEntity|mixed>
*
*/
protected $data = [];
Expand All @@ -41,7 +44,7 @@ class Data implements \ArrayAccess, \Countable, \IteratorAggregate
*
* Constructor.
*
* @param array $data The data for this object.
* @param array<int|string, mixed> $data The data for this object.
*
*/
public function __construct(array $data = [])
Expand Down
10 changes: 6 additions & 4 deletions src/DataIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* An object to allow iteration over the elements of a Data object.
*
* @package Aura.Marshal
*
* @implements \Iterator<int|string, mixed>
*
*/
class DataIterator implements \Iterator
Expand All @@ -25,7 +27,7 @@ class DataIterator implements \Iterator
*
* The data over which we are iterating.
*
* @var ArrayAccess
* @var ArrayAccess<int|string, mixed>
*
*/
protected $data;
Expand All @@ -34,7 +36,7 @@ class DataIterator implements \Iterator
*
* The keys to iterate over in the Data object.
*
* @var array
* @var array<int|string>
*
*/
protected $keys;
Expand All @@ -52,9 +54,9 @@ class DataIterator implements \Iterator
*
* Constructor.
*
* @param ArrayAccess $data The Data object over which to iterate.
* @param ArrayAccess<int|string, mixed> $data The Data object over which to iterate.
*
* @param array $keys The keys in the Data object.
* @param array<int|string> $keys The keys in the Data object.
*
*/
public function __construct(ArrayAccess $data, array $keys = [])
Expand Down
6 changes: 2 additions & 4 deletions src/Entity/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
*/
namespace Aura\Marshal\Entity;

use Aura\Marshal\Lazy\BuilderInterface as LazyBuilderInterface;

/**
*
* Creates a new entity object for a type.
Expand All @@ -25,7 +23,7 @@ class Builder implements BuilderInterface
*
* The class to use for new instances.
*
* @var string
* @var class-string<GenericEntity>
*
*/
protected $class = 'Aura\Marshal\Entity\GenericEntity';
Expand All @@ -34,7 +32,7 @@ class Builder implements BuilderInterface
*
* Creates a new entity object.
*
* @param array|object $data Data to load into the entity.
* @param array<int|string, mixed> $data Data to load into the entity.
*
* @return GenericEntity
*
Expand Down
6 changes: 3 additions & 3 deletions src/Entity/BuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
*/
namespace Aura\Marshal\Entity;

use Aura\Marshal\Type\GenericType;

/**
*
* An interface for EntityBuilder objects.
Expand All @@ -25,7 +23,9 @@ interface BuilderInterface
*
* Creates a new entity object.
*
* @param array $data Data to load into the entity.
* @param array<int|string, mixed> $data Data to load into the entity.
*
* @return GenericEntity
*
*/
public function newInstance(array $data);
Expand Down
1 change: 1 addition & 0 deletions src/Entity/GenericEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* @package Aura.Marshal
*
*/
#[\AllowDynamicProperties]
class GenericEntity extends Data implements ToArrayInterface
{
use MagicArrayAccessTrait;
Expand Down
4 changes: 2 additions & 2 deletions src/Lazy/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Builder implements BuilderInterface
*
* The class to use for new instances.
*
* @var string
* @var class-string<LazyInterface>
*
*/
protected $class = 'Aura\Marshal\Lazy\GenericLazy';
Expand All @@ -37,7 +37,7 @@ class Builder implements BuilderInterface
* @param RelationInterface $relation The relationship object between the
* native and foreign types.
*
* @return Lazy
* @return LazyInterface
*
*/
public function newInstance(RelationInterface $relation)
Expand Down
2 changes: 1 addition & 1 deletion src/Lazy/BuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface BuilderInterface
* @param RelationInterface $relation The relationship object between the
* native and foreign types.
*
* @return Lazy
* @return LazyInterface
*
*/
public function newInstance(RelationInterface $relation);
Expand Down
27 changes: 17 additions & 10 deletions src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Manager
* An array of type definition arrays, which are converted to type
* objects as you request them.
*
* @var array
* @var array<string, GenericType|array<string, mixed>>
*
*/
protected $types;
Expand Down Expand Up @@ -139,7 +139,7 @@ class Manager
*
* @param RelationBuilder $relation_builder A builder for relation objects.
*
* @param array $types Type definitions.
* @param array<string, array<string, mixed>> $types Type definitions.
*
*/
public function __construct(
Expand All @@ -158,7 +158,7 @@ public function __construct(
*
* @param string $name The name to use for the type.
*
* @param array $info An array of type definition information.
* @param array<string, mixed> $info An array of type definition information.
*
* @return void
*
Expand All @@ -180,7 +180,7 @@ public function setType($name, array $info)
*
* @param string $name The name for the relation.
*
* @param array $info The relation information.
* @param array<string, mixed> $info The relation information.
*
* @return void
*
Expand Down Expand Up @@ -225,7 +225,10 @@ public function __get($name)
$this->buildType($name);
}

return $this->types[$name];
/** @var GenericType $type */
$type = $this->types[$name];

return $type;
}

/**
Expand All @@ -244,13 +247,17 @@ public function __get($name)
*
* @param string $name The type name to build.
*
* @return GenericType
* @return void
*
*/
protected function buildType($name)
{
// instantiate and retain the type object. if we don't do this before
// building related fields, then we enter a race condition.
/**
* Instantiate and retain the type object. if we don't do this before
* building related fields, then we enter a race condition.
*
* @var array<string, mixed> $info
*/
$info = $this->types[$name];
$this->types[$name] = $this->type_builder->newInstance($info);

Expand All @@ -266,7 +273,7 @@ protected function buildType($name)
*
* Returns the names of all types in the manager.
*
* @return array
* @return string[]
*
*/
public function getTypes()
Expand All @@ -278,7 +285,7 @@ public function getTypes()
*
* Unsets all entities in all types in the manager.
*
* @return null
* @return void
*
*/
public function clear()
Expand Down
16 changes: 8 additions & 8 deletions src/Relation/AbstractRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ abstract class AbstractRelation
*
* The through type object.
*
* @var GenericType
* @var ?GenericType
*
*/
protected $through;
Expand All @@ -73,7 +73,7 @@ abstract class AbstractRelation
* Native and foreign entities are mapped to each other through this
* association type.
*
* @var string
* @var ?string
*
*/
protected $through_type;
Expand All @@ -83,7 +83,7 @@ abstract class AbstractRelation
* The field name for the native side of the association mapping in the
* "through" type.
*
* @var string
* @var ?string
*
*/
protected $through_native_field;
Expand All @@ -93,7 +93,7 @@ abstract class AbstractRelation
* The field name for the foreign side of the association mapping in the
* "through" type.
*
* @var string
* @var ?string
*
*/
protected $through_foreign_field;
Expand All @@ -112,12 +112,12 @@ abstract class AbstractRelation
*
* @param GenericType $through The through type object.
*
* @param string $through_type The manager name of the through type.
* @param ?string $through_type The manager name of the through type.
*
* @param string $through_native_field The name of the native field in
* @param ?string $through_native_field The name of the native field in
* the through type.
*
* @param string $through_foreign_field The name of the foreign field in
* @param ?string $through_foreign_field The name of the foreign field in
* the through type.
*
*/
Expand All @@ -126,7 +126,7 @@ public function __construct(
GenericType $foreign,
$foreign_type,
$foreign_field,
GenericType $through = null,
?GenericType $through = null,
$through_type = null,
$through_native_field = null,
$through_foreign_field = null
Expand Down
4 changes: 3 additions & 1 deletion src/Relation/BelongsTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*/
namespace Aura\Marshal\Relation;

use Aura\Marshal\Entity\GenericEntity;

/**
*
* Represents a relationship where the native entity belongs to a foreign
Expand All @@ -26,7 +28,7 @@ class BelongsTo extends AbstractRelation implements RelationInterface
*
* @param mixed $entity The native entity.
*
* @return GenericEntity
* @return ?object
*
*/
public function getForEntity($entity)
Expand Down
Loading

0 comments on commit bd33dc5

Please sign in to comment.