Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change message 'typehint' to 'type' and 'typehint type' to 'type'. #270

Closed
wants to merge 11 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public function processNode(Node $node, Scope $scope): array
$scope,
$node->getParams(),
$node->getReturnType(),
'Parameter $%s of anonymous function has invalid typehint type %s.',
'Return typehint of anonymous function has invalid type %s.',
'Parameter $%s of anonymous function has invalid type %s.',
'Anonymous function has invalid return type %s.',
'Anonymous function uses native union types but they\'re supported only on PHP 8.0 and later.'
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Rules/Functions/ExistingClassesInClosureTypehintsRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public function processNode(Node $node, Scope $scope): array
$scope,
$node->getParams(),
$node->getReturnType(),
'Parameter $%s of anonymous function has invalid typehint type %s.',
'Return typehint of anonymous function has invalid type %s.',
'Parameter $%s of anonymous function has invalid type %s.',
'Anonymous function has invalid return type %s.',
'Anonymous function uses native union types but they\'re supported only on PHP 8.0 and later.'
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Rules/Functions/ExistingClassesInTypehintsRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ public function processNode(Node $node, Scope $scope): array
$node->getOriginalNode(),
$scope->getFunction(),
sprintf(
'Parameter $%%s of function %s() has invalid typehint type %%s.',
'Parameter $%%s of function %s() has invalid type %%s.',
$functionName
),
sprintf(
'Return typehint of function %s() has invalid type %%s.',
'Function %s() has invalid return type %%s.',
$functionName
),
sprintf('Function %s() uses native union types but they\'re supported only on PHP 8.0 and later.', $functionName),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private function checkFunctionParameter(FunctionReflection $functionReflection,
if ($parameterType instanceof MixedType && !$parameterType->isExplicitMixed()) {
return [
RuleErrorBuilder::message(sprintf(
'Function %s() has parameter $%s with no typehint specified.',
'Function %s() has parameter $%s with no type specified.',
$functionReflection->getName(),
$parameterReflection->getName()
))->build(),
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Functions/MissingFunctionReturnTypehintRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function processNode(Node $node, Scope $scope): array
if ($returnType instanceof MixedType && !$returnType->isExplicitMixed()) {
return [
RuleErrorBuilder::message(sprintf(
'Function %s() has no return typehint specified.',
'Function %s() has no return type specified.',
$functionReflection->getName()
))->build(),
];
Expand Down
4 changes: 2 additions & 2 deletions src/Rules/Methods/ExistingClassesInTypehintsRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ public function processNode(Node $node, Scope $scope): array
$methodReflection,
$node->getOriginalNode(),
sprintf(
'Parameter $%%s of method %s::%s() has invalid typehint type %%s.',
'Parameter $%%s of method %s::%s() has invalid type %%s.',
$scope->getClassReflection()->getDisplayName(),
$methodReflection->getName()
),
sprintf(
'Return typehint of method %s::%s() has invalid type %%s.',
'Method %s::%s() has invalid return type %%s.',
$scope->getClassReflection()->getDisplayName(),
$methodReflection->getName()
),
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Methods/MissingMethodParameterTypehintRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private function checkMethodParameter(MethodReflection $methodReflection, Parame
if ($parameterType instanceof MixedType && !$parameterType->isExplicitMixed()) {
return [
RuleErrorBuilder::message(sprintf(
'Method %s::%s() has parameter $%s with no typehint specified.',
'Method %s::%s() has parameter $%s with no type specified.',
$methodReflection->getDeclaringClass()->getDisplayName(),
$methodReflection->getName(),
$parameterReflection->getName()
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Methods/MissingMethodReturnTypehintRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function processNode(Node $node, Scope $scope): array
if ($returnType instanceof MixedType && !$returnType->isExplicitMixed()) {
return [
RuleErrorBuilder::message(sprintf(
'Method %s::%s() has no return typehint specified.',
'Method %s::%s() has no return type specified.',
$methodReflection->getDeclaringClass()->getDisplayName(),
$methodReflection->getName()
))->build(),
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Properties/MissingPropertyTypehintRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function processNode(Node $node, Scope $scope): array
if ($propertyType instanceof MixedType && !$propertyType->isExplicitMixed()) {
return [
RuleErrorBuilder::message(sprintf(
'Property %s::$%s has no typehint specified.',
'Property %s::$%s has no type specified.',
$propertyReflection->getDeclaringClass()->getDisplayName(),
$node->getName()
))->build(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function processNode(Node $node, Scope $scope): array
}

$messages[] = RuleErrorBuilder::message(sprintf(
'Anonymous function never returns %s so it can be removed from the return typehint.',
'Anonymous function never returns %s so it can be removed from the return type.',
$type->describe(VerbosityLevel::getRecommendedLevelByType($type))
))->build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function processNode(Node $node, Scope $scope): array
}

$messages[] = RuleErrorBuilder::message(sprintf(
'Anonymous function never returns %s so it can be removed from the return typehint.',
'Anonymous function never returns %s so it can be removed from the return type.',
$type->describe(VerbosityLevel::getRecommendedLevelByType($type))
))->build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function processNode(Node $node, Scope $scope): array
}

$messages[] = RuleErrorBuilder::message(sprintf(
'Function %s() never returns %s so it can be removed from the return typehint.',
'Function %s() never returns %s so it can be removed from the return type.',
$function->getName(),
$type->describe(VerbosityLevel::getRecommendedLevelByType($type))
))->build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function processNode(Node $node, Scope $scope): array
}

$messages[] = RuleErrorBuilder::message(sprintf(
'Method %s::%s() never returns %s so it can be removed from the return typehint.',
'Method %s::%s() never returns %s so it can be removed from the return type.',
$method->getDeclaringClass()->getDisplayName(),
$method->getName(),
$type->describe(VerbosityLevel::getRecommendedLevelByType($type))
Expand Down
8 changes: 5 additions & 3 deletions tests/PHPStan/Analyser/AnalyserIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,11 @@ public function testAnonymousClassWithWrongFilename(): void
{
$errors = $this->runAnalyse(__DIR__ . '/data/anonymous-class-wrong-filename-regression.php');
$this->assertCount(5, $errors);
$this->assertStringContainsString('Return typehint of method', $errors[0]->getMessage());
$this->assertStringContainsString('Method', $errors[0]->getMessage());
$this->assertStringContainsString('has invalid return type', $errors[0]->getMessage());
$this->assertSame(16, $errors[0]->getLine());
$this->assertStringContainsString('Return typehint of method', $errors[1]->getMessage());
$this->assertStringContainsString('Method', $errors[1]->getMessage());
$this->assertStringContainsString('has invalid return type', $errors[1]->getMessage());
$this->assertSame(16, $errors[1]->getLine());
$this->assertSame('Instantiated class AnonymousClassWrongFilename\Bar not found.', $errors[2]->getMessage());
$this->assertSame(18, $errors[2]->getLine());
Expand Down Expand Up @@ -168,7 +170,7 @@ public function testNestedNamespaces(): void
$this->assertCount(2, $errors);
$this->assertSame('Property y\x::$baz has unknown class x\baz as its type.', $errors[0]->getMessage());
$this->assertSame(15, $errors[0]->getLine());
$this->assertSame('Parameter $baz of method y\x::__construct() has invalid typehint type x\baz.', $errors[1]->getMessage());
$this->assertSame('Parameter $baz of method y\x::__construct() has invalid type x\baz.', $errors[1]->getMessage());
$this->assertSame(16, $errors[1]->getLine());
}

Expand Down
4 changes: 2 additions & 2 deletions tests/PHPStan/Command/ErrorFormatter/data/unixBaseline.neon
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
parameters:
ignoreErrors:
-
message: "#^Method BaselineIntegration\\\\WindowsNewlines\\:\\:phpdocWithNewlines\\(\\) has no return typehint specified\\.$#"
message: "#^Method BaselineIntegration\\\\WindowsNewlines\\:\\:phpdocWithNewlines\\(\\) has no return type specified\\.$#"
count: 1
path: WindowsNewlines.php

-
message: "#^Method BaselineIntegration\\\\WindowsNewlines\\:\\:phpdocWithNewlines\\(\\) has parameter \\$object with no typehint specified\\.$#"
message: "#^Method BaselineIntegration\\\\WindowsNewlines\\:\\:phpdocWithNewlines\\(\\) has parameter \\$object with no type specified\\.$#"
count: 1
path: WindowsNewlines.php

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
parameters:
ignoreErrors:
-
message: "#^Method BaselineIntegration\\\\UnixNewlines\\:\\:phpdocWithNewlines\\(\\) has no return typehint specified\\.$#"
message: "#^Method BaselineIntegration\\\\UnixNewlines\\:\\:phpdocWithNewlines\\(\\) has no return type specified\\.$#"
count: 1
path: UnixNewlines.php

-
message: "#^Method BaselineIntegration\\\\UnixNewlines\\:\\:phpdocWithNewlines\\(\\) has parameter \\$object with no typehint specified\\.$#"
message: "#^Method BaselineIntegration\\\\UnixNewlines\\:\\:phpdocWithNewlines\\(\\) has parameter \\$object with no type specified\\.$#"
count: 1
path: UnixNewlines.php

Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Generics/data/functions-6.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"message": "Function PHPStan\\Generics\\Functions\\testF() has no return typehint specified.",
"message": "Function PHPStan\\Generics\\Functions\\testF() has no return type specified.",
"line": 27,
"ignorable": true
},
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Generics/data/pick-6.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"message": "Function PHPStan\\Generics\\Pick\\test() has no return typehint specified.",
"message": "Function PHPStan\\Generics\\Pick\\test() has no return type specified.",
"line": 22,
"ignorable": true
}
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Generics/data/varyingAcceptor-6.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"message": "Function PHPStan\\Generics\\VaryingAcceptor\\testApply() has no return typehint specified.",
"message": "Function PHPStan\\Generics\\VaryingAcceptor\\testApply() has no return type specified.",
"line": 30,
"ignorable": true
}
Expand Down
60 changes: 30 additions & 30 deletions tests/PHPStan/Levels/data/acceptTypes-6.json
Original file line number Diff line number Diff line change
@@ -1,151 +1,151 @@
[
{
"message": "Method Levels\\AcceptTypes\\Foo::doFoo() has no return typehint specified.",
"message": "Method Levels\\AcceptTypes\\Foo::doFoo() has no return type specified.",
"line": 15,
"ignorable": true
},
{
"message": "Method Levels\\AcceptTypes\\Foo::doBar() has no return typehint specified.",
"message": "Method Levels\\AcceptTypes\\Foo::doBar() has no return type specified.",
"line": 30,
"ignorable": true
},
{
"message": "Method Levels\\AcceptTypes\\Foo::doBaz() has no return typehint specified.",
"message": "Method Levels\\AcceptTypes\\Foo::doBaz() has no return type specified.",
"line": 41,
"ignorable": true
},
{
"message": "Method Levels\\AcceptTypes\\Foo::doLorem() has no return typehint specified.",
"message": "Method Levels\\AcceptTypes\\Foo::doLorem() has no return type specified.",
"line": 60,
"ignorable": true
},
{
"message": "Method Levels\\AcceptTypes\\Foo::doIpsum() has no return typehint specified.",
"message": "Method Levels\\AcceptTypes\\Foo::doIpsum() has no return type specified.",
"line": 68,
"ignorable": true
},
{
"message": "Method Levels\\AcceptTypes\\Foo::doFooArray() has no return typehint specified.",
"message": "Method Levels\\AcceptTypes\\Foo::doFooArray() has no return type specified.",
"line": 80,
"ignorable": true
},
{
"message": "Method Levels\\AcceptTypes\\Foo::doBarArray() has no return typehint specified.",
"message": "Method Levels\\AcceptTypes\\Foo::doBarArray() has no return type specified.",
"line": 98,
"ignorable": true
},
{
"message": "Method Levels\\AcceptTypes\\Foo::doBazArray() has no return typehint specified.",
"message": "Method Levels\\AcceptTypes\\Foo::doBazArray() has no return type specified.",
"line": 103,
"ignorable": true
},
{
"message": "Method Levels\\AcceptTypes\\Foo::doBazArrayUnionItemTypes() has no return typehint specified.",
"message": "Method Levels\\AcceptTypes\\Foo::doBazArrayUnionItemTypes() has no return type specified.",
"line": 127,
"ignorable": true
},
{
"message": "Method Levels\\AcceptTypes\\Foo::callableArray() has no return typehint specified.",
"message": "Method Levels\\AcceptTypes\\Foo::callableArray() has no return type specified.",
"line": 138,
"ignorable": true
},
{
"message": "Method Levels\\AcceptTypes\\Foo::expectCallable() has no return typehint specified.",
"message": "Method Levels\\AcceptTypes\\Foo::expectCallable() has no return type specified.",
"line": 148,
"ignorable": true
},
{
"message": "Method Levels\\AcceptTypes\\Foo::iterableCountable() has no return typehint specified.",
"message": "Method Levels\\AcceptTypes\\Foo::iterableCountable() has no return type specified.",
"line": 160,
"ignorable": true
},
{
"message": "Method Levels\\AcceptTypes\\Foo::benevolentUnionNotReported() has no return typehint specified.",
"message": "Method Levels\\AcceptTypes\\Foo::benevolentUnionNotReported() has no return type specified.",
"line": 176,
"ignorable": true
},
{
"message": "Method Levels\\AcceptTypes\\ClosureAccepts::doFoo() has no return typehint specified.",
"message": "Method Levels\\AcceptTypes\\ClosureAccepts::doFoo() has no return type specified.",
"line": 208,
"ignorable": true
},
{
"message": "Method Levels\\AcceptTypes\\ClosureAccepts::doFooUnionClosures() has no return typehint specified.",
"message": "Method Levels\\AcceptTypes\\ClosureAccepts::doFooUnionClosures() has no return type specified.",
"line": 254,
"ignorable": true
},
{
"message": "Method Levels\\AcceptTypes\\ClosureAccepts::doBar() has no return typehint specified.",
"message": "Method Levels\\AcceptTypes\\ClosureAccepts::doBar() has no return type specified.",
"line": 332,
"ignorable": true
},
{
"message": "Method Levels\\AcceptTypes\\ClosureAccepts::doBaz() has no return typehint specified.",
"message": "Method Levels\\AcceptTypes\\ClosureAccepts::doBaz() has no return type specified.",
"line": 342,
"ignorable": true
},
{
"message": "Method Levels\\AcceptTypes\\Baz::doFoo() has no return typehint specified.",
"message": "Method Levels\\AcceptTypes\\Baz::doFoo() has no return type specified.",
"line": 409,
"ignorable": true
},
{
"message": "Method Levels\\AcceptTypes\\Baz::doBar() has no return typehint specified.",
"message": "Method Levels\\AcceptTypes\\Baz::doBar() has no return type specified.",
"line": 418,
"ignorable": true
},
{
"message": "Method Levels\\AcceptTypes\\Baz::doBaz() has no return typehint specified.",
"message": "Method Levels\\AcceptTypes\\Baz::doBaz() has no return type specified.",
"line": 423,
"ignorable": true
},
{
"message": "Method Levels\\AcceptTypes\\Baz::doLorem() has no return typehint specified.",
"message": "Method Levels\\AcceptTypes\\Baz::doLorem() has no return type specified.",
"line": 437,
"ignorable": true
},
{
"message": "Method Levels\\AcceptTypes\\Baz::doIpsum() has no return typehint specified.",
"message": "Method Levels\\AcceptTypes\\Baz::doIpsum() has no return type specified.",
"line": 445,
"ignorable": true
},
{
"message": "Method Levels\\AcceptTypes\\Baz::doFooArray() has no return typehint specified.",
"message": "Method Levels\\AcceptTypes\\Baz::doFooArray() has no return type specified.",
"line": 490,
"ignorable": true
},
{
"message": "Method Levels\\AcceptTypes\\Baz::doBarArray() has no return typehint specified.",
"message": "Method Levels\\AcceptTypes\\Baz::doBarArray() has no return type specified.",
"line": 502,
"ignorable": true
},
{
"message": "Method Levels\\AcceptTypes\\Baz::testUnions() has no return typehint specified.",
"message": "Method Levels\\AcceptTypes\\Baz::testUnions() has no return type specified.",
"line": 524,
"ignorable": true
},
{
"message": "Method Levels\\AcceptTypes\\Baz::testUnions2() has no return typehint specified.",
"message": "Method Levels\\AcceptTypes\\Baz::testUnions2() has no return type specified.",
"line": 535,
"ignorable": true
},
{
"message": "Method Levels\\AcceptTypes\\Baz::requireArray() has no return typehint specified.",
"message": "Method Levels\\AcceptTypes\\Baz::requireArray() has no return type specified.",
"line": 549,
"ignorable": true
},
{
"message": "Method Levels\\AcceptTypes\\Baz::requireFoo() has no return typehint specified.",
"message": "Method Levels\\AcceptTypes\\Baz::requireFoo() has no return type specified.",
"line": 554,
"ignorable": true
},
{
"message": "Method Levels\\AcceptTypes\\ArrayShapes::doFoo() has no return typehint specified.",
"message": "Method Levels\\AcceptTypes\\ArrayShapes::doFoo() has no return type specified.",
"line": 570,
"ignorable": true
},
{
"message": "Method Levels\\AcceptTypes\\ArrayShapes::doBar() has no return typehint specified.",
"message": "Method Levels\\AcceptTypes\\ArrayShapes::doBar() has no return type specified.",
"line": 603,
"ignorable": true
}
Expand Down