Completed
Push — master ( 6d6774...64f3ed )
by Jeroen
11:23 queued 05:13
created

Kunstmaan/SeoBundle/Repository/SeoRepository.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\SeoBundle\Repository;
4
5
use Doctrine\ORM\EntityRepository;
6
use Kunstmaan\AdminBundle\Entity\AbstractEntity;
7
use Kunstmaan\SeoBundle\Entity\Seo;
8
use Kunstmaan\UtilitiesBundle\Helper\ClassLookup;
9
10
/**
11
 * Repository for Seo
12
 */
13
class SeoRepository extends EntityRepository
14
{
15
    /**
16
     * Find the seo information for the given entity
17
     *
18
     * @param AbstractEntity $entity
19
     *
20
     * @return Seo
0 ignored issues
show
Should the return type not be Seo|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
21
     */
22
    public function findFor(AbstractEntity $entity)
23
    {
24
        return $this->findOneBy(array('refId' => $entity->getId(), 'refEntityName' => ClassLookup::getClass($entity)));
25
    }
26
27
    /**
28
     * @param AbstractEntity $entity
29
     *
30
     * @return Seo
31
     */
32
    public function findOrCreateFor(AbstractEntity $entity)
33
    {
34
        $seo = $this->findFor($entity);
35
36
        if (\is_null($seo)) {
37
            $seo = new Seo();
38
            $seo->setRef($entity);
39
        }
40
41
        return $seo;
42
    }
43
}
44