Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9e97c63

Browse files
author
plumthedev
committed
refactor finder exclude
1 parent 32c8f35 commit 9e97c63

File tree

1 file changed

+97
-10
lines changed

1 file changed

+97
-10
lines changed

‎src/Finder.php‎

Lines changed: 97 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,116 @@
44
*
55
* @author Kacper Pruszynski (plumthedev)
66
* @link https://github.com/plumthedev/yii2-php-cs-fixer-config
7-
* @copyright Copyright (c) 2019 plumthedev
7+
* @copyright Copyright (c) 2019 - 2019 plumthedev
88
* @license https://github.com/plumthedev/yii2-php-cs-fixer-config/blob/master/LICENSE
99
* @version 1.0.1
1010
*/
1111

1212
namespace plumthedev\PhpCsFixer;
1313

1414
use PhpCsFixer\Finder as PhpCsFixerFinder;
15+
use yii\base\InvalidArgumentException;
16+
use yii\helpers\ArrayHelper;
1517

1618
class Finder extends PhpCsFixerFinder
1719
{
18-
public $yiiProjectExcludePaths = [
19-
'views',
20-
'mail',
21-
'vendor',
22-
'backend/views',
23-
'frontend/views',
24-
'common/mail',
25-
];
20+
/**
21+
* Yii app directories to exclude with PhpCsFixerConfig.
22+
* @var array
23+
*/
24+
public $yiiAppExclude = [];
2625

2726
public function __construct()
2827
{
2928
parent::__construct();
30-
$this->exclude($this->yiiProjectExcludePaths);
29+
$this->yiiAppExclude = $this->getYiiAppExclude();
30+
$this->exclude($this->yiiAppExclude);
31+
}
32+
33+
/**
34+
* Get Yii2 App Basic directories to exclude.
35+
*
36+
* @see https://github.com/yiisoft/yii2-app-basic
37+
* @return array
38+
*/
39+
protected function getYiiAppBasicExclude()
40+
{
41+
return [
42+
'mail',
43+
'runtime',
44+
'vagrant',
45+
'views',
46+
'web',
47+
'vendor',
48+
'node_modules',
49+
];
50+
}
51+
52+
/**
53+
* Get Yii2 App Advanced directories to exclude.
54+
*
55+
* @see https://github.com/yiisoft/yii2-app-advanced
56+
* @return array
57+
*/
58+
protected function getYiiAppAdvancedExclude()
59+
{
60+
return [
61+
'backend/runtime',
62+
'backend/views',
63+
'backend/web',
64+
'backend/assets',
65+
'common/mail',
66+
'console/runtime',
67+
'docs',
68+
'environments',
69+
'frontend/assets',
70+
'frontend/runtime',
71+
'frontend/views',
72+
'frontend/web',
73+
'vagrant',
74+
'vendor',
75+
'node_modules',
76+
];
77+
}
78+
79+
/**
80+
* Return Yii app directories to exclude.
81+
* If values have been specified, they will be returned,
82+
* otherwise merge default directories for basic and advanced app.
83+
*
84+
* @return array Directories to exclude
85+
*/
86+
public function getYiiAppExclude()
87+
{
88+
if (!empty($this->yiiAppExclude)) {
89+
return $this->yiiAppExclude;
90+
}
91+
return ArrayHelper::merge(
92+
$this->getYiiAppBasicExclude(),
93+
$this->getYiiAppAdvancedExclude()
94+
);
95+
}
96+
97+
/**
98+
* Set Finder directories to exclude.
99+
*
100+
* @param array $yiiAppExclude Directories to exclude.
101+
* @param bool $mergeWithDefault Whether to merge with default directories to exclude.
102+
* @throws InvalidArgumentException Throw exception if directories to exclude is not array.
103+
*/
104+
public function setYiiAppExclude($yiiAppExclude, $mergeWithDefault = true)
105+
{
106+
if (!is_array($yiiAppExclude)) {
107+
throw new InvalidArgumentException('Directories to exclude must be a array.');
108+
}
109+
110+
if ($mergeWithDefault) {
111+
$yiiAppExclude = ArrayHelper::merge(
112+
$yiiAppExclude,
113+
$this->getYiiAppExclude()
114+
);
115+
}
116+
117+
$this->yiiAppExclude = $yiiAppExclude;
31118
}
32119
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /