-
Notifications
You must be signed in to change notification settings - Fork 0
/
Finder.php
119 lines (109 loc) · 3.09 KB
/
Finder.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
/**
* Yii2 PHP CS Fixer Config
*
* @author Kacper Pruszynski (plumthedev)
* @link https://github.com/plumthedev/yii2-php-cs-fixer-config
* @copyright Copyright (c) 2019 - 2019 plumthedev
* @license https://github.com/plumthedev/yii2-php-cs-fixer-config/blob/master/LICENSE
* @version 1.2.0
*/
namespace plumthedev\PhpCsFixer;
use PhpCsFixer\Finder as PhpCsFixerFinder;
use yii\base\InvalidArgumentException;
use yii\helpers\ArrayHelper;
class Finder extends PhpCsFixerFinder
{
/**
* Yii app directories to exclude with PhpCsFixerConfig.
* @var array
*/
public $yiiAppExclude = [];
public function __construct()
{
parent::__construct();
$this->yiiAppExclude = $this->getYiiAppExclude();
$this->exclude($this->yiiAppExclude);
}
/**
* Get Yii2 App Basic directories to exclude.
*
* @see https://github.com/yiisoft/yii2-app-basic
* @return array
*/
protected function getYiiAppBasicExclude()
{
return [
'mail',
'runtime',
'vagrant',
'views',
'web',
'vendor',
'node_modules',
];
}
/**
* Get Yii2 App Advanced directories to exclude.
*
* @see https://github.com/yiisoft/yii2-app-advanced
* @return array
*/
protected function getYiiAppAdvancedExclude()
{
return [
'backend/runtime',
'backend/views',
'backend/web',
'backend/assets',
'common/mail',
'console/runtime',
'docs',
'environments',
'frontend/assets',
'frontend/runtime',
'frontend/views',
'frontend/web',
'vagrant',
'vendor',
'node_modules',
];
}
/**
* Return Yii app directories to exclude.
* If values have been specified, they will be returned,
* otherwise merge default directories for basic and advanced app.
*
* @return array Directories to exclude
*/
public function getYiiAppExclude()
{
if (!empty($this->yiiAppExclude)) {
return $this->yiiAppExclude;
}
return ArrayHelper::merge(
$this->getYiiAppBasicExclude(),
$this->getYiiAppAdvancedExclude()
);
}
/**
* Set Finder directories to exclude.
*
* @param array $yiiAppExclude Directories to exclude.
* @param bool $mergeWithDefault Whether to merge with default directories to exclude.
* @throws InvalidArgumentException Throw exception if directories to exclude is not array.
*/
public function setYiiAppExclude($yiiAppExclude, $mergeWithDefault = true)
{
if (!is_array($yiiAppExclude)) {
throw new InvalidArgumentException('Directories to exclude must be a array.');
}
if ($mergeWithDefault) {
$yiiAppExclude = ArrayHelper::merge(
$yiiAppExclude,
$this->getYiiAppExclude()
);
}
$this->yiiAppExclude = $yiiAppExclude;
}
}