Skip to content

Commit

Permalink
setup rector
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry committed Nov 21, 2023
1 parent 186f264 commit 660a3f4
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 9 deletions.
24 changes: 22 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ INFECTION_SRC := $(shell find src tests) phpunit.xml.dist
PHP_CS_FIXER_BIN = vendor-bin/php-cs-fixer/vendor/bin/php-cs-fixer
PHP_CS_FIXER = $(PHP_CS_FIXER_BIN)

RECTOR_BIN = vendor-bin/rector/vendor/bin/rector
RECTOR = $(RECTOR_BIN)

WEBSITE_SRC := mkdocs.yaml $(shell find doc)
# This is defined in mkdocs.yaml#site_dir
WEBSITE_OUTPUT = dist/website
Expand Down Expand Up @@ -157,7 +160,7 @@ cs: ## Fixes CS
cs: root_cs requirement_checker_cs

.PHONY: root_cs
root_cs: gitignore_sort composer_normalize php_cs_fixer
root_cs: gitignore_sort composer_normalize rector php_cs_fixer

.PHONY: requirement_checker_cs
requirement_checker_cs:
Expand All @@ -169,7 +172,7 @@ cs_lint: ## Lints CS
cs_lint: root_cs_lint requirement_checker_cs_lint

.PHONY: root_cs_lint
root_cs_lint: composer_normalize_lint php_cs_fixer_lint
root_cs_lint: composer_normalize_lint rector_lint php_cs_fixer_lint

.PHONY: requirement_checker_cs_lint
requirement_checker_cs_lint:
Expand All @@ -183,6 +186,14 @@ php_cs_fixer: $(PHP_CS_FIXER_BIN) dist
php_cs_fixer_lint: $(PHP_CS_FIXER_BIN) dist
$(PHP_CS_FIXER) fix --ansi --verbose --dry-run --diff

.PHONY: rector
rector: $(RECTOR_BIN)
$(RECTOR)

.PHONY: rector_lint
rector_lint: $(RECTOR_BIN)
$(RECTOR) --dry-run

.PHONY: composer_normalize
composer_normalize: composer.json vendor
composer normalize --ansi
Expand Down Expand Up @@ -354,6 +365,15 @@ vendor-bin/php-cs-fixer/composer.lock: vendor-bin/php-cs-fixer/composer.json
@echo "$(ERROR_COLOR)$(@) is not up to date. You may want to run the following command:$(NO_COLOR)"
@echo "$$ composer bin php-cs-fixer update --lock && touch -c $(@)"

$(RECTOR_BIN): vendor-bin/rector/vendor
touch -c $@
vendor-bin/rector/vendor: vendor-bin/rector/composer.lock $(COMPOSER_BIN_PLUGIN_VENDOR)
composer bin rector install
touch -c $@
vendor-bin/rector/composer.lock: vendor-bin/rector/composer.json
@echo "$(ERROR_COLOR)$(@) is not up to date. You may want to run the following command:$(NO_COLOR)"
@echo "$$ composer bin rector update --lock && touch -c $(@)"

.PHONY: infection_install
infection_install: $(INFECTION_BIN)

Expand Down
10 changes: 9 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
$rectorConfig->importNames();

$rectorConfig->sets([
LevelSetList::UP_TO_PHP_81,
LevelSetList::UP_TO_PHP_82,
]);

$rectorConfig->skip([
\Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector::class,
\Rector\Php55\Rector\String_\StringClassNameToClassConstantRector::class => [
__DIR__.'/src/Configuration/Configuration.php',
],
\Rector\Php73\Rector\String_\SensitiveHereNowDocRector::class,
]);
};
3 changes: 2 additions & 1 deletion src/Phar/PharMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use function Safe\realpath;
use function sprintf;
use function var_export;
use const JSON_THROW_ON_ERROR;
use const SORT_LOCALE_STRING;

/**
Expand Down Expand Up @@ -82,7 +83,7 @@ public static function fromPhar(Phar|PharData $phar, ?string $pubKeyContent): se

public static function fromJson(string $json): self
{
$decodedJson = json_decode($json, true);
$decodedJson = json_decode($json, true, flags: JSON_THROW_ON_ERROR);

$filesMeta = $decodedJson['filesMeta'];

Expand Down
6 changes: 4 additions & 2 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
use Composer\InstalledVersions;
use ErrorException;
use Fidry\Console\IO;
use Isolated\Symfony\Component\Finder\Finder as IsolatedFinder;
use KevinGH\Box\Console\Php\PhpSettingsHandler;
use Phar;
use Symfony\Component\Console\Helper\Helper;
use Symfony\Component\Console\Logger\ConsoleLogger;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Finder\Finder as SymfonyFinder;
use Webmozart\Assert\Assert;
use function bin2hex;
use function class_alias;
Expand Down Expand Up @@ -173,8 +175,8 @@ function format_time(float $secs): string
function register_aliases(): void
{
// Exposes the finder used by PHP-Scoper PHAR to allow its usage in the configuration file.
if (false === class_exists(\Isolated\Symfony\Component\Finder\Finder::class)) {
class_alias(\Symfony\Component\Finder\Finder::class, \Isolated\Symfony\Component\Finder\Finder::class);
if (false === class_exists(IsolatedFinder::class)) {
class_alias(SymfonyFinder::class, IsolatedFinder::class);
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/RequirementChecker/DecodedComposerJsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace KevinGH\Box\RequirementChecker;

use PHPUnit\Framework\TestCase;
use function json_decode;
use function Safe\json_decode;

/**
* @covers \KevinGH\Box\RequirementChecker\DecodedComposerJson
Expand Down
2 changes: 1 addition & 1 deletion tests/RequirementChecker/DecodedComposerLockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
namespace KevinGH\Box\RequirementChecker;

use PHPUnit\Framework\TestCase;
use function json_decode;
use function Safe\json_decode;

/**
* @covers \KevinGH\Box\RequirementChecker\DecodedComposerLock
Expand Down
2 changes: 1 addition & 1 deletion vendor-bin/rector/composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"require-dev": {
"rector/rector": "^0.14"
"rector/rector": ">=0.14"
}
}

0 comments on commit 660a3f4

Please sign in to comment.