1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* MageSpec |
4
|
|
|
* |
5
|
|
|
* NOTICE OF LICENSE |
6
|
|
|
* |
7
|
|
|
* This source file is subject to the MIT License, that is bundled with this |
8
|
|
|
* package in the file LICENSE. |
9
|
|
|
* It is also available through the world-wide-web at this URL: |
10
|
|
|
* |
11
|
|
|
* http://opensource.org/licenses/MIT |
12
|
|
|
* |
13
|
|
|
* If you did not receive a copy of the license and are unable to obtain it |
14
|
|
|
* through the world-wide-web, please send an email |
15
|
|
|
* to <[email protected]> so we can send you a copy immediately. |
16
|
|
|
* |
17
|
|
|
* @category MageTest |
18
|
|
|
* @package PhpSpec_MagentoExtension |
19
|
|
|
* |
20
|
|
|
* @copyright Copyright (c) 2012-2013 MageTest team and contributors. |
21
|
|
|
*/ |
22
|
|
|
namespace MageTest\PhpSpec\MagentoExtension\Locator\Magento; |
23
|
|
|
|
24
|
|
|
use InvalidArgumentException; |
25
|
|
|
use PhpSpec\Locator\ResourceLocator; |
26
|
|
|
use PhpSpec\Util\Filesystem; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* ModelLocator |
30
|
|
|
* |
31
|
|
|
* @category MageTest |
32
|
|
|
* @package PhpSpec_MagentoExtension |
33
|
|
|
* |
34
|
|
|
* @author MageTest team (https://github.com/MageTest/MageSpec/contributors) |
35
|
|
|
*/ |
36
|
|
View Code Duplication |
class ModelLocator extends AbstractResourceLocator implements ResourceLocator |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* @return int |
40
|
|
|
*/ |
41
|
|
|
public function getPriority() |
42
|
|
|
{ |
43
|
|
|
return 40; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param string $file |
48
|
|
|
* @return bool |
49
|
|
|
*/ |
50
|
|
|
protected function isSupported($file) |
51
|
|
|
{ |
52
|
|
|
return strpos($file, 'Model') > 0; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param array $parts |
57
|
|
|
* @param ResourceLocator $locator |
58
|
|
|
* @return ModelResource |
59
|
|
|
* @throws \InvalidArgumentException |
60
|
|
|
*/ |
61
|
|
|
protected function getResource(array $parts, ResourceLocator $locator) |
62
|
|
|
{ |
63
|
|
|
if (!$locator instanceof ModelLocator) { |
64
|
|
|
throw new \InvalidArgumentException('Model resource requires a model locator'); |
65
|
|
|
} |
66
|
|
|
return new ModelResource($parts, $locator); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return string |
71
|
|
|
*/ |
72
|
|
|
protected function getClassType() |
73
|
|
|
{ |
74
|
|
|
return 'Model'; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return string |
79
|
|
|
*/ |
80
|
|
|
protected function getValidator() |
81
|
|
|
{ |
82
|
|
|
return '/^(model):([a-zA-Z0-9]+)_([a-zA-Z0-9]+)\/([a-zA-Z0-9]+)(_[\w]+)?$/'; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
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.