Skip to content

Commit

Permalink
Removed tip about inferPrivatePropertyTypeFromConstructor`
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed May 10, 2020
1 parent 9a7ce62 commit b31b9d8
Show file tree
Hide file tree
Showing 16 changed files with 7 additions and 138 deletions.
3 changes: 0 additions & 3 deletions conf/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1137,9 +1137,6 @@ services:
class: PHPStan\Command\ErrorFormatter\TableErrorFormatter
arguments:
showTipsOfTheDay: %tipsOfTheDay%
checkThisOnly: %checkThisOnly%
inferPrivatePropertyTypeFromConstructor: %inferPrivatePropertyTypeFromConstructor%
checkMissingTypehints: %checkMissingTypehints%

errorFormatter.checkstyle:
class: PHPStan\Command\ErrorFormatter\CheckstyleErrorFormatter
Expand Down
4 changes: 1 addition & 3 deletions src/Analyser/Analyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public function analyse(
$errors = [];
$internalErrorsCount = 0;
$reachedInternalErrorsCountLimit = false;
$inferrablePropertyTypesFromConstructorHelper = new InferrablePropertyTypesFromConstructorHelper();
$dependencies = [];
foreach ($files as $file) {
if ($preFileCallback !== null) {
Expand All @@ -75,7 +74,7 @@ public function analyse(
$file,
$allAnalysedFiles,
$this->registry,
$inferrablePropertyTypesFromConstructorHelper
null
);
$errors = array_merge($errors, $fileAnalyserResult->getErrors());
$dependencies[$file] = $fileAnalyserResult->getDependencies();
Expand Down Expand Up @@ -112,7 +111,6 @@ public function analyse(
return new AnalyserResult(
$errors,
[],
$inferrablePropertyTypesFromConstructorHelper->hasInferrablePropertyTypesFromConstructor(),
$internalErrorsCount === 0 ? $dependencies : null,
$reachedInternalErrorsCountLimit
);
Expand Down
11 changes: 0 additions & 11 deletions src/Analyser/AnalyserResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ class AnalyserResult
/** @var string[] */
private $internalErrors;

/** @var bool */
private $hasInferrablePropertyTypesFromConstructor;

/** @var array<string, array<string>>|null */
private $dependencies;

Expand All @@ -26,14 +23,12 @@ class AnalyserResult
/**
* @param \PHPStan\Analyser\Error[] $errors
* @param string[] $internalErrors
* @param bool $hasInferrablePropertyTypesFromConstructor
* @param array<string, array<string>>|null $dependencies
* @param bool $reachedInternalErrorsCountLimit
*/
public function __construct(
array $errors,
array $internalErrors,
bool $hasInferrablePropertyTypesFromConstructor,
?array $dependencies,
bool $reachedInternalErrorsCountLimit
)
Expand All @@ -57,7 +52,6 @@ static function (Error $a, Error $b): int {

$this->errors = $errors;
$this->internalErrors = $internalErrors;
$this->hasInferrablePropertyTypesFromConstructor = $hasInferrablePropertyTypesFromConstructor;
$this->dependencies = $dependencies;
$this->reachedInternalErrorsCountLimit = $reachedInternalErrorsCountLimit;
}
Expand Down Expand Up @@ -86,11 +80,6 @@ public function getInternalErrors(): array
return $this->internalErrors;
}

public function hasInferrablePropertyTypesFromConstructor(): bool
{
return $this->hasInferrablePropertyTypesFromConstructor;
}

/**
* @return array<string, array<string>>|null
*/
Expand Down
53 changes: 0 additions & 53 deletions src/Analyser/InferrablePropertyTypesFromConstructorHelper.php

This file was deleted.

1 change: 0 additions & 1 deletion src/Analyser/ResultCache/ResultCacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ public function process(AnalyserResult $analyserResult, ResultCache $resultCache
return new AnalyserResult(
$flatErrors,
$internalErrors,
$analyserResult->hasInferrablePropertyTypesFromConstructor(),
$dependencies,
$analyserResult->hasReachedInternalErrorsCountLimit()
);
Expand Down
5 changes: 1 addition & 4 deletions src/Command/AnalyseApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public function analyse(
$ignoredErrorHelperResult = $this->ignoredErrorHelper->initialize();
if (count($ignoredErrorHelperResult->getErrors()) > 0) {
$errors = $ignoredErrorHelperResult->getErrors();
$hasInferrablePropertyTypesFromConstructor = false;
$warnings = [];
} else {
$resultCache = $this->resultCacheManager->restore($files, $debug);
Expand All @@ -117,7 +116,6 @@ public function analyse(
$input
);
$analyserResult = $this->resultCacheManager->process($intermediateAnalyserResult, $resultCache);
$hasInferrablePropertyTypesFromConstructor = $analyserResult->hasInferrablePropertyTypesFromConstructor();
$internalErrors = $analyserResult->getInternalErrors();
$errors = $ignoredErrorHelperResult->process($analyserResult->getErrors(), $onlyFiles, $files, count($internalErrors) > 0 || $analyserResult->hasReachedInternalErrorsCountLimit());
$warnings = $ignoredErrorHelperResult->getWarnings();
Expand Down Expand Up @@ -145,7 +143,6 @@ public function analyse(
$notFileSpecificErrors,
$warnings,
$defaultLevelUsed,
$hasInferrablePropertyTypesFromConstructor,
$projectConfigFile
);
}
Expand All @@ -170,7 +167,7 @@ private function runAnalyser(
$errorOutput->getStyle()->progressStart($allAnalysedFilesCount);
$errorOutput->getStyle()->progressAdvance($allAnalysedFilesCount);
$errorOutput->getStyle()->progressFinish();
return new AnalyserResult([], [], false, [], false);
return new AnalyserResult([], [], [], false);
}

/** @var bool $runningInParallel */
Expand Down
11 changes: 0 additions & 11 deletions src/Command/AnalysisResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ class AnalysisResult
/** @var bool */
private $defaultLevelUsed;

/** @var bool */
private $hasInferrablePropertyTypesFromConstructor;

/** @var string|null */
private $projectConfigFile;

Expand All @@ -30,15 +27,13 @@ class AnalysisResult
* @param string[] $notFileSpecificErrors
* @param string[] $warnings
* @param bool $defaultLevelUsed
* @param bool $hasInferrablePropertyTypesFromConstructor
* @param string|null $projectConfigFile
*/
public function __construct(
array $fileSpecificErrors,
array $notFileSpecificErrors,
array $warnings,
bool $defaultLevelUsed,
bool $hasInferrablePropertyTypesFromConstructor,
?string $projectConfigFile
)
{
Expand All @@ -61,7 +56,6 @@ static function (Error $a, Error $b): int {
$this->notFileSpecificErrors = $notFileSpecificErrors;
$this->warnings = $warnings;
$this->defaultLevelUsed = $defaultLevelUsed;
$this->hasInferrablePropertyTypesFromConstructor = $hasInferrablePropertyTypesFromConstructor;
$this->projectConfigFile = $projectConfigFile;
}

Expand Down Expand Up @@ -109,11 +103,6 @@ public function isDefaultLevelUsed(): bool
return $this->defaultLevelUsed;
}

public function hasInferrablePropertyTypesFromConstructor(): bool
{
return $this->hasInferrablePropertyTypesFromConstructor;
}

public function getProjectConfigFile(): ?string
{
return $this->projectConfigFile;
Expand Down
38 changes: 1 addition & 37 deletions src/Command/ErrorFormatter/TableErrorFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,13 @@ class TableErrorFormatter implements ErrorFormatter
/** @var bool */
private $showTipsOfTheDay;

/** @var bool */
private $checkThisOnly;

/** @var bool */
private $inferPrivatePropertyTypeFromConstructor;

/** @var bool */
private $checkMissingTypehints;

public function __construct(
RelativePathHelper $relativePathHelper,
bool $showTipsOfTheDay,
bool $checkThisOnly,
bool $inferPrivatePropertyTypeFromConstructor,
bool $checkMissingTypehints
bool $showTipsOfTheDay
)
{
$this->relativePathHelper = $relativePathHelper;
$this->showTipsOfTheDay = $showTipsOfTheDay;
$this->checkThisOnly = $checkThisOnly;
$this->inferPrivatePropertyTypeFromConstructor = $inferPrivatePropertyTypeFromConstructor;
$this->checkMissingTypehints = $checkMissingTypehints;
}

public function formatErrors(
Expand All @@ -52,21 +37,6 @@ public function formatErrors(

$style = $output->getStyle();

$showInferPropertiesTip = function () use ($output, $analysisResult, $projectConfigFile): void {
if (
$this->checkThisOnly
|| !$analysisResult->hasInferrablePropertyTypesFromConstructor()
|| $this->inferPrivatePropertyTypeFromConstructor
) {
return;
}

$output->writeLineFormatted('💡 Tip of the Day:');
$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.");
$output->writeLineFormatted(sprintf('Use <fg=cyan>inferPrivatePropertyTypeFromConstructor: true</> in your <fg=cyan>%s</> to try it out!', $projectConfigFile));
$output->writeLineFormatted('');
};

if (!$analysisResult->hasErrors() && !$analysisResult->hasWarnings()) {
$style->success('No errors');
if ($this->showTipsOfTheDay) {
Expand All @@ -78,8 +48,6 @@ public function formatErrors(
AnalyseCommand::DEFAULT_LEVEL
));
$output->writeLineFormatted('');
} else {
$showInferPropertiesTip();
}
}

Expand Down Expand Up @@ -140,10 +108,6 @@ public function formatErrors(
$style->warning($finalMessage);
}

if ($this->checkMissingTypehints && $this->showTipsOfTheDay) {
$showInferPropertiesTip();
}

return $analysisResult->getTotalErrorsCount() > 0 ? 1 : 0;
}

Expand Down
6 changes: 1 addition & 5 deletions src/Command/WorkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use Clue\React\NDJson\Encoder;
use PHPStan\Analyser\Error;
use PHPStan\Analyser\FileAnalyser;
use PHPStan\Analyser\InferrablePropertyTypesFromConstructorHelper;
use PHPStan\Analyser\NodeScopeResolver;
use PHPStan\DependencyInjection\Container;
use PHPStan\Rules\Registry;
Expand Down Expand Up @@ -146,7 +145,6 @@ private function runWorker(
'errors' => [$error->getMessage()],
'dependencies' => [],
'filesCount' => 0,
'hasInferrablePropertyTypesFromConstructor' => false,
'internalErrorsCount' => 1,
],
]);
Expand All @@ -171,10 +169,9 @@ private function runWorker(
$files = $json['files'];
$errors = [];
$dependencies = [];
$inferrablePropertyTypesFromConstructorHelper = new InferrablePropertyTypesFromConstructorHelper();
foreach ($files as $file) {
try {
$fileAnalyserResult = $fileAnalyser->analyseFile($file, $analysedFiles, $registry, $inferrablePropertyTypesFromConstructorHelper);
$fileAnalyserResult = $fileAnalyser->analyseFile($file, $analysedFiles, $registry, null);
$fileErrors = $fileAnalyserResult->getErrors();
$dependencies[$file] = $fileAnalyserResult->getDependencies();
foreach ($fileErrors as $fileError) {
Expand All @@ -199,7 +196,6 @@ private function runWorker(
'errors' => $errors,
'dependencies' => $dependencies,
'filesCount' => count($files),
'hasInferrablePropertyTypesFromConstructor' => $inferrablePropertyTypesFromConstructorHelper->hasInferrablePropertyTypesFromConstructor(),
'internalErrorsCount' => $internalErrorsCount,
]]);
});
Expand Down
5 changes: 1 addition & 4 deletions src/Parallel/ParallelAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public function analyse(
$numberOfProcesses = $schedule->getNumberOfProcesses();
$errors = [];
$internalErrors = [];
$hasInferrablePropertyTypesFromConstructor = false;

$server = new \React\Socket\TcpServer('127.0.0.1:0', $loop);
$this->processPool = new ProcessPool($server);
Expand Down Expand Up @@ -117,7 +116,7 @@ public function analyse(
$processIdentifier,
$input
), $loop, $this->processTimeout);
$process->start(function (array $json) use ($process, &$internalErrors, &$errors, &$dependencies, &$jobs, $postFileCallback, &$hasInferrablePropertyTypesFromConstructor, &$internalErrorsCount, &$reachedInternalErrorsCountLimit, $processIdentifier): void {
$process->start(function (array $json) use ($process, &$internalErrors, &$errors, &$dependencies, &$jobs, $postFileCallback, &$internalErrorsCount, &$reachedInternalErrorsCountLimit, $processIdentifier): void {
foreach ($json['errors'] as $jsonError) {
if (is_string($jsonError)) {
$internalErrors[] = sprintf('Internal error: %s', $jsonError);
Expand All @@ -139,7 +138,6 @@ public function analyse(
$postFileCallback($json['filesCount']);
}

$hasInferrablePropertyTypesFromConstructor = $hasInferrablePropertyTypesFromConstructor || $json['hasInferrablePropertyTypesFromConstructor'];
$internalErrorsCount += $json['internalErrorsCount'];
if ($internalErrorsCount >= $this->internalErrorsCountLimit) {
$reachedInternalErrorsCountLimit = true;
Expand Down Expand Up @@ -172,7 +170,6 @@ public function analyse(
return new AnalyserResult(
$errors,
$internalErrors,
$hasInferrablePropertyTypesFromConstructor,
$internalErrorsCount === 0 ? $dependencies : null,
$reachedInternalErrorsCountLimit
);
Expand Down
1 change: 0 additions & 1 deletion src/Testing/ErrorFormatterTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ protected function getAnalysisResult(int $numFileErrors, int $numGenericErrors):
$genericErrors,
[],
false,
false,
null
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private function runPath(string $path, int $expectedStatusCode): string
$memoryLimitFile = self::getContainer()->getParameter('memoryLimitFile');

$relativePathHelper = new FuzzyRelativePathHelper(__DIR__, [], DIRECTORY_SEPARATOR);
$errorFormatter = new TableErrorFormatter($relativePathHelper, false, false, false, true);
$errorFormatter = new TableErrorFormatter($relativePathHelper, false);
$analysisResult = $analyserApplication->analyse(
[$path],
true,
Expand Down
1 change: 0 additions & 1 deletion tests/PHPStan/Command/AnalysisResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public function testErrorsAreSortedByFileNameAndLine(): void
[],
[],
false,
false,
null
))->getFileSpecificErrors()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ public function testFormatErrorMessagesRegexEscape(): void
['Escape Regex without file # ~ <> \' ()'],
[],
false,
false,
null
);
$formatter->formatErrors(
Expand Down
Loading

0 comments on commit b31b9d8

Please sign in to comment.