Skip to content

Commit

Permalink
Add --skip-file to finalize command (#54)
Browse files Browse the repository at this point in the history
* Add --skip-file to finalize command

* cleanup

* misc
  • Loading branch information
TomasVotruba authored Sep 13, 2024
1 parent c417816 commit e25f654
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 8 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ This will keep mocked classes non-final, so PHPUnit can extend them internally.
<br>
Do you want to skip file or two?
```bash
vendor/bin/swiss-knife finalize-classes src tests --skip-file src/SpecialProxy.php
```
<br>
### 5. Privatize local class constants
PHPStan can report unused private class constants, but it skips all the public ones.
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
"phpstan/phpstan": "^1.11",
"phpunit/phpunit": "^10.5",
"rector/rector": "^1.0",
"rector/type-perfect": "^0.2.0",
"shipmonk/composer-dependency-analyser": "^1.7",
"symplify/easy-coding-standard": "^12.3",
"tomasvotruba/class-leak": "^0.2.16",
"tomasvotruba/type-coverage": "^0.3.1",
"tomasvotruba/unused-public": "^0.3.11",
"tracy/tracy": "^2.10"
},
"autoload": {
Expand Down
15 changes: 15 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,29 @@ parameters:
- */Fixture/*
- */Source/*

type_perfect:
null_over_false: true
no_mixed_property: true
no_mixed_caller: true
narrow_param: true
narrow_return: true

type_coverage:
return: 99
param: 99
property: 99
constant: 99

unused_public:
constants: true
properties: true
methods: true

ignoreErrors:
# unrelated
- '#Parameter \#1 \$className of class Rector\\SwissKnife\\ValueObject\\ClassConstant constructor expects class-string, string given#'

- '#Parameter \#1 \$objectOrClass of class ReflectionClass constructor expects class-string<T of object>\|T of object, string given#'

# false positive callable/closure in type-perfect
- '#Parameters should have "array\|\(Closure\)\|null" types as the only types passed to this method#'
10 changes: 9 additions & 1 deletion src/Command/FinalizeClassesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ protected function configure(): void
'Skip mocked classes as well (use only if unable to run bypass-finals package)'
);

$this->addOption(
'skip-file',
null,
InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED,
'Skip file or files by path'
);

$this->addOption(
'dry-run',
null,
Expand All @@ -72,7 +79,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$this->symfonyStyle->title('1. Detecting parent and entity classes');

$phpFileInfos = PhpFilesFinder::find($paths);
$skippedFiles = $input->getOption('skip-file');
$phpFileInfos = PhpFilesFinder::find($paths, $skippedFiles);

// double to count for both parent and entity resolver
$stepRatio = $areMockedSkipped ? 3 : 2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function enterNode(Node $node): ?Node
continue;
}

$this->classConstants[] = new ClassConstant($className, $constantName, $classConst->getLine());
$this->classConstants[] = new ClassConstant($className, $constantName);
}
}

Expand Down
6 changes: 0 additions & 6 deletions src/ValueObject/ClassConstant.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
public function __construct(
private string $className,
private string $constantName,
private int $line
) {
Assert::notEmpty($constantName);
Assert::notEmpty($className);
Expand All @@ -29,9 +28,4 @@ public function getConstantName(): string
{
return $this->constantName;
}

public function getLine(): int
{
return $this->line;
}
}

0 comments on commit e25f654

Please sign in to comment.