Completed
Push — master ( d34f34...c67d8d )
by Gilmar
23:17
created

Invoice::beforeConstruct()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
ccs 4
cts 4
cp 1
cc 3
eloc 4
nc 2
nop 1
crap 3
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\Order\Shippings;
16
17
use Gpupo\CommonSdk\Entity\EntityAbstract;
18
use Gpupo\CommonSdk\Entity\EntityInterface;
19
use Gpupo\NetshoesSdk\Traits\DateTimeTrait;
20
21
/**
22
 * @method string getNumber()    Acesso a number
23
 * @method setNumber(string $number)    Define number
24
 * @method int getLine()    Acesso a line
25
 * @method setLine(integer $line)    Define line
26
 * @method string getAccessKey()    Acesso a accessKey
27
 * @method setAccessKey(string $accessKey)    Define accessKey
28
 * @method setShipDate(string $shipDate)    Define shipDate
29
 * @method string getUrl()    Acesso a url
30
 * @method setUrl(string $url)    Define url
31
 */
32
class Invoice extends EntityAbstract implements EntityInterface
33
{
34
    use DateTimeTrait;
35
36
    protected $primaryKey = 'number';
37
38
    /**
39
     * @codeCoverageIgnore
40
     */
41
    public function getSchema()
42
    {
43
        return [
44
            'number'    => 'string',
45
            'line'      => 'integer',
46
            'accessKey' => 'string',
47
            'issueDate' => 'datetime',
48
            'shipDate'  => 'datetime',
49
            'url'       => 'string',
50
        ];
51
    }
52
53 4
    /**
54
     * {@inheritdoc}
55 4
     */
56 4
    protected function beforeConstruct($data = null)
57
    {
58 4
        if (is_array($data) && array_key_exists('date', $data)) {
59
            $data['issueDate'] = $data['date'];
60
        }
61 2
62
        return $data;
63 2
    }
64
65
    public function check()
66 1
    {
67
        $this->setRequiredSchema(['number', 'line', 'accessKey', 'issueDate']);
68 1
        $this->setOptionalSchema(['shipDate', 'url']);
69
70
        return $this->isValid();
71
    }
72
73
    public function getIssueDate()
74
    {
75
        return $this->dateGet('issueDate');
76
    }
77
78
    public function getShipDate()
79
    {
80
        return $this->dateGet('shipDate');
81
    }
82
}
83