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

AbstractDecorator   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 6
c 3
b 0
f 0
lcom 1
cbo 3
dl 0
loc 47
ccs 20
cts 20
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A fail() 0 9 1
A invalid() 0 6 1
A setOrder() 0 7 1
A getOrder() 0 4 1
A validate() 0 12 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