Completed
Pull Request — master (#10)
by Tim
08:38
created

EeAttributeObserverTrait::prepareAttributes()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 35
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 35
ccs 0
cts 21
cp 0
rs 8.8571
cc 3
eloc 15
nc 4
nop 0
crap 12

2 Methods

Rating   Name   Duplication   Size   Complexity  
A EeAttributeObserverTrait::getPrimaryKey() 0 4 1
A EeAttributeObserverTrait::getLastRowId() 0 4 1
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\Ee\Observers\EeProductAttributeObserverTrait
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2016 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/techdivision/import-ee
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Ee\Observers;
22
23
use TechDivision\Import\Ee\Utils\MemberNames;
24
use TechDivision\Import\Observers\AttributeObserverTrait;
25
26
/**
27
 * Trait that provides basic EAV attribute functionality for Magento EE.
28
 *
29
 * @author    Tim Wagner <[email protected]>
30
 * @copyright 2016 TechDivision GmbH <[email protected]>
31
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
32
 * @link      https://github.com/techdivision/import-ee
33
 * @link      http://www.techdivision.com
34
 */
35
trait EeAttributeObserverTrait
36
{
37
38
    /**
39
     * The attribute observer trait implementation.
40
     *
41
     * @var \TechDivision\Import\Observers\AttributeObserverTrait
42
     */
43
    use AttributeObserverTrait;
44
45
    /**
46
     * Return's the PK column name to create the product => attribute relation.
47
     *
48
     * @return string The PK column name
49
     */
50
    protected function getPrimaryKeyMemberName()
51
    {
52
        return MemberNames::ROW_ID;
53
    }
54
55
    /**
56
     * Return's the PK to create the product => attribute relation.
57
     *
58
     * @return integer The PK to create the relation with
59
     */
60
    protected function getPrimaryKey()
61
    {
62
        return $this->getLastRowId();
63
    }
64
65
    /**
66
     * Return's the row ID of the product that has been created recently.
67
     *
68
     * @return string The row Id
69
     */
70
    protected function getLastRowId()
71
    {
72
        return $this->getSubject()->getLastRowId();
0 ignored issues
show
Bug introduced by
It seems like getSubject() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
73
    }
74
}
75