Completed
Push — master ( e3bdbd...42f197 )
by Gilmar
26:10
created

Translator::loadMap()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 1.008

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 8
loc 8
rs 9.4285
ccs 4
cts 5
cp 0.8
cc 1
eloc 5
nc 1
nop 1
crap 1.008
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\Product;
16
17
use Gpupo\CommonSchema\AbstractTranslator;
18
use Gpupo\CommonSchema\TranslatorDataCollection;
19
use Gpupo\CommonSchema\TranslatorInterface;
20
use Gpupo\CommonSdk\Traits\LoadTrait;
21
22 View Code Duplication
final class Translator extends AbstractTranslator implements TranslatorInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
23
{
24
    use LoadTrait;
25
26 54
    private function loadMap($name)
27
    {
28 54
        $file = __DIR__.'/map/translate.'.$name.'.map.php';
29 54
        $method = 'get'.ucfirst($name);
30
        $pars = [$name => $this->$method()];
31
32
        return $this->loadArrayFromFile($file, $pars);
33 54
    }
34
35 54
    /**
36
     * {@inheritdoc}
37
     */
38
    public function translateTo()
39
    {
40
        if (!$this->getNative() instanceof Product) {
41 52
            throw new \Exception('Product missed!');
42
        }
43 52
44
        return $this->factoryOutputCollection($this->loadMap('native'));
45 52
    }
46
47
    /**
48
     * {@inheritdoc}
49 52
     */
50
    public function translateFrom()
51
    {
52
        if (!$this->getForeign() instanceof TranslatorDataCollection) {
53
            throw new \Exception('Foreign missed!');
54
        }
55
56
        return new Product($this->loadMap('foreign'));
57
    }
58
}
59