Completed
Push — master ( f3d682...6367b5 )
by Gilmar
21:40
created

AbstractDecorator::validate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 9.4285
cc 2
eloc 6
nc 2
nop 0
crap 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\Order\Decorator;
16
17
use Gpupo\Common\Entity\Collection;
18
use Gpupo\CommonSdk\Traits\LoggerTrait;
19
use Gpupo\NetshoesSdk\Entity\Order\Order;
20
21
abstract class AbstractDecorator extends Collection
22
{
23
    use LoggerTrait;
24
25 5
    protected function fail($string = '')
26
    {
27 5
        $message = 'Order incomplete for status ['.$string.']';
28 5
        $this->log('error', $message, [
29 5
            'order' => $this->getOrder(),
30
        ]);
31
32 5
        throw new \InvalidArgumentException($message);
33
    }
34
35 10
    protected function invalid($string = '')
36
    {
37 10
        $message = 'Attribute invalid: '.$string.' ';
38
39 10
        throw new \InvalidArgumentException($message);
40
    }
41
42 20
    public function setOrder(Order $order)
43
    {
44 20
        $this->set('order', $order);
45 20
        $this->initLogger($order->getLogger());
46
47 20
        return $this;
48
    }
49
50 25
    public function getOrder()
51
    {
52 25
        return $this->get('order');
53
    }
54
55 25
    public function validate()
56
    {
57 25
        $order = $this->getOrder();
58
59 25
        if (empty($order)) {
60 10
            $this->invalid('Order');
61
        }
62
63 15
        $this->getOrder()->check();
64
65 15
        return $this;
66
    }
67
}
68