Completed
Push — master ( cebedb...b44bca )
by Gilmar
22:17
created

AbstractManager::translateFindById()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

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