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

Make more generic, remove optional parameters and go required-only #44

Merged
merged 4 commits into from
Jan 24, 2024
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
3 changes: 1 addition & 2 deletions .github/workflows/code_analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ jobs:

name: ${{ matrix.actions.name }}
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- uses: actions/checkout@v4

-
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
php-version: 8.2
coverage: none

- uses: "ramsey/composer-install@v2"
Expand Down
29 changes: 0 additions & 29 deletions .github/workflows/php_linter.yaml

This file was deleted.

10 changes: 3 additions & 7 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,18 @@ on:
branches:
- main

env:
# see https://github.com/composer/composer/issues/9368#issuecomment-718112361
COMPOSER_ROOT_VERSION: "dev-main"

jobs:
tests:
runs-on: ubuntu-latest
name: PHP 8.1 tests

steps:
- uses: actions/checkout@v2

- uses: shivammathur/setup-php@v2
with:
php-version: 8.1
coverage: none # disable xdebug, pcov
php-version: 8.2
coverage: none

- uses: "ramsey/composer-install@v1"

- run: vendor/bin/phpunit
45 changes: 21 additions & 24 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,27 @@
"homepage": "https://getrector.com",
"license": "MIT",
"require": {
"php": ">=8.1",
"php": ">=8.2",
"nette/utils": "^3.2",
"nikic/php-parser": "^4.17",
"symfony/console": "^6.3",
"symfony/finder": "^6.3",
"nikic/php-parser": "^4.18",
"symfony/console": "^6.4",
"symfony/finder": "^6.4",
"webmozart/assert": "^1.11",
"symfony/filesystem": "^6.3",
"illuminate/container": "^10.20"
"symfony/filesystem": "^6.4",
"illuminate/container": "^10.42"
},
"require-dev": {
"rector/rector-src": "dev-main",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpunit/phpunit": "^10.3",
"symplify/easy-coding-standard": "^12.0",
"symplify/phpstan-extensions": "^11.0",
"symplify/phpstan-rules": "^12.0",
"rector/rector": "dev-main",
"phpunit/phpunit": "^10.5",
"symplify/easy-coding-standard": "^12.1",
"symplify/phpstan-extensions": "^11.4",
"symplify/phpstan-rules": "^12.4",
"phpstan/extension-installer": "^1.3",
"symplify/vendor-patches": "^11.0",
"symplify/vendor-patches": "^11.3",
"phpstan/phpstan-webmozart-assert": "^1.2",
"tracy/tracy": "^2.10",
"symplify/easy-testing": "^11.1",
"tomasvotruba/class-leak": "^0.1.3",
"tomasvotruba/unused-public": "0.3.2.72",
"tomasvotruba/type-coverage": "^0.2.1",
"rector/rector": "*",
"phpstan/phpstan": "^1.10",
"tomasvotruba/cognitive-complexity": "^0.1.1"
"tracy/tracy": "^2.10.5",
"tomasvotruba/class-leak": "^0.2.6",
"phpstan/phpstan": "^1.10.55"
},
"autoload": {
"psr-4": {
Expand All @@ -54,6 +48,11 @@
"includes": [
"config/config.php"
]
},
"patches": {
"package-name": [
"https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/illuminate-container-container-php.patch"
]
}
},
"config": {
Expand All @@ -62,7 +61,5 @@
"rector/extension-installer": true,
"phpstan/extension-installer": true
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
}
17 changes: 6 additions & 11 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@
declare(strict_types=1);

use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList;

return static function (ECSConfig $ecsConfig): void {
$ecsConfig->sets([SetList::PSR_12, SetList::SYMPLIFY, SetList::COMMON, SetList::CLEAN_CODE, SetList::SYMPLIFY]);

$ecsConfig->paths([
return ECSConfig::configure()
->withPreparedSets(psr12: true, common: true, strict: true, symplify: true)
->withPaths([
__DIR__ . '/src',
__DIR__ . '/config',
__DIR__ . '/tests',
__DIR__ . '/ecs.php',
__DIR__ . '/rector.php',
__DIR__ . '/templates/rector-recipe.php',
]);

$ecsConfig->skip([__DIR__ . '/tests/RectorGenerator/Fixture', __DIR__ . '/tests/RectorGenerator/Source']);
};
])
->withRootFiles()
->withSkip([__DIR__ . '/tests/RectorGenerator/Fixture', __DIR__ . '/tests/RectorGenerator/Source']);
47 changes: 15 additions & 32 deletions src/Command/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
namespace Rector\RectorGenerator\Command;

