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

getHierarchyByMetadataSubject()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 25
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

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