Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#000000 removed childAllowed on entityCollection #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions src/Collection/EntityCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ abstract class EntityCollection implements \Countable, \Iterator
{
/** @var array */
private $entities = array();
/** @var bool */
protected $allowEntitiesChildren;

/**
* @return string
Expand All @@ -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);
}
Expand Down Expand Up @@ -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());
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/Collection/EntityStrictCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
15 changes: 0 additions & 15 deletions src/Tester/Collection/EntityStrictCollectionTester.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down