Completed
Pull Request — 5.6 (#2830)
by Jeroen
14:14
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
     * @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...
19
     */
20
    public function findFor(AbstractEntity $entity)
21
    {
22
        return $this->findOneBy(['refId' => $entity->getId(), 'refEntityName' => ClassLookup::getClass($entity)]);
23
    }
24
25
    /**
26
     * @return Seo
27
     */
28
    public function findOrCreateFor(AbstractEntity $entity)
29
    {
30
        $seo = $this->findFor($entity);
31
32
        if (\is_null($seo)) {
33
            $seo = new Seo();
34
            $seo->setRef($entity);
35
        }
36
37
        return $seo;
38
    }
39
}
40