Test Failed
Push — develop ( d382d0...28e0cd )
by Daniel
10:59
created

ContentRepository::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Silverback\ApiComponentBundle\Repository;
6
7
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
8
use Doctrine\Common\Collections\ArrayCollection;
9
use Doctrine\Common\Collections\Collection;
10
use PHPCR\RepositoryException;
11
use Silverback\ApiComponentBundle\Entity\Content\AbstractContent;
12
use Symfony\Bridge\Doctrine\RegistryInterface;
13
14
/**
15
 * @method AbstractContent|null find($id, $lockMode = null, $lockVersion = null)
16
 * @method AbstractContent|null findOneBy(array $criteria, array $orderBy = null)
17
 * @method AbstractContent[]    findAll()
18
 * @method AbstractContent[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
19
 */
20
class ContentRepository extends ServiceEntityRepository
21
{
22
    private $registry;
23
24
    public function __construct(RegistryInterface $registry)
25
    {
26
        $this->registry = $registry;
27
        parent::__construct($registry, AbstractContent::class);
28
    }
29
30
    public function findPageByType(string $entityClass): Collection
31
    {
32
        if (!is_subclass_of($entityClass, AbstractContent::class)) {
33
            throw new RepositoryException(substr('The entity class must be a subclass of %s', AbstractContent::class));
0 ignored issues
show
Bug introduced by
Silverback\ApiComponentB...\AbstractContent::class of type string is incompatible with the type integer expected by parameter $start of substr(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

33
            throw new RepositoryException(substr('The entity class must be a subclass of %s', /** @scrutinizer ignore-type */ AbstractContent::class));
Loading history...
34
        }
35
        $childRepository = new ServiceEntityRepository($this->registry, $entityClass);
36
        $result = new ArrayCollection($childRepository->findAll());
37
38
        $uow = $childRepository->getEntityManager()->getUnitOfWork();
39
        $scheduledInsertions = $uow->getScheduledEntityInsertions();
40
        foreach ($scheduledInsertions as $scheduledInsertion) {
41
            if (is_a($scheduledInsertion, $entityClass)) {
42
                $result->add($scheduledInsertion);
43
            }
44
        }
45
        return $result;
46
    }
47
}
48