Skip to content

Commit ffb9cb3

Browse files
committed
Revert "Removed unnecessary checks for $mappings[$type]"
This reverts commit 83c7f00.
1 parent 0aefd99 commit ffb9cb3

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

src/Helpers/DataIncludedHelper.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ protected static function removeResourcesNotIncluded(array &$mappings, $parentTy
264264
*/
265265
protected static function isDeleteableIncludedResource(array &$mappings, $parentType, $includeValue)
266266
{
267-
return count($mappings[$parentType]->getIncludedResources()) > 0
267+
return !empty($mappings[$parentType])
268+
&& count($mappings[$parentType]->getIncludedResources()) > 0
268269
&& false === in_array($includeValue[Serializer::CLASS_IDENTIFIER_KEY], $mappings[$parentType]->getIncludedResources(), true);
269270
}
270271
}

src/Helpers/DataLinksHelper.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static function setResponseDataLinks(array &$mappings, array &$value)
3232
$data = [];
3333
$type = $value[Serializer::CLASS_IDENTIFIER_KEY];
3434

35-
if (\is_scalar($type)) {
35+
if (\is_scalar($type) && !empty($mappings[$type])) {
3636
$copy = $value;
3737
RecursiveFormatterHelper::formatScalarValues($copy);
3838
if (!empty($copy[Serializer::CLASS_IDENTIFIER_KEY])) {
@@ -105,7 +105,7 @@ public static function setResponseDataRelationship(array &$mappings, array &$arr
105105
$parentType
106106
);
107107

108-
if (!empty($selfLink = $mappings[$parentType]->getRelationshipSelfUrl($propertyName))) {
108+
if (!empty($mappings[$parentType]) && !empty($selfLink = $mappings[$parentType]->getRelationshipSelfUrl($propertyName))) {
109109
$href = \str_replace($idProperties, $idValues, $selfLink);
110110
if ($selfLink != $href) {
111111
$propertyNameKey = DataAttributesHelper::transformToValidMemberName($propertyName);
@@ -126,7 +126,7 @@ public static function setResponseDataRelationship(array &$mappings, array &$arr
126126
$parentType = $parent[Serializer::CLASS_IDENTIFIER_KEY];
127127

128128
//Removes relationships related to the current resource if filtering include resources has been set.
129-
if (!empty($mappings[$parentType]->isFilteringIncludedResources())) {
129+
if (!empty($mappings[$parentType]) && !empty($mappings[$parentType]->isFilteringIncludedResources())) {
130130
foreach ($newData[JsonApiTransformer::RELATIONSHIPS_KEY][$propertyName] as $position => $includedResource) {
131131
if (count($mappings[$parentType]->getIncludedResources()) > 0 &&
132132
false === in_array($type, $mappings[$parentType]->getIncludedResources(), true)
@@ -222,7 +222,7 @@ public static function setResponseDataRelationshipSelfLinks($propertyName, array
222222
$data = [];
223223
$parentType = $parent[Serializer::CLASS_IDENTIFIER_KEY];
224224

225-
if (\is_scalar($parentType)) {
225+
if (\is_scalar($parentType) && !empty($mappings[$parentType])) {
226226
$copy = $parent;
227227
RecursiveFormatterHelper::formatScalarValues($copy);
228228
if (!empty($copy[Serializer::CLASS_IDENTIFIER_KEY])) {

src/Helpers/PropertyHelper.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ class PropertyHelper
2828
*/
2929
public static function setResponseDataTypeAndId(array &$mappings, array &$value)
3030
{
31-
$type = $value[Serializer::CLASS_IDENTIFIER_KEY];
32-
33-
//Recursion base case
34-
if (empty($mappings[$type])) {
31+
if (empty($type = $value[Serializer::CLASS_IDENTIFIER_KEY]) || (empty($mappings[$type]))) {
3532
return [];
3633
}
3734

0 commit comments

Comments
 (0)