use Rector\RectorGenerator\Exception\ShouldNotHappenException;
use Rector\RectorGenerator\FileSystem\ConfigFilesystem;
use Rector\RectorGenerator\FileSystem\PathHelper;
use Rector\RectorGenerator\Generator\RectorGenerator;
use Rector\RectorGenerator\Provider\RectorRecipeProvider;
use Rector\RectorGenerator\TemplateVariablesFactory;
use Rector\RectorGenerator\ValueObject\NamePattern;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -22,9 +19,6 @@
final class GenerateCommand extends Command
{
public function __construct(
private readonly ConfigFilesystem $configFilesystem,
private readonly SymfonyStyle $symfonyStyle,
private readonly TemplateVariablesFactory $templateVariablesFactory,
private readonly RectorRecipeProvider $rectorRecipeProvider,
private readonly RectorGenerator $rectorGenerator,
) {
Expand All @@ -39,29 +33,14 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
$rectorRecipe = $this->rectorRecipeProvider->provide();
$targetDirectory = getcwd();

$generatedFilePaths = $this->rectorGenerator->generate($rectorRecipe, $targetDirectory);

// nothing new
if ($generatedFilePaths === []) {
return self::SUCCESS;
}
$symfonyStyle = new SymfonyStyle($input, $output);

$setFilePath = $rectorRecipe->getSetFilePath();
if ($setFilePath !== null) {
$templateVariables = $this->templateVariablesFactory->createFromRectorRecipe($rectorRecipe);
$rectorRecipe = $this->rectorRecipeProvider->provide();

$this->configFilesystem->appendRectorServiceToSet(
$setFilePath,
$templateVariables,
NamePattern::RECTOR_FQN_NAME_PATTERN
);
}
$generatedFilePaths = $this->rectorGenerator->generate($rectorRecipe, getcwd());

$testCaseDirectoryPath = $this->resolveTestCaseDirectoryPath($generatedFilePaths);
$this->printSuccess($rectorRecipe->getName(), $generatedFilePaths, $testCaseDirectoryPath);
$this->printSuccess($rectorRecipe->getName(), $generatedFilePaths, $testCaseDirectoryPath, $symfonyStyle);

return self::SUCCESS;
}
Expand All @@ -76,7 +55,7 @@ private function resolveTestCaseDirectoryPath(array $generatedFilePaths): string
continue;
}

$relativeFilePath = PathHelper::getRelativePathFromDirector($generatedFilePath, getcwd());
$relativeFilePath = PathHelper::getRelativePathFromDirectory($generatedFilePath, getcwd());
return dirname($relativeFilePath);
}

Expand All @@ -86,21 +65,25 @@ private function resolveTestCaseDirectoryPath(array $generatedFilePaths): string
/**
* @param string[] $generatedFilePaths
*/
private function printSuccess(string $name, array $generatedFilePaths, string $testCaseFilePath): void
{
private function printSuccess(
string $name,
array $generatedFilePaths,
string $testCaseFilePath,
SymfonyStyle $symfonyStyle
): void {
$message = sprintf('New files generated for "%s":', $name);
$this->symfonyStyle->title($message);
$symfonyStyle->title($message);

sort($generatedFilePaths);

foreach ($generatedFilePaths as $generatedFilePath) {
$relativeFilePath = PathHelper::getRelativePathFromDirector($generatedFilePath, getcwd());
$this->symfonyStyle->writeln(' * ' . $relativeFilePath);
$relativeFilePath = PathHelper::getRelativePathFromDirectory($generatedFilePath, getcwd());
$symfonyStyle->writeln(' * ' . $relativeFilePath);
}

$message = sprintf('Make tests green again:%svendor/bin/phpunit %s', PHP_EOL . PHP_EOL, $testCaseFilePath);

$this->symfonyStyle->success($message);
$symfonyStyle->success($message);
}

private function isGeneratedFilePathTestCase(string $generatedFilePath): bool
Expand Down
27 changes: 20 additions & 7 deletions src/Command/InitRecipeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

namespace Rector\RectorGenerator\Command;

use Rector\RectorGenerator\TemplateInitializer;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Filesystem\Filesystem;

final class InitRecipeCommand extends Command
{
public function __construct(
private readonly TemplateInitializer $templateInitializer
) {
parent::__construct();
}
/**
* @var string
*/
private const RECIPE_FILE_NAME = 'rector-recipe.php';

protected function configure(): void
{
Expand All @@ -25,7 +25,20 @@ protected function configure(): void

protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->templateInitializer->initialize(__DIR__ . '/../../templates/rector-recipe.php', 'rector-recipe.php');
$symfonyStyle = new SymfonyStyle($input, $output);

$templateFilePath = __DIR__ . '/../../templates/rector-recipe.php';
$targetFilePath = getcwd() . '/' . self::RECIPE_FILE_NAME;

if (file_exists($targetFilePath)) {
$symfonyStyle->warning(sprintf('Config file "%s" already exists', self::RECIPE_FILE_NAME));
return self::SUCCESS;
}

$filesystem = new Filesystem();
$filesystem->copy($templateFilePath, $targetFilePath);

$symfonyStyle->success(sprintf('"%s" config file was added', self::RECIPE_FILE_NAME));

return self::SUCCESS;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Enum/Packages.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ final class Packages
/**
* @var string[]
*/
public const RECTOR_CORE = ['Symfony', 'Nette', 'Doctrine', 'Laravel', 'PHPUnit', 'CakePHP', 'PHPOffice'];
public const RECTOR_CORE = ['Symfony', 'Doctrine', 'PHPUnit'];
}
72 changes: 0 additions & 72 deletions src/FileSystem/ConfigFilesystem.php

This file was deleted.

Loading
Loading