Skip to content

Commit

Permalink
Merge pull request #64 from Crell/au-closure
Browse files Browse the repository at this point in the history
Use updated AttributeUtils
  • Loading branch information
Crell committed Jul 11, 2024
2 parents 8b4871d + 6cde1ed commit a3229d7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Updates should follow the [Keep a CHANGELOG](http://keepachangelog.com/) princip

### Added
- Null values may now be excluded when serializing. See the `omitNullFields` and `omitIfNull` flags in the README.
- We now require AttributeUtils 1.2, which lets us use closures rather than method name strings for subAttribute callbacks. (Internal improvement.)

### Deprecated
- Nothing
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
],
"require": {
"php": "~8.1",
"crell/attributeutils": "~1.0",
"crell/attributeutils": "~1.2",
"crell/fp": "~1.0"
},
"require-dev": {
"phpbench/phpbench": "^1.1.2",
"phpstan/phpstan": "^1.10",
"phpunit/phpunit": "~10.3",
"symfony/yaml": "^5.3"
"phpbench/phpbench": "^1.3.0",
"phpstan/phpstan": "^1.11",
"phpunit/phpunit": "~10.5",
"symfony/yaml": "^5.4"
},
"suggest": {
"symfony/yaml": "Enables serializing to/from YAML files."
Expand Down
14 changes: 3 additions & 11 deletions src/Attributes/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use Crell\Serde\PropValue;
use Crell\Serde\Renaming\LiteralName;
use Crell\Serde\Renaming\RenamingStrategy;
use Crell\Serde\DeformatterResult;
use Crell\Serde\TypeCategory;
use Crell\Serde\TypeField;
use Crell\Serde\TypeMap;
Expand Down Expand Up @@ -277,19 +276,12 @@ protected function enumType(string $phpType): TypeCategory
public function subAttributes(): array
{
return [
TypeMap::class => 'fromTypeMap',
TypeField::class => 'fromTypeField',
TypeMap::class => fn(?TypeMap $map) => $this->typeMap = $map,
TypeField::class => $this->fromTypeField(...),
];
}

public function fromTypeMap(?TypeMap $map): void
{
// This may assign to null, which is OK as that will
// evaluate to false when we need it to.
$this->typeMap = $map;
}

public function fromTypeField(?TypeField $typeField): void
protected function fromTypeField(?TypeField $typeField): void
{
if ($typeField && !$typeField->acceptsType($this->phpType)) {
throw FieldTypeIncompatible::create($typeField::class, $this->phpType);
Expand Down

0 comments on commit a3229d7

Please sign in to comment.