Skip to content
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
20 changes: 15 additions & 5 deletions .github/workflows/bare_run.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: Bare Run on various PHP versions

on:
pull_request: null
push:
tags:
- '*'
branches:
- main

jobs:
bare_run:
Expand All @@ -12,12 +13,21 @@ jobs:
strategy:
fail-fast: false
matrix:
php_version: ['7.4', '8.0', '8.1']
php_version: ['7.4', '8.2', '8.5']

steps:
- uses: actions/checkout@v4

- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
php-version: ${{ matrix.php_version }}
coverage: none

- run: composer require rector/swiss-knife --dev --ansi
# verify sources parse on the target PHP version
- run: find bin src -name '*.php' -print0 | xargs -0 -n1 -P4 php -l

# install prod dependencies only; dev tooling targets 8.x and is irrelevant here
- run: composer install --no-dev --ignore-platform-reqs --ansi

# smoke-test the binary
- run: bin/swiss-knife
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ composer.lock
/vendor

.phpunit.cache
.phpunit.result.cache

tmp
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
"bin/swiss-knife"
],
"require": {
"php": ">=8.4",
"php": ">=7.4",
"ext-tokenizer": "*",
"entropy/entropy": "^0.4.23",
"nikic/php-parser": "^5.9"
},
"require-dev": {
"phpstan/extension-installer": "^1.4",
"phpstan/phpstan": "^2.2",
"phpunit/phpunit": "^12.5",
"phpunit/phpunit": "^9.6",
"rector/jack": "^1.1",
"rector/rector": "^2.4",
"shipmonk/composer-dependency-analyser": "^1.8",
Expand Down
1 change: 0 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
cacheDirectory=".phpunit.cache"
>
<testsuites>
<testsuite name="unit">
Expand Down
16 changes: 14 additions & 2 deletions src/Analyzer/NeedsFinalizeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,31 @@
use Rector\SwissKnife\PhpParser\NodeTraverserFactory;
use Rector\SwissKnife\PhpParser\NodeVisitor\NeedForFinalizeNodeVisitor;

final readonly class NeedsFinalizeAnalyzer
final class NeedsFinalizeAnalyzer
{
/**
* @readonly
*/
private CachedPhpParser $cachedPhpParser;

/**
* @readonly
*/
private NodeTraverser $finalizingNodeTraverser;

/**
* @readonly
*/
private NeedForFinalizeNodeVisitor $needForFinalizeNodeVisitor;

/**
* @param string[] $excludedClasses
*/
public function __construct(
array $excludedClasses,
private CachedPhpParser $cachedPhpParser
CachedPhpParser $cachedPhpParser
) {
$this->cachedPhpParser = $cachedPhpParser;
Assert::allString($excludedClasses);

$this->needForFinalizeNodeVisitor = new NeedForFinalizeNodeVisitor($excludedClasses);
Expand Down
25 changes: 19 additions & 6 deletions src/Command/CheckCommentedCodeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,27 @@
use Rector\SwissKnife\Comments\CommentedCodeAnalyzer;
use Rector\SwissKnife\Finder\PhpFilesFinder;

final readonly class CheckCommentedCodeCommand implements CommandInterface
final class CheckCommentedCodeCommand implements CommandInterface
{
private const int DEFAULT_LINE_LIMIT = 5;
/**
* @readonly
*/
private CommentedCodeAnalyzer $commentedCodeAnalyzer;

/**
* @readonly
*/
private OutputPrinter $outputPrinter;

public function __construct(
private CommentedCodeAnalyzer $commentedCodeAnalyzer,
private OutputPrinter $outputPrinter,
) {
/**
* @var int
*/
private const DEFAULT_LINE_LIMIT = 5;

public function __construct(CommentedCodeAnalyzer $commentedCodeAnalyzer, OutputPrinter $outputPrinter)
{
$this->commentedCodeAnalyzer = $commentedCodeAnalyzer;
$this->outputPrinter = $outputPrinter;
}

/**
Expand Down
20 changes: 15 additions & 5 deletions src/Command/CheckConflictsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,22 @@
use Rector\SwissKnife\Finder\FilesFinder;
use Rector\SwissKnife\Git\ConflictResolver;

final readonly class CheckConflictsCommand implements CommandInterface
final class CheckConflictsCommand implements CommandInterface
{
public function __construct(
private ConflictResolver $conflictResolver,
private OutputPrinter $outputPrinter,
) {
/**
* @readonly
*/
private ConflictResolver $conflictResolver;

/**
* @readonly
*/
private OutputPrinter $outputPrinter;

public function __construct(ConflictResolver $conflictResolver, OutputPrinter $outputPrinter)
{
$this->conflictResolver = $conflictResolver;
$this->outputPrinter = $outputPrinter;
}

/**
Expand Down
23 changes: 17 additions & 6 deletions src/Command/DuplicatedCodeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,26 @@
use Rector\SwissKnife\DuplicatedCode\CloneDetector;
use Rector\SwissKnife\Finder\PhpFilesFinder;

final readonly class DuplicatedCodeCommand implements CommandInterface
final class DuplicatedCodeCommand implements CommandInterface
{
private const int DEFAULT_MIN_LINES = 5;
/**
* @readonly
*/
private OutputPrinter $outputPrinter;

/**
* @var int
*/
private const DEFAULT_MIN_LINES = 5;

private const int DEFAULT_MIN_TOKENS = 70;
/**
* @var int
*/
private const DEFAULT_MIN_TOKENS = 70;

public function __construct(
private OutputPrinter $outputPrinter,
) {
public function __construct(OutputPrinter $outputPrinter)
{
$this->outputPrinter = $outputPrinter;
}

/**
Expand Down
34 changes: 27 additions & 7 deletions src/Command/FeaturesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,34 @@
use Rector\SwissKnife\Lines\Finder\ProjectFilesFinder;
use Rector\SwissKnife\Lines\OutputFormatter\JsonOutputFormatter;

final readonly class FeaturesCommand implements CommandInterface
final class FeaturesCommand implements CommandInterface
{
public function __construct(
private OutputPrinter $outputPrinter,
private FeatureCounterAnalyzer $featureCounterAnalyzer,
private ResultPrinter $resultPrinter,
private JsonOutputFormatter $jsonOutputFormatter,
) {
/**
* @readonly
*/
private OutputPrinter $outputPrinter;

/**
* @readonly
*/
private FeatureCounterAnalyzer $featureCounterAnalyzer;

/**
* @readonly
*/
private ResultPrinter $resultPrinter;

/**
* @readonly
*/
private JsonOutputFormatter $jsonOutputFormatter;

public function __construct(OutputPrinter $outputPrinter, FeatureCounterAnalyzer $featureCounterAnalyzer, ResultPrinter $resultPrinter, JsonOutputFormatter $jsonOutputFormatter)
{
$this->outputPrinter = $outputPrinter;
$this->featureCounterAnalyzer = $featureCounterAnalyzer;
$this->resultPrinter = $resultPrinter;
$this->jsonOutputFormatter = $jsonOutputFormatter;
}

/**
Expand Down
46 changes: 36 additions & 10 deletions src/Command/FinalizeClassesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,46 @@
use Rector\SwissKnife\ParentClassResolver;
use Rector\SwissKnife\PhpParser\CachedPhpParser;

final readonly class FinalizeClassesCommand implements CommandInterface
final class FinalizeClassesCommand implements CommandInterface
{
/**
* @readonly
*/
private OutputPrinter $outputPrinter;

/**
* @readonly
*/
private ParentClassResolver $parentClassResolver;

/**
* @readonly
*/
private EntityClassResolver $entityClassResolver;

/**
* @readonly
*/
private CachedPhpParser $cachedPhpParser;

/**
* @readonly
*/
private MockedClassResolver $mockedClassResolver;

/**
* @see https://regex101.com/r/Q5Nfbo/1
* @var string
*/
private const string NEWLINE_CLASS_START_REGEX = '#^(readonly )?class\s#m';

public function __construct(
private OutputPrinter $outputPrinter,
private ParentClassResolver $parentClassResolver,
private EntityClassResolver $entityClassResolver,
private CachedPhpParser $cachedPhpParser,
private MockedClassResolver $mockedClassResolver,
) {
private const NEWLINE_CLASS_START_REGEX = '#^(readonly )?class\s#m';

public function __construct(OutputPrinter $outputPrinter, ParentClassResolver $parentClassResolver, EntityClassResolver $entityClassResolver, CachedPhpParser $cachedPhpParser, MockedClassResolver $mockedClassResolver)
{
$this->outputPrinter = $outputPrinter;
$this->parentClassResolver = $parentClassResolver;
$this->entityClassResolver = $entityClassResolver;
$this->cachedPhpParser = $cachedPhpParser;
$this->mockedClassResolver = $mockedClassResolver;
}

/**
Expand Down
20 changes: 15 additions & 5 deletions src/Command/FindMultiClassesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,22 @@
use Rector\SwissKnife\Finder\MultipleClassInOneFileFinder;
use Rector\SwissKnife\Finder\PhpFilesFinder;

final readonly class FindMultiClassesCommand implements CommandInterface
final class FindMultiClassesCommand implements CommandInterface
{
public function __construct(
private MultipleClassInOneFileFinder $multipleClassInOneFileFinder,
private OutputPrinter $outputPrinter,
) {
/**
* @readonly
*/
private MultipleClassInOneFileFinder $multipleClassInOneFileFinder;

/**
* @readonly
*/
private OutputPrinter $outputPrinter;

public function __construct(MultipleClassInOneFileFinder $multipleClassInOneFileFinder, OutputPrinter $outputPrinter)
{
$this->multipleClassInOneFileFinder = $multipleClassInOneFileFinder;
$this->outputPrinter = $outputPrinter;
}

/**
Expand Down
34 changes: 27 additions & 7 deletions src/Command/GenerateSymfonySmokeTestsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,34 @@
use Rector\SwissKnife\SmokeTestgen\Utils\TestPathResolver;
use RuntimeException;

final readonly class GenerateSymfonySmokeTestsCommand implements CommandInterface
final class GenerateSymfonySmokeTestsCommand implements CommandInterface
{
public function __construct(
private TestsDirectoryResolver $testsDirectoryResolver,
private TestTemplateResolver $testTemplateResolver,
private TemplateDecorator $templateDecorator,
private OutputPrinter $outputPrinter,
) {
/**
* @readonly
*/
private TestsDirectoryResolver $testsDirectoryResolver;

/**
* @readonly
*/
private TestTemplateResolver $testTemplateResolver;

/**
* @readonly
*/
private TemplateDecorator $templateDecorator;

/**
* @readonly
*/
private OutputPrinter $outputPrinter;

public function __construct(TestsDirectoryResolver $testsDirectoryResolver, TestTemplateResolver $testTemplateResolver, TemplateDecorator $templateDecorator, OutputPrinter $outputPrinter)
{
$this->testsDirectoryResolver = $testsDirectoryResolver;
$this->testTemplateResolver = $testTemplateResolver;
$this->templateDecorator = $templateDecorator;
$this->outputPrinter = $outputPrinter;
}

public function getName(): string
Expand Down
Loading
Loading