Completed
Push — master ( 7f3ed3...4200af )
by Gilmar
22:41
created

Status::getMessage()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
ccs 4
cts 5
cp 0.8
cc 2
nc 2
nop 0
crap 2.032
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 <https://www.gpupo.com/>.
13
 */
14
15
namespace Gpupo\NetshoesSdk\Entity\Product;
16
17
use Gpupo\CommonSdk\Entity\EntityAbstract;
18
use Gpupo\CommonSdk\Entity\EntityInterface;
19
use Gpupo\CommonSdk\Exception\RuntimeException;
20
21
final class Status extends EntityAbstract implements EntityInterface
22
{
23
    /**
24
     * @codeCoverageIgnore
25
     */
26
    public function getSchema()
27
    {
28
        return [
29
            'active'          => 'boolean',
30
            'skuSynchronized' => 'boolean',
31
            'statusMatch'     => 'string',
32
            'hasPrice'        => 'boolean',
33
            'hasStock'        => 'boolean',
34
        ];
35
    }
36
37 1
    public function getMessage()
38
    {
39 1
        $statusMatch = $this->get('statusMatch');
40
41 1
        if (empty($statusMatch)) {
42
            throw new RuntimeException('Product Not Found', 404);
43
        }
44
45 1
        return $statusMatch;
46
    }
47
48 1
    public function isPending()
49
    {
50 1
        return 'PROCESSADO_INTEGRACAO_CATALOGO' !== $this->getMessage();
51
    }
52
53
    public function toLog()
54
    {
55
        $array = [
56
            'message' => $this->getMessage(),
57
        ];
58
59
        foreach (['getActive', 'getHasPrice', 'getHasStock', 'isPending'] as $k) {
60
            $array[$k] = (true === $this->$k()) ? 'yes' : 'no';
61
        }
62
63
        return $array;
64
    }
65
}
66