From a965a3a7e6b3e022e68128326b463b43634556ce Mon Sep 17 00:00:00 2001 From: Oriac Date: Mon, 24 Apr 2017 16:56:28 +0200 Subject: [PATCH] #000000 removed childAllowed on entityCollection --- src/Collection/EntityCollection.php | 15 +++------------ src/Collection/EntityStrictCollection.php | 4 +--- .../Collection/EntityStrictCollectionTester.php | 15 --------------- 3 files changed, 4 insertions(+), 30 deletions(-) diff --git a/src/Collection/EntityCollection.php b/src/Collection/EntityCollection.php index bb9d6e0..23dc5da 100644 --- a/src/Collection/EntityCollection.php +++ b/src/Collection/EntityCollection.php @@ -12,8 +12,6 @@ abstract class EntityCollection implements \Countable, \Iterator { /** @var array */ private $entities = array(); - /** @var bool */ - protected $allowEntitiesChildren; /** * @return string @@ -25,10 +23,8 @@ abstract public static function entityClass(): string; * @param array $entities * @param bool $allowEntitiesChildren */ - public function __construct(array $entities = array(), bool $allowEntitiesChildren = false) + public function __construct(array $entities = array()) { - $this->allowEntitiesChildren = $allowEntitiesChildren; - foreach ($entities as $entity) { $this->add($entity); } @@ -69,12 +65,7 @@ public function isValid($entity): bool { if (!is_object($entity)) return false; - $entityClass = $this->allowEntitiesChildren ? get_parent_class($entity) : get_class($entity); - if ($entityClass === static::entityClass()){ - return true; - } - - return false; + return is_a($entity, static::entityClass()); } /** @@ -134,7 +125,7 @@ public function slice(int $offset, $length = null) { $entities = array_slice($this->entities, $offset, $length, true); - return new static($entities, $this->allowEntitiesChildren); + return new static($entities); } /** diff --git a/src/Collection/EntityStrictCollection.php b/src/Collection/EntityStrictCollection.php index 8f18cba..5f6a856 100644 --- a/src/Collection/EntityStrictCollection.php +++ b/src/Collection/EntityStrictCollection.php @@ -16,14 +16,12 @@ abstract class EntityStrictCollection extends EntityCollection * @param bool $allowEntitiesChildren * @throws \Exception */ - public function __construct(array $entities, bool $allowEntitiesChildren = false) + public function __construct(array $entities) { if (empty($entities)) { throw static::customEmptyException(); } - $this->allowEntitiesChildren = $allowEntitiesChildren; - foreach ($entities as $entity) { $this->add($entity); } diff --git a/src/Tester/Collection/EntityStrictCollectionTester.php b/src/Tester/Collection/EntityStrictCollectionTester.php index c5c4d1a..42d6bac 100644 --- a/src/Tester/Collection/EntityStrictCollectionTester.php +++ b/src/Tester/Collection/EntityStrictCollectionTester.php @@ -81,21 +81,6 @@ public function invalidAddElement() $collection->add([]); } - /** - * @test - */ - public function validChildrenElementByConstructor() - { - /** @var EntityStrictCollection $entityCollectionClass */ - $entityCollectionClass = $this->entityCollectionClass(); - $exception = $entityCollectionClass::customInvalidEntityException(); - - $this->expectException(get_class($exception)); - $this->expectExceptionMessage($exception->getMessage()); - - new $entityCollectionClass([$this->prophesize($entityCollectionClass::entityClass())->reveal()]); - } - /** * @test */