Completed
Push — master ( 90bc38...4ece41 )
by Gilmar
25:06
created

PriceSchedule   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 9
Bugs 1 Features 0
Metric Value
wmc 7
c 9
b 1
f 0
lcom 1
cbo 1
dl 0
loc 49
ccs 16
cts 16
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getSchema() 0 9 1
A setUp() 0 4 1
A dateFormat() 0 7 1
A setDateInit() 0 4 1
A setDateEnd() 0 4 1
A toArray() 0 10 2
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 DateTime;
18
use DateTimeZone;
19
use Gpupo\CommonSdk\Entity\EntityAbstract;
20
use Gpupo\CommonSdk\Entity\EntityInterface;
21
22
/**
23
 * @method float getPriceFrom()    Acesso a priceFrom
24
 * @method setPriceFrom(float $priceFrom)    Define priceFrom
25
 * @method float getPriceTo()    Acesso a priceTo
26
 * @method setPriceTo(float $priceTo)    Define priceTo
27
 * @method string getDateInit()    Acesso a dateInit
28
 * @method setDateInit(string $dateInit)    Define dateInit
29
 * @method string getDateEnd()    Acesso a dateEnd
30
 * @method setDateEnd(string $dateEnd)    Define dateEnd
31
 */
32
class PriceSchedule extends EntityAbstract implements EntityInterface
33
{
34
    /**
35
     * @codeCoverageIgnore
36
     */
37
    public function getSchema()
38
    {
39
        return  [
40
            'priceFrom' => 'number',
41
            'priceTo'   => 'number',
42
            'dateInit'  => 'string',
43
            'dateEnd'   => 'string',
44
        ];
45
    }
46
47 7
    protected function setUp()
48
    {
49 7
        $this->setOptionalSchema(['priceFrom', 'dateEnd']);
50 7
    }
51
52 8
    protected function dateFormat($string)
53
    {
54 8
        $timezone = new DateTimeZone('UTC');
55 8
        $datetime = new DateTime($string, $timezone);
56
57 8
        return $datetime->format('c');
58
    }
59
60 6
    public function setDateInit($string)
61
    {
62 6
        return parent::setDateInit($this->dateFormat($string));
63
    }
64
65 1
    public function setDateEnd($string)
66
    {
67 1
        return parent::setDateEnd($this->dateFormat($string));
68
    }
69
70 5
    public function toArray()
71
    {
72 5
        $d = parent::getDateInit();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getDateInit() instead of toArray()). Are you sure this is correct? If so, you might want to change this to $this->getDateInit().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
73
74 5
        if (empty($d)) {
75 5
            $this->setDateInit('');
76
        }
77
78 5
        return parent::toArray();
79
    }
80
}
81