Skip to content

Commit e25f654

Browse files
authored
Add --skip-file to finalize command (#54)
* Add --skip-file to finalize command * cleanup * misc
1 parent c417816 commit e25f654

File tree

6 files changed

+35
-8
lines changed

6 files changed

+35
-8
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ This will keep mocked classes non-final, so PHPUnit can extend them internally.
102102
103103
<br>
104104
105+
Do you want to skip file or two?
106+
107+
```bash
108+
vendor/bin/swiss-knife finalize-classes src tests --skip-file src/SpecialProxy.php
109+
```
110+
111+
<br>
112+
105113
### 5. Privatize local class constants
106114
107115
PHPStan can report unused private class constants, but it skips all the public ones.

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
"phpstan/phpstan": "^1.11",
2121
"phpunit/phpunit": "^10.5",
2222
"rector/rector": "^1.0",
23+
"rector/type-perfect": "^0.2.0",
2324
"shipmonk/composer-dependency-analyser": "^1.7",
2425
"symplify/easy-coding-standard": "^12.3",
2526
"tomasvotruba/class-leak": "^0.2.16",
2627
"tomasvotruba/type-coverage": "^0.3.1",
28+
"tomasvotruba/unused-public": "^0.3.11",
2729
"tracy/tracy": "^2.10"
2830
},
2931
"autoload": {

phpstan.neon

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,29 @@ parameters:
99
- */Fixture/*
1010
- */Source/*
1111

12+
type_perfect:
13+
null_over_false: true
14+
no_mixed_property: true
15+
no_mixed_caller: true
16+
narrow_param: true
17+
narrow_return: true
18+
1219
type_coverage:
1320
return: 99
1421
param: 99
1522
property: 99
1623
constant: 99
1724

25+
unused_public:
26+
constants: true
27+
properties: true
28+
methods: true
29+
1830
ignoreErrors:
1931
# unrelated
2032
- '#Parameter \#1 \$className of class Rector\\SwissKnife\\ValueObject\\ClassConstant constructor expects class-string, string given#'
2133

2234
- '#Parameter \#1 \$objectOrClass of class ReflectionClass constructor expects class-string<T of object>\|T of object, string given#'
35+
36+
# false positive callable/closure in type-perfect
37+
- '#Parameters should have "array\|\(Closure\)\|null" types as the only types passed to this method#'

src/Command/FinalizeClassesCommand.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ protected function configure(): void
5353
'Skip mocked classes as well (use only if unable to run bypass-finals package)'
5454
);
5555

56+
$this->addOption(
57+
'skip-file',
58+
null,
59+
InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED,
60+
'Skip file or files by path'
61+
);
62+
5663
$this->addOption(
5764
'dry-run',
5865
null,
@@ -72,7 +79,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7279

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

75-
$phpFileInfos = PhpFilesFinder::find($paths);
82+
$skippedFiles = $input->getOption('skip-file');
83+
$phpFileInfos = PhpFilesFinder::find($paths, $skippedFiles);
7684

7785
// double to count for both parent and entity resolver
7886
$stepRatio = $areMockedSkipped ? 3 : 2;

src/PhpParser/NodeVisitor/FindNonPrivateClassConstNodeVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function enterNode(Node $node): ?Node
4545
continue;
4646
}
4747

48-
$this->classConstants[] = new ClassConstant($className, $constantName, $classConst->getLine());
48+
$this->classConstants[] = new ClassConstant($className, $constantName);
4949
}
5050
}
5151

src/ValueObject/ClassConstant.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
public function __construct(
1515
private string $className,
1616
private string $constantName,
17-
private int $line
1817
) {
1918
Assert::notEmpty($constantName);
2019
Assert::notEmpty($className);
@@ -29,9 +28,4 @@ public function getConstantName(): string
2928
{
3029
return $this->constantName;
3130
}
32-
33-
public function getLine(): int
34-
{
35-
return $this->line;
36-
}
3731
}

0 commit comments

Comments
 (0)