Completed
Push — master ( c872d4...3a3f1c )
by Gilmar
22:46
created

Item::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of gpupo/netshoes-sdk
5
 * Created by Gilmar Pupo <[email protected]>
6
 * For the information of copyright and license you should read the file
7
 * LICENSE which is distributed with this source code.
8
 * Para a informação dos direitos autorais e de licença você deve ler o arquivo
9
 * LICENSE que é distribuído com este código-fonte.
10
 * Para obtener la información de los derechos de autor y la licencia debe leer
11
 * el archivo LICENSE que se distribuye con el código fuente.
12
 * For more information, see <http://www.g1mr.com/>.
13
 */
14
15
namespace Gpupo\NetshoesSdk\Entity\Product\Sku;
16
17
use Gpupo\CommonSdk\Entity\EntityAbstract;
18
use Gpupo\CommonSdk\Entity\EntityInterface;
19
20
class Item extends EntityAbstract implements EntityInterface
21
{
22
    protected $primaryKey = 'sku';
23
24
    protected $exclude = ['price', 'priceSchedule', 'stock', 'status'];
25
26
    /**
27
     * @codeCoverageIgnore
28
     */
29
    public function getSchema()
30
    {
31
        return  [
32
            'sku'           => 'string',
33
            'name'          => 'string',
34
            'description'   => 'string',
35
            'color'         => 'string',
36
            'size'          => 'string',
37
            'gender'        => 'string',
38
            'eanIsbn'       => 'string',
39
            'images'        => 'object',
40
            'video'         => 'string',
41
            'height'        => 'string',
42
            'width'         => 'string',
43
            'depth'         => 'string',
44
            'weight'        => 'string',
45
            'price'         => 'object',
46
            'priceSchedule' => 'object',
47
            'stock'         => 'object',
48
            'status'        => 'object',
49
        ];
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55 4
    protected function setUp()
56
    {
57 4
        $this->setOptionalSchema($this->exclude);
58 4
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63 7
    protected function beforeConstruct($data = null)
64
    {
65 7
        if (empty($data)) {
66
            return;
67
        }
68
69 7
        if (is_array($data)) {
70 7
            if (array_key_exists('stock', $data)) {
71 3
                $data['stock'] = ['available' => $data['stock']];
72
            }
73
74 7
            if (array_key_exists('listPrice', $data)) {
75 3
                $data['price'] = ['price' => $data['listPrice']];
76 3
                unset($data['listPrice']);
77
            }
78
79 7
            if (array_key_exists('sellPrice', $data)) {
80 3
                $data['priceSchedule'] = ['priceTo' => $data['sellPrice']];
81 3
                unset($data['sellPrice']);
82
            }
83
84 7
            if (array_key_exists('status', $data)) {
85 3
                $data['status'] = ['active' => $data['status']];
86
            }
87
        }
88
89 7
        return $data;
90
    }
91
92
    /**
93
     * {@inheritdoc}
94
     */
95 2
    public function toArray()
96
    {
97 2
        $a = parent::toArray();
98
99 2
        foreach ($this->exclude as $k) {
100 2
            unset($a[$k]);
101
        }
102
103 2
        return $a;
104
    }
105
106 1
    protected function toPrice()
107
    {
108 1
        return $this->getPrice()->toArray();
0 ignored issues
show
Documentation Bug introduced by
The method getPrice does not exist on object<Gpupo\NetshoesSdk\Entity\Product\Sku\Item>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
109
    }
110
111
    protected function toPriceSchedule()
112
    {
113
        return $this->getPriceSchedule()->toArray();
0 ignored issues
show
Bug introduced by
The method getPriceSchedule() does not exist on Gpupo\NetshoesSdk\Entity\Product\Sku\Item. Did you maybe mean toPriceSchedule()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
114
    }
115
116 1
    protected function toStatus()
117
    {
118 1
        return $this->getStatus()->toArray();
0 ignored issues
show
Documentation Bug introduced by
The method getStatus does not exist on object<Gpupo\NetshoesSdk\Entity\Product\Sku\Item>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
119
    }
120
121 1
    protected function toStock()
122
    {
123 1
        return $this->getStock()->toArray();
0 ignored issues
show
Documentation Bug introduced by
The method getStock does not exist on object<Gpupo\NetshoesSdk\Entity\Product\Sku\Item>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
124
    }
125
}
126