Completed
Push — master ( 79d213...eeff33 )
by Kamil
23:15
created

CircularDependencyChecker   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A check() 0 15 4
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\Loader;
13
14
use Sylius\Bundle\ThemeBundle\Model\ThemeInterface;
15
16
/**
17
 * @author Kamil Kokot <[email protected]>
18
 */
19
final class CircularDependencyChecker implements CircularDependencyCheckerInterface
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    public function check(ThemeInterface $theme, array $previousThemes = [])
25
    {
26
        if (0 === count($theme->getParents())) {
27
            return;
28
        }
29
30
        $previousThemes = array_merge($previousThemes, [$theme]);
31
        foreach ($theme->getParents() as $parent) {
32
            if (in_array($parent, $previousThemes, true)) {
33
                throw new CircularDependencyFoundException(array_merge($previousThemes, [$parent]));
34
            }
35
36
            $this->check($parent, $previousThemes);
37
        }
38
    }
39
}
40