Passed
Pull Request — master (#20)
by
unknown
02:24
created

Various::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types = 1);
4
5
/**
6
 * File: Various.php
7
 *
8
 * @author Bartosz Kubicki [email protected]>
9
 * @copyright Copyright (C) 2018 Lizard Media (http://lizardmedia.pl)
10
 */
11
12
namespace LizardMedia\ProductAttachment\Helper;
13
14
15
use \Magento\Catalog\Api\Data\ProductInterface;
16
use \Magento\Framework\App\Helper\AbstractHelper;
17
use \Magento\Framework\App\ProductMetadataInterface;
18
use \Magento\Framework\EntityManager\MetadataPool;
19
20
/**
21
 * Various Helper
22
 * @package LizardMedia\ProductAttachment\Helper
23
 */
24
class Various extends AbstractHelper
25
{
26
    /**
27
     * @var \Magento\Framework\App\ProductMetadataInterface
28
     */
29
    private $productMetadata;
30
31
32
   /**
33
     * @var \Magento\Framework\EntityManager\MetadataPool
34
     */
35
    private $metadataPool;
36
37
38
    /**
39
     * @param \Magento\Framework\App\ProductMetadataInterface $productMetadata
40
     * @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
41
     */
42
    public function __construct(
43
        ProductMetadataInterface $productMetadata,
44
        MetadataPool $metadataPool
45
    ) {
46
        $this->productMetadata = $productMetadata;
47
        $this->metadataPool = $metadataPool;
48
    }
49
50
    /**
51
     * @return string
52
     */
53
    public function getLinkFieldValue()
54
    {
55
        return  (
56
            $this->productMetadata->getEdition() !== 'Community'
57
            && version_compare($this->productMetadata->getVersion(), '2.1.0', '>=')
58
        )
59
            ? 'entity_id'
60
            : $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
61
    }
62
}
63