Completed
Push — master ( d72e6b...d34f34 )
by Gilmar
24:51
created

AbstractMetadata   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 9
c 5
b 0
f 0
lcom 0
cbo 2
dl 0
loc 41
ccs 17
cts 17
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A normalizeMetas() 0 18 4
B cutMetadata() 0 17 5
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\Metadata\MetadataContainerAbstract;
18
use Gpupo\CommonSdk\Traits\FinderTrait;
19
20
abstract class AbstractMetadata extends MetadataContainerAbstract
21
{
22
    use FinderTrait;
23
24 5
    protected function cutMetadata($raw)
25
    {
26 5
        if (empty($raw) || !is_array($raw)) {
27 1
            return [[]];
28
        }
29
30 4
        if (array_key_exists('_links', $raw)) {
31 1
            foreach ($raw['_links'] as $k => $v) {
32 1
                $raw['links'][] = [
33 1
                    'rel'  => $k,
34 1
                    'href' => current($v),
35
                ];
36
            }
37
        }
38
39 4
        return  $this->dataPiece('links', $raw);
40
    }
41
42 4
    protected function normalizeMetas($metas)
43
    {
44 4
        $data = [];
45
        $rm = [
46 4
            'http://sandbox-catalogo-vs.netshoes.local/mp-catalogo-api/rs',
47
            'http://api-sandbox.netshoes.com.br/api',
48
        ];
49
50 4
        if (is_array($metas)) {
51 4
            foreach ($metas as $meta) {
52 4
                if (array_key_exists('rel', $meta)) {
53 4
                    $data[$meta['rel']] = str_replace($rm, '', $meta['href']);
54
                }
55
            }
56
        }
57
58 4
        return $data;
59
    }
60
}
61