Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Add rector as part of the process #1183

Merged
merged 14 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/auto-review.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ jobs:
- name: Ensure that the PHP-CS-Fixer make target is up to date
run: make php_cs_fixer_install

- name: Install Rector
uses: ramsey/composer-install@v2
with:
working-directory: vendor-bin/rector

- name: Ensure that the PHP-CS-Fixer make target is up to date
run: make rector_install

- run: make root_cs_lint

composer-validate:
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/requirement-checker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ jobs:
- name: Ensure that the PHP-CS-Fixer make target is up to date
run: make php_cs_fixer_install

- name: Install Rector
uses: ramsey/composer-install@v2
with:
working-directory: vendor-bin/rector

- name: Ensure that the PHP-CS-Fixer make target is up to date
run: make rector_install

- name: Install the Composer dependencies
uses: ramsey/composer-install@v2
with:
Expand Down
27 changes: 25 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ PHPBENCH = $(PHPBENCH_BIN)
PHPBENCH_WITH_COMPACTORS_VENDOR_DIR = fixtures/bench/with-compactors/vendor
PHPBENCH_WITHOUT_COMPACTORS_VENDOR_DIR = fixtures/bench/without-compactors/vendor

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 @@ -162,7 +165,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 @@ -174,7 +177,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 @@ -188,6 +191,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 @@ -406,6 +417,18 @@ vendor-bin/phpbench/composer.lock: vendor-bin/phpbench/composer.json
@echo "$(ERROR_COLOR)$(@) is not up to date. You may want to run the following command:$(NO_COLOR)"
@echo "$$ composer bin phpbench update --lock && touch -c $(@)"

.PHONY: rector_install
rector_install: $(RECTOR_BIN)

$(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
11 changes: 10 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
$rectorConfig->importNames();

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

$rectorConfig->skip([
\Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector::class,
\Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector::class,
\Rector\Php55\Rector\String_\StringClassNameToClassConstantRector::class => [
__DIR__.'/src/Configuration/Configuration.php',
],
\Rector\Php73\Rector\String_\SensitiveHereNowDocRector::class,
]);
};
32 changes: 30 additions & 2 deletions requirement-checker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ PHAR_EXTRACT = ../res/requirement-checker
BOX_BIN = ../bin/box
BOX = $(BOX_BIN)

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

DIFF = diff --strip-trailing-cr --ignore-all-space --side-by-side --suppress-common-lines


Expand Down Expand Up @@ -109,11 +112,11 @@ phpunit_autoreview: $(PHPUNIT_BIN) vendor

.PHONY: cs
cs: ## Fixes CS
cs: gitignore_sort composer_normalize php_cs_fixer
cs: gitignore_sort composer_normalize rector php_cs_fixer

.PHONY: cs_lint
cs_lint: ## Checks CS
cs_lint: composer_normalize_lint php_cs_fixer_lint
cs_lint: composer_normalize_lint rector_lint php_cs_fixer_lint

.PHONY: gitignore_sort
gitignore_sort:
Expand All @@ -135,6 +138,28 @@ php_cs_fixer: $(PHP_CS_FIXER_BIN)
php_cs_fixer_lint: $(PHP_CS_FIXER_BIN)
$(PHP_CS_FIXER) fix --ansi --verbose --dry-run --diff

.PHONY: rector
rector: rector_src rector_tests

.PHONY: rector_src
rector_src: $(RECTOR_BIN)
$(RECTOR) --config=rector-src.php

.PHONY: rector_tests
rector_tests: $(RECTOR_BIN)
$(RECTOR) --config=rector-tests.php

.PHONY: rector_lint
rector_lint: rector_lint_src rector_lint_tests

.PHONY: rector_lint_src
rector_lint_src: $(RECTOR_BIN)
$(RECTOR) --config=rector-src.php --dry-run

.PHONY: rector_lint_tests
rector_lint_tests: $(RECTOR_BIN)
$(RECTOR) --config=rector-tests.php --dry-run


#
# Tests
Expand Down Expand Up @@ -240,3 +265,6 @@ $(PHAR_EXTRACT): $(PHAR) $(BOX_BIN)

$(BOX_BIN):
cd ..; $(MAKE) --file=Makefile bin/box

$(RECTOR_BIN):
cd ..; $(MAKE) --file=Makefile rector_install
22 changes: 22 additions & 0 deletions requirement-checker/rector-src.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\DowngradeLevelSetList;
use Rector\Set\ValueObject\LevelSetList;

$applyCommonConfig = require __DIR__.'/rector.php';

return static function (RectorConfig $rectorConfig) use ($applyCommonConfig): void {
$applyCommonConfig($rectorConfig);

$rectorConfig->paths([
__DIR__ . '/src',
]);

$rectorConfig->sets([
LevelSetList::UP_TO_PHP_72,
// DowngradeLevelSetList::DOWN_TO_PHP_72,
]);
};
25 changes: 25 additions & 0 deletions requirement-checker/rector-tests.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
use Rector\Set\ValueObject\LevelSetList;

$applyCommonConfig = require __DIR__.'/rector.php';

