Skip to content

Commit b31b9d8

Browse files
committed
Removed tip about inferPrivatePropertyTypeFromConstructor`
1 parent 9a7ce62 commit b31b9d8

16 files changed

+7
-138
lines changed

conf/config.neon

-3
Original file line numberDiff line numberDiff line change
@@ -1137,9 +1137,6 @@ services:
11371137
class: PHPStan\Command\ErrorFormatter\TableErrorFormatter
11381138
arguments:
11391139
showTipsOfTheDay: %tipsOfTheDay%
1140-
checkThisOnly: %checkThisOnly%
1141-
inferPrivatePropertyTypeFromConstructor: %inferPrivatePropertyTypeFromConstructor%
1142-
checkMissingTypehints: %checkMissingTypehints%
11431140

11441141
errorFormatter.checkstyle:
11451142
class: PHPStan\Command\ErrorFormatter\CheckstyleErrorFormatter

src/Analyser/Analyser.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public function analyse(
6363
$errors = [];
6464
$internalErrorsCount = 0;
6565
$reachedInternalErrorsCountLimit = false;
66-
$inferrablePropertyTypesFromConstructorHelper = new InferrablePropertyTypesFromConstructorHelper();
6766
$dependencies = [];
6867
foreach ($files as $file) {
6968
if ($preFileCallback !== null) {
@@ -75,7 +74,7 @@ public function analyse(
7574
$file,
7675
$allAnalysedFiles,
7776
$this->registry,
78-
$inferrablePropertyTypesFromConstructorHelper
77+
null
7978
);
8079
$errors = array_merge($errors, $fileAnalyserResult->getErrors());
8180
$dependencies[$file] = $fileAnalyserResult->getDependencies();
@@ -112,7 +111,6 @@ public function analyse(
112111
return new AnalyserResult(
113112
$errors,
114113
[],
115-
$inferrablePropertyTypesFromConstructorHelper->hasInferrablePropertyTypesFromConstructor(),
116114
$internalErrorsCount === 0 ? $dependencies : null,
117115
$reachedInternalErrorsCountLimit
118116
);

src/Analyser/AnalyserResult.php

-11
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ class AnalyserResult
1414
/** @var string[] */
1515
private $internalErrors;
1616

17-
/** @var bool */
18-
private $hasInferrablePropertyTypesFromConstructor;
19-
2017
/** @var array<string, array<string>>|null */
2118
private $dependencies;
2219

@@ -26,14 +23,12 @@ class AnalyserResult
2623
/**
2724
* @param \PHPStan\Analyser\Error[] $errors
2825
* @param string[] $internalErrors
29-
* @param bool $hasInferrablePropertyTypesFromConstructor
3026
* @param array<string, array<string>>|null $dependencies
3127
* @param bool $reachedInternalErrorsCountLimit
3228
*/
3329
public function __construct(
3430
array $errors,
3531
array $internalErrors,
36-
bool $hasInferrablePropertyTypesFromConstructor,
3732
?array $dependencies,
3833
bool $reachedInternalErrorsCountLimit
3934
)
@@ -57,7 +52,6 @@ static function (Error $a, Error $b): int {
5752

5853
$this->errors = $errors;
5954
$this->internalErrors = $internalErrors;
60-
$this->hasInferrablePropertyTypesFromConstructor = $hasInferrablePropertyTypesFromConstructor;
6155
$this->dependencies = $dependencies;
6256
$this->reachedInternalErrorsCountLimit = $reachedInternalErrorsCountLimit;
6357
}
@@ -86,11 +80,6 @@ public function getInternalErrors(): array
8680
return $this->internalErrors;
8781
}
8882

89-
public function hasInferrablePropertyTypesFromConstructor(): bool
90-
{
91-
return $this->hasInferrablePropertyTypesFromConstructor;
92-
}
93-
9483
/**
9584
* @return array<string, array<string>>|null
9685
*/

src/Analyser/InferrablePropertyTypesFromConstructorHelper.php

-53
This file was deleted.

src/Analyser/ResultCache/ResultCacheManager.php

-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ public function process(AnalyserResult $analyserResult, ResultCache $resultCache
215215
return new AnalyserResult(
216216
$flatErrors,
217217
$internalErrors,
218-
$analyserResult->hasInferrablePropertyTypesFromConstructor(),
219218
$dependencies,
220219
$analyserResult->hasReachedInternalErrorsCountLimit()
221220
);

src/Command/AnalyseApplication.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ public function analyse(
103103
$ignoredErrorHelperResult = $this->ignoredErrorHelper->initialize();
104104
if (count($ignoredErrorHelperResult->getErrors()) > 0) {
105105
$errors = $ignoredErrorHelperResult->getErrors();
106-
$hasInferrablePropertyTypesFromConstructor = false;
107106
$warnings = [];
108107
} else {
109108
$resultCache = $this->resultCacheManager->restore($files, $debug);
@@ -117,7 +116,6 @@ public function analyse(
117116
$input
118117
);
119118
$analyserResult = $this->resultCacheManager->process($intermediateAnalyserResult, $resultCache);
120-
$hasInferrablePropertyTypesFromConstructor = $analyserResult->hasInferrablePropertyTypesFromConstructor();
121119
$internalErrors = $analyserResult->getInternalErrors();
122120
$errors = $ignoredErrorHelperResult->process($analyserResult->getErrors(), $onlyFiles, $files, count($internalErrors) > 0 || $analyserResult->hasReachedInternalErrorsCountLimit());
123121
$warnings = $ignoredErrorHelperResult->getWarnings();
@@ -145,7 +143,6 @@ public function analyse(
145143
$notFileSpecificErrors,
146144
$warnings,
147145
$defaultLevelUsed,
148-
$hasInferrablePropertyTypesFromConstructor,
149146
$projectConfigFile
150147
);
151148
}
@@ -170,7 +167,7 @@ private function runAnalyser(
170167
$errorOutput->getStyle()->progressStart($allAnalysedFilesCount);
171168
$errorOutput->getStyle()->progressAdvance($allAnalysedFilesCount);
172169
$errorOutput->getStyle()->progressFinish();
173-
return new AnalyserResult([], [], false, [], false);
170+
return new AnalyserResult([], [], [], false);
174171
}
175172

176173
/** @var bool $runningInParallel */

src/Command/AnalysisResult.php

-11
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ class AnalysisResult
1919
/** @var bool */
2020
private $defaultLevelUsed;
2121

22-
/** @var bool */
23-
private $hasInferrablePropertyTypesFromConstructor;
24-
2522
/** @var string|null */
2623
private $projectConfigFile;
2724

@@ -30,15 +27,13 @@ class AnalysisResult
3027
* @param string[] $notFileSpecificErrors
3128
* @param string[] $warnings
3229
* @param bool $defaultLevelUsed
33-
* @param bool $hasInferrablePropertyTypesFromConstructor
3430
* @param string|null $projectConfigFile
3531
*/
3632
public function __construct(
3733
array $fileSpecificErrors,
3834
array $notFileSpecificErrors,
3935
array $warnings,
4036
bool $defaultLevelUsed,
41-
bool $hasInferrablePropertyTypesFromConstructor,
4237
?string $projectConfigFile
4338
)
4439
{
@@ -61,7 +56,6 @@ static function (Error $a, Error $b): int {
6156
$this->notFileSpecificErrors = $notFileSpecificErrors;
6257
$this->warnings = $warnings;
6358
$this->defaultLevelUsed = $defaultLevelUsed;
64-
$this->hasInferrablePropertyTypesFromConstructor = $hasInferrablePropertyTypesFromConstructor;
6559
$this->projectConfigFile = $projectConfigFile;
6660
}
6761

@@ -109,11 +103,6 @@ public function isDefaultLevelUsed(): bool
109103
return $this->defaultLevelUsed;
110104
}
111105

112-
public function hasInferrablePropertyTypesFromConstructor(): bool
113-
{
114-
return $this->hasInferrablePropertyTypesFromConstructor;
115-
}
116-
117106
public function getProjectConfigFile(): ?string
118107
{
119108
return $this->projectConfigFile;

src/Command/ErrorFormatter/TableErrorFormatter.php

+1-37
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,13 @@ class TableErrorFormatter implements ErrorFormatter
1616
/** @var bool */
1717
private $showTipsOfTheDay;
1818

19-
/** @var bool */
20-
private $checkThisOnly;
21-
22-
/** @var bool */
23-
private $inferPrivatePropertyTypeFromConstructor;
24-
25-
/** @var bool */
26-
private $checkMissingTypehints;
27-
2819
public function __construct(
2920
RelativePathHelper $relativePathHelper,
30-
bool $showTipsOfTheDay,
31-
bool $checkThisOnly,
32-
bool $inferPrivatePropertyTypeFromConstructor,
33-
bool $checkMissingTypehints
21+
bool $showTipsOfTheDay
3422
)
3523
{
3624
$this->relativePathHelper = $relativePathHelper;
3725
$this->showTipsOfTheDay = $showTipsOfTheDay;
38-
$this->checkThisOnly = $checkThisOnly;
39-
$this->inferPrivatePropertyTypeFromConstructor = $inferPrivatePropertyTypeFromConstructor;
40-
$this->checkMissingTypehints = $checkMissingTypehints;
4126
}
4227

4328
public function formatErrors(
@@ -52,21 +37,6 @@ public function formatErrors(
5237

5338
$style = $output->getStyle();
5439

55-
$showInferPropertiesTip = function () use ($output, $analysisResult, $projectConfigFile): void {
56-
if (
57-
$this->checkThisOnly
58-
|| !$analysisResult->hasInferrablePropertyTypesFromConstructor()
59-
|| $this->inferPrivatePropertyTypeFromConstructor
60-
) {
61-
return;
62-
}
63-
64-
$output->writeLineFormatted('💡 Tip of the Day:');
65-
$output->writeLineFormatted("One or more properties in your code do not have a phpDoc with a type\nbut it could be inferred from the constructor to find more bugs.");
66-
$output->writeLineFormatted(sprintf('Use <fg=cyan>inferPrivatePropertyTypeFromConstructor: true</> in your <fg=cyan>%s</> to try it out!', $projectConfigFile));
67-
$output->writeLineFormatted('');
68-
};
69-
7040
if (!$analysisResult->hasErrors() && !$analysisResult->hasWarnings()) {
7141
$style->success('No errors');
7242
if ($this->showTipsOfTheDay) {
@@ -78,8 +48,6 @@ public function formatErrors(
7848
AnalyseCommand::DEFAULT_LEVEL
7949
));
8050
$output->writeLineFormatted('');
81-
} else {
82-
$showInferPropertiesTip();
8351
}
8452
}
8553

@@ -140,10 +108,6 @@ public function formatErrors(
140108
$style->warning($finalMessage);
141109
}
142110

143-
if ($this->checkMissingTypehints && $this->showTipsOfTheDay) {
144-
$showInferPropertiesTip();
145-
}
146-
147111
return $analysisResult->getTotalErrorsCount() > 0 ? 1 : 0;
148112
}
149113

src/Command/WorkerCommand.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Clue\React\NDJson\Encoder;
77
use PHPStan\Analyser\Error;
88
use PHPStan\Analyser\FileAnalyser;
9-
use PHPStan\Analyser\InferrablePropertyTypesFromConstructorHelper;
109
use PHPStan\Analyser\NodeScopeResolver;
1110
use PHPStan\DependencyInjection\Container;
1211
use PHPStan\Rules\Registry;
@@ -146,7 +145,6 @@ private function runWorker(
146145
'errors' => [$error->getMessage()],
147146
'dependencies' => [],
148147
'filesCount' => 0,
149-
'hasInferrablePropertyTypesFromConstructor' => false,
150148
'internalErrorsCount' => 1,
151149
],
152150
]);
@@ -171,10 +169,9 @@ private function runWorker(
171169
$files = $json['files'];
172170
$errors = [];
173171
$dependencies = [];
174-
$inferrablePropertyTypesFromConstructorHelper = new InferrablePropertyTypesFromConstructorHelper();
175172
foreach ($files as $file) {
176173
try {
177-
$fileAnalyserResult = $fileAnalyser->analyseFile($file, $analysedFiles, $registry, $inferrablePropertyTypesFromConstructorHelper);
174+
$fileAnalyserResult = $fileAnalyser->analyseFile($file, $analysedFiles, $registry, null);
178175
$fileErrors = $fileAnalyserResult->getErrors();
179176
$dependencies[$file] = $fileAnalyserResult->getDependencies();
180177
foreach ($fileErrors as $fileError) {
@@ -199,7 +196,6 @@ private function runWorker(
199196
'errors' => $errors,
200197
'dependencies' => $dependencies,
201198
'filesCount' => count($files),
202-
'hasInferrablePropertyTypesFromConstructor' => $inferrablePropertyTypesFromConstructorHelper->hasInferrablePropertyTypesFromConstructor(),
203199
'internalErrorsCount' => $internalErrorsCount,
204200
]]);
205201
});

src/Parallel/ParallelAnalyser.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ public function analyse(
6161
$numberOfProcesses = $schedule->getNumberOfProcesses();
6262
$errors = [];
6363
$internalErrors = [];
64-
$hasInferrablePropertyTypesFromConstructor = false;
6564

6665
$server = new \React\Socket\TcpServer('127.0.0.1:0', $loop);
6766
$this->processPool = new ProcessPool($server);
@@ -117,7 +116,7 @@ public function analyse(
117116
$processIdentifier,
118117
$input
119118
), $loop, $this->processTimeout);
120-
$process->start(function (array $json) use ($process, &$internalErrors, &$errors, &$dependencies, &$jobs, $postFileCallback, &$hasInferrablePropertyTypesFromConstructor, &$internalErrorsCount, &$reachedInternalErrorsCountLimit, $processIdentifier): void {
119+
$process->start(function (array $json) use ($process, &$internalErrors, &$errors, &$dependencies, &$jobs, $postFileCallback, &$internalErrorsCount, &$reachedInternalErrorsCountLimit, $processIdentifier): void {
121120
foreach ($json['errors'] as $jsonError) {
122121
if (is_string($jsonError)) {
123122
$internalErrors[] = sprintf('Internal error: %s', $jsonError);
@@ -139,7 +138,6 @@ public function analyse(
139138
$postFileCallback($json['filesCount']);
140139
}
141140

142-
$hasInferrablePropertyTypesFromConstructor = $hasInferrablePropertyTypesFromConstructor || $json['hasInferrablePropertyTypesFromConstructor'];
143141
$internalErrorsCount += $json['internalErrorsCount'];
144142
if ($internalErrorsCount >= $this->internalErrorsCountLimit) {
145143
$reachedInternalErrorsCountLimit = true;
@@ -172,7 +170,6 @@ public function analyse(
172170
return new AnalyserResult(
173171
$errors,
174172
$internalErrors,
175-
$hasInferrablePropertyTypesFromConstructor,
176173
$internalErrorsCount === 0 ? $dependencies : null,
177174
$reachedInternalErrorsCountLimit
178175
);

src/Testing/ErrorFormatterTestCase.php

-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ protected function getAnalysisResult(int $numFileErrors, int $numGenericErrors):
8080
$genericErrors,
8181
[],
8282
false,
83-
false,
8483
null
8584
);
8685
}

tests/PHPStan/Command/AnalyseApplicationIntegrationTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private function runPath(string $path, int $expectedStatusCode): string
5454
$memoryLimitFile = self::getContainer()->getParameter('memoryLimitFile');
5555

5656
$relativePathHelper = new FuzzyRelativePathHelper(__DIR__, [], DIRECTORY_SEPARATOR);
57-
$errorFormatter = new TableErrorFormatter($relativePathHelper, false, false, false, true);
57+
$errorFormatter = new TableErrorFormatter($relativePathHelper, false);
5858
$analysisResult = $analyserApplication->analyse(
5959
[$path],
6060
true,

tests/PHPStan/Command/AnalysisResultTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public function testErrorsAreSortedByFileNameAndLine(): void
3939
[],
4040
[],
4141
false,
42-
false,
4342
null
4443
))->getFileSpecificErrors()
4544
);

tests/PHPStan/Command/ErrorFormatter/BaselineNeonErrorFormatterTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ public function testFormatErrorMessagesRegexEscape(): void
131131
['Escape Regex without file # ~ <> \' ()'],
132132
[],
133133
false,
134-
false,
135134
null
136135
);
137136
$formatter->formatErrors(

0 commit comments

Comments
 (0)