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 PhpSpec\Locator\ResourceLocator as ResourceLocatorInterface; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* HelperLocator |
28
|
|
|
* |
29
|
|
|
* @category MageTest |
30
|
|
|
* @package PhpSpec_MagentoExtension |
31
|
|
|
* |
32
|
|
|
* @author MageTest team (https://github.com/MageTest/MageSpec/contributors) |
33
|
|
|
*/ |
34
|
|
View Code Duplication |
class HelperLocator extends AbstractResourceLocator implements ResourceLocatorInterface |
|
|
|
|
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* @return int |
38
|
|
|
*/ |
39
|
|
|
public function getPriority() |
40
|
|
|
{ |
41
|
|
|
return 20; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param string $file |
46
|
|
|
* @return bool |
47
|
|
|
*/ |
48
|
|
|
protected function isSupported($file) |
49
|
|
|
{ |
50
|
|
|
return strpos($file, 'Helper') > 0; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param array $parts |
55
|
|
|
* @param ResourceLocatorInterface $locator |
56
|
|
|
* @return HelperResource |
57
|
|
|
* @throws \InvalidArgumentException |
58
|
|
|
*/ |
59
|
|
|
protected function getResource(array $parts, ResourceLocatorInterface $locator) |
60
|
|
|
{ |
61
|
|
|
if (!$locator instanceof HelperLocator) { |
62
|
|
|
throw new \InvalidArgumentException('Helper resource requires a helper locator'); |
63
|
|
|
} |
64
|
|
|
return new HelperResource($parts, $locator); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return string |
69
|
|
|
*/ |
70
|
|
|
protected function getClassType() |
71
|
|
|
{ |
72
|
|
|
return 'Helper'; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return string |
77
|
|
|
*/ |
78
|
|
|
protected function getValidator() |
79
|
|
|
{ |
80
|
|
|
return '/^(helper):([a-zA-Z0-9]+)_([a-zA-Z0-9]+)\/([a-zA-Z0-9]+)(_[\w]+)?$/'; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
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.