StaticContentRepository::findPublishedOneByName()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 2
nop 1
1
<?php
2
3
namespace Lakion\CmsPlugin\Repository;
4
5
use Doctrine\ODM\PHPCR\DocumentManagerInterface;
6
use Doctrine\ODM\PHPCR\Mapping\ClassMetadata;
7
use Lakion\CmsPlugin\Document\StaticContent;
8
use Sylius\Bundle\ResourceBundle\Doctrine\ODM\PHPCR\DocumentRepository;
9
10
class StaticContentRepository extends DocumentRepository implements StaticContentRepositoryInterface
0 ignored issues
show
Bug introduced by
There is at least one abstract method in this class. Maybe declare it as abstract, or implement the remaining methods: find, findAll, findBy, findOneBy, getClassName
Loading history...
11
{
12
    /**
13
     * @var string
14
     */
15
    private $staticContentPath;
16
17
    /**
18
     * @param DocumentManagerInterface $dm
19
     * @param ClassMetadata $class
20
     * @param string $staticContentPath
21
     */
22
    public function __construct(DocumentManagerInterface $dm, ClassMetadata $class, $staticContentPath)
23
    {
24
        parent::__construct($dm, $class);
25
26
        $this->staticContentPath = $staticContentPath;
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function findPublishedOneByName($name)
33
    {
34
        /** @var StaticContent|null $staticContent */
35
        $staticContent = $this->find($this->staticContentPath . '/' . $name);
36
37
        if (null === $staticContent || !$staticContent->isPublishable()) {
38
            return null;
39
        }
40
41
        return $staticContent;
42
    }
43
}
44