This repository has been archived by the owner on Mar 1, 2023. It is now read-only.
generated from narrowspark/php-library-template
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrector.php
84 lines (68 loc) · 3.04 KB
/
rector.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
<?php
declare(strict_types=1);
/**
* Copyright (c) 2020-2021 Daniel Bannert
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/narrowspark/automatic-versions
*/
use Nette\Utils\FileSystem;
use Nette\Utils\Strings;
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersion;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
// paths to refactor; solid alternative to CLI arguments
$parameters->set(Option::PATHS, [__DIR__ . '/bin', __DIR__ . '/src', __DIR__ . '/tests']);
// is your PHP version different from the one your refactor to? [default: your PHP version], uses PHP_VERSION_ID format
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_80);
// auto import fully qualified class names? [default: false]
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
// skip root namespace classes, like \DateTime or \Exception [default: true]
$parameters->set(Option::IMPORT_SHORT_CLASSES, false);
// skip classes used in PHP DocBlocks, like in /** @var \Some\Class */ [default: true]
$parameters->set(Option::IMPORT_DOC_BLOCKS, false);
// Run Rector only on changed files
$parameters->set(Option::ENABLE_CACHE, true);
$phpstanPath = getcwd() . '/phpstan.neon';
$phpstanNeonContent = FileSystem::read($phpstanPath);
$bleedingEdgePattern = '#\n\s+-(.*?)bleedingEdge\.neon[\'|"]?#';
// bleeding edge clean out, see https://github.com/rectorphp/rector/issues/2431
if (Strings::match($phpstanNeonContent, $bleedingEdgePattern)) {
$temporaryPhpstanNeon = getcwd() . '/rector-temp-phpstan.neon';
$clearedPhpstanNeonContent = Strings::replace($phpstanNeonContent, $bleedingEdgePattern);
FileSystem::write($temporaryPhpstanNeon, $clearedPhpstanNeonContent);
$phpstanPath = $temporaryPhpstanNeon;
}
// Path to phpstan with extensions, that PHPStan in Rector uses to determine types
$parameters->set(Option::PHPSTAN_FOR_RECTOR_PATH, $phpstanPath);
$parameters->set(Option::SETS, [
SetList::CODING_STYLE,
SetList::CODE_QUALITY,
SetList::CODE_QUALITY_STRICT,
SetList::DEAD_CODE,
SetList::PRIVATIZATION,
SetList::NAMING,
SetList::TYPE_DECLARATION,
SetList::ORDER,
SetList::PHP_71,
SetList::PHP_72,
SetList::PHP_73,
SetList::PHP_74,
SetList::PHP_80,
SetList::EARLY_RETURN,
SetList::TYPE_DECLARATION_STRICT,
SetList::PSR_4,
SetList::SAFE_07,
PHPUnitSetList::PHPUNIT_CODE_QUALITY,
PHPUnitSetList::PHPUNIT_91,
PHPUnitSetList::PHPUNIT_EXCEPTION,
PHPUnitSetList::PHPUNIT_YIELD_DATA_PROVIDER,
PHPUnitSetList::PHPUNIT_SPECIFIC_METHOD,
]);
};