|
4 | 4 | *
|
5 | 5 | * @author Kacper Pruszynski (plumthedev)
|
6 | 6 | * @link https://github.com/plumthedev/yii2-php-cs-fixer-config
|
7 |
| - * @copyright Copyright (c) 2019 plumthedev |
| 7 | + * @copyright Copyright (c) 2019 - 2019 plumthedev |
8 | 8 | * @license https://github.com/plumthedev/yii2-php-cs-fixer-config/blob/master/LICENSE
|
9 | 9 | * @version 1.0.1
|
10 | 10 | */
|
11 | 11 |
|
12 | 12 | namespace plumthedev\PhpCsFixer;
|
13 | 13 |
|
14 | 14 | use PhpCsFixer\Finder as PhpCsFixerFinder;
|
| 15 | +use yii\base\InvalidArgumentException; |
| 16 | +use yii\helpers\ArrayHelper; |
15 | 17 |
|
16 | 18 | class Finder extends PhpCsFixerFinder
|
17 | 19 | {
|
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 = []; |
26 | 25 |
|
27 | 26 | public function __construct()
|
28 | 27 | {
|
29 | 28 | 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; |
31 | 118 | }
|
32 | 119 | }
|
0 commit comments