return static function (RectorConfig $rectorConfig) use ($applyCommonConfig): void {
$applyCommonConfig($rectorConfig);

$rectorConfig->paths([
__DIR__ . '/tests',
]);

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

$rectorConfig->skip([
ClosureToArrowFunctionRector::class
]);
};
17 changes: 17 additions & 0 deletions requirement-checker/rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\DowngradeLevelSetList;
use Rector\Set\ValueObject\LevelSetList;

// Common configuration
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->autoloadPaths([
__DIR__ . '/vendor/autoload.php',
__DIR__ . '/../vendor-bin/rector/vendor/autoload.php',
]);

$rectorConfig->importNames();
};
4 changes: 1 addition & 3 deletions requirement-checker/src/RequirementCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ final class RequirementCollection implements IteratorAggregate, Countable
*/
public function __construct($phpIniPath = null)
{
$this->phpIniPath = null === $phpIniPath
? get_cfg_var('cfg_file_path')
: $phpIniPath;
$this->phpIniPath = $phpIniPath ?? get_cfg_var('cfg_file_path');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion requirement-checker/tests/RequirementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function __invoke(): bool
$requirement->isFulfilled();

self::fail('Expected exception to be thrown.');
} catch (Error $error) {
} catch (Error) {
self::assertTrue(true);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Annotation/DocblockAnnotationParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ final class DocblockAnnotationParser
/**
* @var array<string, mixed>
*/
private array $ignoredAnnotationsAsKeys;
private readonly array $ignoredAnnotationsAsKeys;

/**
* @param string[] $ignoredAnnotations
*/
public function __construct(
private DocBlockFactoryInterface $factory,
private Formatter $tagsFormatter,
private readonly DocBlockFactoryInterface $factory,
private readonly Formatter $tagsFormatter,
array $ignoredAnnotations,
) {
$this->ignoredAnnotationsAsKeys = array_flip($ignoredAnnotations);
Expand Down
6 changes: 3 additions & 3 deletions src/Box.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,12 +463,12 @@ private function processContents(array $files): array

// Keep the fully qualified call here since this function may be executed without the right autoloading
// mechanism
\KevinGH\Box\register_aliases();
register_aliases();
if ($enableParallelization) {
\KevinGH\Box\register_error_handler();
register_error_handler();
}

$contents = \Fidry\FileSystem\FS::getFileContents($file);
$contents = FS::getFileContents($file);

$local = $mapFile($file);

Expand Down
2 changes: 1 addition & 1 deletion src/Compactor/Compactors.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class Compactors implements Compactor, Countable
/**
* @var Compactor[]
*/
private array $compactors;
private readonly array $compactors;

private ?PhpScoper $scoperCompactor = null;

Expand Down
2 changes: 1 addition & 1 deletion src/Compactor/FileExtensionCompactor.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ abstract class FileExtensionCompactor extends BaseCompactor
/**
* @var string[]
*/
private array $extensions;
private readonly array $extensions;

/**
* @param string[] $extensions the list of supported file extensions
Expand Down
2 changes: 1 addition & 1 deletion src/Compactor/Php.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static function create(array $ignoredAnnotations): self
}

public function __construct(
private ?DocblockAnnotationParser $annotationParser,
private readonly ?DocblockAnnotationParser $annotationParser,
array $extensions = ['php'],
) {
parent::__construct($extensions);
Expand Down
2 changes: 1 addition & 1 deletion src/Compactor/PhpScoper.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
/**
* @private
*/
final class PhpScoper implements Compactor
final readonly class PhpScoper implements Compactor
{
public function __construct(private Scoper $scoper)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Compactor/Placeholder.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class Placeholder implements Compactor
/**
* @var scalar[]
*/
private array $placeholders;
private readonly array $placeholders;

/**
* @param scalar[] $placeholders
Expand Down
2 changes: 1 addition & 1 deletion src/Composer/CompilerPsrLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
final class CompilerPsrLogger extends AbstractLogger
{
public function __construct(
private CompilerLogger $decoratedLogger,
private readonly CompilerLogger $decoratedLogger,
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/Composer/ComposerFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

final class ComposerFile
{
private ?string $path;
private array $contents;
private readonly ?string $path;
private readonly array $contents;

public static function createEmpty(): self
{
Expand Down
8 changes: 4 additions & 4 deletions src/Composer/ComposerFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use function array_map;
use function array_values;

final class ComposerFiles
final readonly class ComposerFiles
{
public static function createEmpty(): self
{
Expand All @@ -30,9 +30,9 @@ public static function createEmpty(): self
}

public function __construct(
private readonly ComposerFile $composerJson,
private readonly ComposerFile $composerLock,
private readonly ComposerFile $installedJson,
private ComposerFile $composerJson,
private ComposerFile $composerLock,
private ComposerFile $installedJson,
) {
}

Expand Down
6 changes: 3 additions & 3 deletions src/Composer/ComposerOrchestrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public static function create(): self
}

public function __construct(
private ComposerProcessFactory $processFactory,
private LoggerInterface $logger,
private FileSystem $fileSystem,
private readonly ComposerProcessFactory $processFactory,
private readonly LoggerInterface $logger,
private readonly FileSystem $fileSystem,
) {
}

Expand Down
Loading
Loading