Completed
Push — master ( 90ccc1...22512f )
by Kamil
35:43
created

ProductHierarchyProvider::supports()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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\Component\Core\Metadata\HierarchyProvider;
13
14
use Sylius\Component\Core\Model\ArchetypeInterface;
15
use Sylius\Component\Core\Model\ProductInterface;
16
use Sylius\Component\Metadata\HierarchyProvider\MetadataHierarchyProviderInterface;
17
use Sylius\Component\Metadata\Model\MetadataSubjectInterface;
18
19
/**
20
 * @author Kamil Kokot <[email protected]>
21
 */
22
class ProductHierarchyProvider implements MetadataHierarchyProviderInterface
23
{
24
    /**
25
     * {@inheritdoc}
26
     *
27
     * @param ProductInterface|MetadataSubjectInterface $product
28
     */
29
    public function getHierarchyByMetadataSubject(MetadataSubjectInterface $product)
30
    {
31
        $hierarchy = [
32
            $product->getMetadataIdentifier(),
33
        ];
34
35
        /** @var ArchetypeInterface $productArchetype */
36
        $productArchetype = $product->getArchetype();
37
        if (null !== $productArchetype) {
38
            $hierarchy[] = $productArchetype->getMetadataIdentifier();
39
        }
40
41
        $hierarchy[] = $product->getMetadataClassIdentifier();
42
        $hierarchy[] = 'DefaultPage';
43
44
        return $hierarchy;
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function supports(MetadataSubjectInterface $metadataSubject)
51
    {
52
        return $metadataSubject instanceof ProductInterface;
53
    }
54
}
55