diff --git a/examples/bootstrap_examples.php b/examples/bootstrap_examples.php index fc4793d..e266cb5 100644 --- a/examples/bootstrap_examples.php +++ b/examples/bootstrap_examples.php @@ -142,7 +142,7 @@ public function getOfficialLink() { * optionally helpers for the specific profile */ - public function setTimestamps(ResourceInterface $resource, \DateTimeInterface $created=null, \DateTimeInterface $updated=null) { + public function setTimestamps(ResourceInterface $resource, ?\DateTimeInterface $created=null, ?\DateTimeInterface $updated=null) { if ($resource instanceof ResourceIdentifierObject) { throw new Exception('cannot add attributes to identifier objects'); } diff --git a/src/ErrorsDocument.php b/src/ErrorsDocument.php index 025bc06..12f2ade 100644 --- a/src/ErrorsDocument.php +++ b/src/ErrorsDocument.php @@ -29,9 +29,9 @@ class ErrorsDocument extends Document { ]; /** - * @param ErrorObject $errorObject optional + * @param ?ErrorObject $errorObject optional */ - public function __construct(ErrorObject $errorObject=null) { + public function __construct(?ErrorObject $errorObject=null) { parent::__construct(); if ($errorObject !== null) { diff --git a/src/helpers/RequestParser.php b/src/helpers/RequestParser.php index 14a8373..a4abbc3 100644 --- a/src/helpers/RequestParser.php +++ b/src/helpers/RequestParser.php @@ -293,6 +293,18 @@ public function getAttribute($attributeName) { return $this->document['data']['attributes'][$attributeName]; } + /** + * @param string $attributeName + * @return mixed|null + */ + public function findAttribute($attributeName) { + if ($this->hasAttribute($attributeName) === false) { + return null; + } + + return $this->getAttribute($attributeName); + } + /** * @param string $relationshipName * @return boolean diff --git a/tests/example_output/ExampleTimestampsProfile.php b/tests/example_output/ExampleTimestampsProfile.php index 56b07f5..4426643 100644 --- a/tests/example_output/ExampleTimestampsProfile.php +++ b/tests/example_output/ExampleTimestampsProfile.php @@ -11,7 +11,7 @@ public function getOfficialLink() { return 'https://jsonapi.org/recommendations/#authoring-profiles'; } - public function setTimestamps(ResourceInterface $resource, \DateTimeInterface $created=null, \DateTimeInterface $updated=null) { + public function setTimestamps(ResourceInterface $resource, ?\DateTimeInterface $created=null, ?\DateTimeInterface $updated=null) { if ($resource instanceof ResourceIdentifierObject) { throw new Exception('cannot add attributes to identifier objects'); }