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
|
|
|
use BadMethodCallException; |
12
|
|
|
use Magento\Framework\Module\ResourceInterface as ModuleResourceInterface; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class ModuleVersion |
16
|
|
|
* |
17
|
|
|
* @package N98\Magento\Api |
18
|
|
|
*/ |
19
|
|
|
class ModuleVersion implements ModuleInterface, ModuleVersionInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var Module |
23
|
|
|
*/ |
24
|
|
|
private $module; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var ModuleResourceInterface |
28
|
|
|
*/ |
29
|
|
|
private $resource; |
30
|
|
|
|
31
|
|
|
public function __construct(Module $module, ModuleResourceInterface $resource) |
32
|
|
|
{ |
33
|
|
|
$this->module = $module; |
34
|
|
|
$this->resource = $resource; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* {@inheritdoc} |
39
|
|
|
*/ |
40
|
|
|
public function getName() |
41
|
|
|
{ |
42
|
|
|
return $this->module->getName(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* {@inheritdoc} |
47
|
|
|
*/ |
48
|
|
|
public function getVersion() |
49
|
|
|
{ |
50
|
|
|
return $this->module->getVersion(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* {@inheritdoc} |
55
|
|
|
*/ |
56
|
|
View Code Duplication |
public function getDataVersion() |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
$name = $this->getName(); |
59
|
|
|
$version = $this->resource->getDataVersion($name); |
60
|
|
|
if ($version === false) { |
61
|
|
|
throw new BadMethodCallException(sprintf("Module '%s' data-version is not available.", $name)); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return $version; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritdoc} |
69
|
|
|
*/ |
70
|
|
View Code Duplication |
public function getDbVersion() |
|
|
|
|
71
|
|
|
{ |
72
|
|
|
$name = $this->getName(); |
73
|
|
|
$version = $this->resource->getDbVersion($name); |
74
|
|
|
if ($version === false) { |
75
|
|
|
throw new BadMethodCallException(sprintf("Module '%s' db-version is not available.", $name)); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return $version; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* {@inheritdoc} |
83
|
|
|
*/ |
84
|
|
|
public function setDataVersion($version) |
85
|
|
|
{ |
86
|
|
|
$this->resource->setDataVersion($this->getName(), $version); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* {@inheritdoc} |
91
|
|
|
*/ |
92
|
|
|
public function setDbVersion($version) |
93
|
|
|
{ |
94
|
|
|
$this->resource->setDbVersion($this->getName(), $version); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
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.