Completed
Push — master ( 4207f0...333332 )
by Kamil
23:19 queued 01:42
created

ThemeRepository   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 8
lcom 0
cbo 1
dl 0
loc 49
rs 10
c 4
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A find() 0 4 1
A findOneBySlug() 0 4 1
A __construct() 0 12 3
A findOneByPath() 0 11 3
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\ThemeBundle\Repository;
13
14
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface;
15
use Sylius\Component\Resource\Repository\InMemoryRepository;
16
17
/**
18
 * @author Kamil Kokot <[email protected]>
19
 */
20
final class ThemeRepository extends InMemoryRepository implements ThemeRepositoryInterface
21
{
22
    /**
23
     * @param array|ThemeInterface[] $themes Can be an array of serialized themes
24
     */
25
    public function __construct(array $themes = [])
26
    {
27
        parent::__construct(ThemeInterface::class);
28
29
        foreach ($themes as $theme) {
30
            if (!$theme instanceof ThemeInterface) {
31
                $theme = unserialize($theme);
32
            }
33
34
            $this->add($theme);
35
        }
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function find($id)
42
    {
43
        return $this->findOneBySlug($id);
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function findOneBySlug($slug)
50
    {
51
        return $this->findOneBy(['slug' => $slug]);
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function findOneByPath($path)
58
    {
59
        /** @var ThemeInterface $theme */
60
        foreach ($this->findAll() as $theme) {
61
            if (0 === strpos($path, $theme->getPath())) {
62
                return $theme;
63
            }
64
        }
65
66
        return null;
67
    }
68
}
69