diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index ee60783b2f..69bce069d2 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -4230,12 +4230,6 @@ parameters: count: 1 path: src/lib/Form/Data/Section/SectionUpdateData.php - - - message: '#^Cannot access property \$path on Ibexa\\Contracts\\Core\\Repository\\Values\\Content\\Location\|false\.$#' - identifier: property.nonObject - count: 1 - path: src/lib/Form/Data/TrashItemData.php - - message: '#^Method Ibexa\\AdminUi\\Form\\Data\\URLWildcard\\URLWildcardDeleteData\:\:__construct\(\) has parameter \$urlWildcardsChoices with no value type specified in iterable type array\.$#' identifier: missingType.iterableValue diff --git a/src/lib/Form/Data/TrashItemData.php b/src/lib/Form/Data/TrashItemData.php index efc1a00934..a1a197de08 100644 --- a/src/lib/Form/Data/TrashItemData.php +++ b/src/lib/Form/Data/TrashItemData.php @@ -81,7 +81,7 @@ public function isParentInTrash(): bool { $lastAncestor = end($this->ancestors); - return $this->location->path !== array_merge($lastAncestor->path, [(string)$this->location->id]); + return $lastAncestor !== false && $this->location->path !== array_merge($lastAncestor->path, [(string)$this->location->id]); } public function getCreator(): ?User diff --git a/tests/lib/Form/Data/TrashItemDataTest.php b/tests/lib/Form/Data/TrashItemDataTest.php new file mode 100644 index 0000000000..1c2d1c4e0a --- /dev/null +++ b/tests/lib/Form/Data/TrashItemDataTest.php @@ -0,0 +1,57 @@ + ['1', '2', '3'], 'id' => 3]); + $data = new TrashItemData($trashItem, null, []); + + self::assertFalse($data->isParentInTrash()); + } + + public function testIsParentInTrashReturnsFalseWhenPathsMatch(): void + { + $trashItem = new TrashItem(['path' => ['1', '2', '3'], 'id' => 3]); + + $ancestor = new Location(['path' => ['1', '2']]); + $data = new TrashItemData($trashItem, null, [$ancestor]); + + self::assertFalse($data->isParentInTrash()); + } + + public function testIsParentInTrashReturnsTrueWhenPathsDoNotMatch(): void + { + $trashItem = new TrashItem(['path' => ['1', '2', '3'], 'id' => 3]); + $ancestor = new Location(['path' => ['1']]); + + $data = new TrashItemData($trashItem, null, [$ancestor]); + + self::assertTrue($data->isParentInTrash()); + } + + public function testIsParentInTrashWithMultipleAncestors(): void + { + $trashItem = new TrashItem(['path' => ['1', '2', '3', '4'], 'id' => 4]); + + $ancestor1 = new Location(['path' => ['1']]); + $ancestor2 = new Location(['path' => ['1', '2', '3']]); + + $data = new TrashItemData($trashItem, null, [$ancestor1, $ancestor2]); + + self::assertFalse($data->isParentInTrash()); + } +}