Completed
Push — develop ( 5bf394...6bbee1 )
by Tom
06:47
created

ModuleVersion   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 76
Duplicated Lines 23.68 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 9
c 1
b 0
f 1
lcom 1
cbo 1
dl 18
loc 76
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getName() 0 4 1
A getVersion() 0 4 1
A getDataVersion() 9 9 2
A getDbVersion() 9 9 2
A setDataVersion() 0 4 1
A setDbVersion() 0 4 1

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
 * @author Tom Klingenberg <[email protected]>
4
 * @copyright Copyright (c) 2016 netz98 new media GmbH (http://www.netz98.de)
5
 *
6
 * @see PROJECT_LICENSE.txt
7
 */
8
9
namespace N98\Magento\Api;
10
11
12
use BadMethodCallException;
13
use Magento\Framework\Module\ResourceInterface as ModuleResourceInterface;
14
15
class ModuleVersion implements ModuleInterface
16
{
17
    /**
18
     * @var Module
19
     */
20
    private $module;
21
22
    /**
23
     * @var ModuleResource
24
     */
25
    private $resource;
26
27
    public function __construct(Module $module, ModuleResourceInterface $resource)
28
    {
29
        $this->module = $module;
30
        $this->resource = $resource;
0 ignored issues
show
Documentation Bug introduced by
It seems like $resource of type object<Magento\Framework...dule\ResourceInterface> is incompatible with the declared type object<N98\Magento\Api\ModuleResource> of property $resource.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function getName()
37
    {
38
        return $this->module->getName();
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function getVersion()
45
    {
46
        return $this->module->getVersion();
47
    }
48
49
    /**
50
     * @return string
51
     */
52 View Code Duplication
    public function getDataVersion()
0 ignored issues
show
Duplication introduced by
This method 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...
53
    {
54
        $name = $this->getName();
55
        $version = $this->resource->getDataVersion($name);
56
        if ($version === false) {
57
            throw new BadMethodCallException(sprintf("Module '%s' data-version is not available.", $name));
58
        }
59
        return $version;
60
    }
61
62
    /**
63
     * @return string
64
     */
65 View Code Duplication
    public function getDbVersion()
0 ignored issues
show
Duplication introduced by
This method 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...
66
    {
67
        $name = $this->getName();
68
        $version = $this->resource->getDbVersion($name);
69
        if ($version === false) {
70
            throw new BadMethodCallException(sprintf("Module '%s' db-version is not available.", $name));
71
        }
72
        return $version;
73
    }
74
75
    /**
76
     * @param string $version
77
     */
78
    public function setDataVersion($version)
79
    {
80
        $this->resource->setDataVersion($this->getName(), $version);
81
    }
82
83
    /**
84
     * @param string $version
85
     */
86
    public function setDbVersion($version)
87
    {
88
        $this->resource->setDbVersion($this->getName(), $version);
89
    }
90
}
91