Passed
Push — master ( 4b1d00...aab577 )
by Bartosz
03:34 queued 01:45
created

Version::getLinkFieldValue()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 3
nc 4
nop 0
1
<?php
2
3
declare(strict_types = 1);
4
5
/**
6
 * File: Version.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
use Exception;
15
use Magento\Catalog\Api\Data\ProductInterface;
16
use Magento\Framework\App\ProductMetadata;
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 Version
25
{
26
    /**
27
     * @var ProductMetadataInterface
28
     */
29
    private $productMetadata;
30
31
   /**
32
    * @var MetadataPool
33
    */
34
   private $metadataPool;
35
36
    /**
37
     * @param ProductMetadataInterface $productMetadata
38
     * @param MetadataPool $metadataPool
39
     */
40
    public function __construct(
41
        ProductMetadataInterface $productMetadata,
42
        MetadataPool $metadataPool
43
    ) {
44
        $this->productMetadata = $productMetadata;
45
        $this->metadataPool = $metadataPool;
46
    }
47
48
    /**
49
     * @return string
50
     * @throws Exception
51
     */
52
    public function getLinkFieldValue(): string
53
    {
54
        return  (
55
            $this->productMetadata->getEdition() !== ProductMetadata::EDITION_NAME
56
            && version_compare($this->productMetadata->getVersion(), '2.1.0', '>=')
57
        )
58
            ? 'entity_id'
59
            : $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
60
    }
61
}
62