Completed
Push — master ( a5e931...d15f5b )
by Gilmar
28:45 queued 03:51
created

AbstractManager::findById()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
cc 3
eloc 5
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;
16
17
use Gpupo\CommonSdk\Entity\EntityInterface;
18
use Gpupo\CommonSdk\Entity\ManagerAbstract;
19
use Gpupo\CommonSdk\Entity\ManagerInterface;
20
21
abstract class AbstractManager extends ManagerAbstract implements ManagerInterface
22
{
23 5
    protected function fetchDefaultParameters()
24
    {
25
        return [
26 5
            'buId'           => 'ZT',
27
            'orderStartDate' => null,
28
        ];
29
    }
30
31 18
    public function factoryMap($operation, array $parameters = null)
32
    {
33 18
        return parent::factoryMap($operation, array_merge($this->fetchDefaultParameters(), (array) $parameters));
34
    }
35
36
    /**
37
     * @codeCoverageIgnore
38
     *
39
     * @return Gpupo\Common\Entity\CollectionAbstract|null|false
40
     */
41
    protected function fetchPrepare($data)
42
    {
43
        if (empty($data)) {
44
            return false;
45
        }
46
47
        return $this->factoryEntityCollection($data);
48
    }
49
50 4
    protected function factoryEntityCollection($data)
51
    {
52 4
        return $this->factoryNeighborObject($this->getEntityName().'Collection', $data);
53
    }
54
55 1
    public function save(EntityInterface $entity, $route = 'save')
56
    {
57 1
        return $this->execute($this->factoryMap($route), $entity->toJson($route));
58
    }
59
60
    /**
61
     * @return Gpupo\Common\Entity\CollectionAbstract|false
62
     */
63 4
    public function findById($itemId)
64
    {
65 4
        $data = parent::findById($itemId);
66
67 4
        if (empty($data) || $data->get('type') === 'Resource_Not_Found') {
68 1
            return false;
69
        }
70
71 3
        return $this->factoryEntity($data->toArray());
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     *
77
     * @codeCoverageIgnore
78
     */
79
    public function update(EntityInterface $entity, EntityInterface $existent = null)
80
    {
81
        $text = 'Chamada a Atualização de entity '.$this->entity;
82
83
        return $this->log('debug', $text, [
84
            'entity'   => $entity,
85
            'existent' => $existent,
86
        ]);
87
    }
88
}
89