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

Translator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 80%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
c 3
b 0
f 0
lcom 1
cbo 2
dl 36
loc 36
rs 10
ccs 8
cts 10
cp 0.8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A loadMap() 7 7 1
A translateTo() 8 8 2
A translateFrom() 8 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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