Skip to content

Commit

Permalink
Merge pull request #38 from moufmouf/bitly
Browse files Browse the repository at this point in the history
Adding bitly links for arrays and type-hinting
  • Loading branch information
moufmouf authored Oct 15, 2018
2 parents 36e48a5 + b4dce53 commit 444e134
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
16 changes: 8 additions & 8 deletions src/Rules/TypeHints/AbstractMissingTypeHintRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ private function analyzeWithTypehint(DebugContextInterface $debugContext, Type $
if ($phpTypeHint instanceof ArrayType) {
if ($docblockWithoutNullable instanceof MixedType && !$docblockWithoutNullable->isExplicitMixed()) {
if ($debugContext instanceof ParameterDebugContext) {
return sprintf('%s type is "array". Please provide a @param annotation to further specify the type of the array. For instance: @param int[] $%s', (string) $debugContext, $debugContext->getName());
return sprintf('%s type is "array". Please provide a @param annotation to further specify the type of the array. For instance: @param int[] $%s. More info: http://bit.ly/typehintarray', (string) $debugContext, $debugContext->getName());
} else {
return sprintf('%s return type is "array". Please provide a @return annotation to further specify the type of the array. For instance: @return int[]', (string) $debugContext);
return sprintf('%s return type is "array". Please provide a @return annotation to further specify the type of the array. For instance: @return int[]. More info: http://bit.ly/typehintarray', (string) $debugContext);
}
} else {
if ($docblockWithoutNullable instanceof UnionType) {
Expand All @@ -199,9 +199,9 @@ private function analyzeWithTypehint(DebugContextInterface $debugContext, Type $

if ($docblockTypehint instanceof ArrayType && $docblockTypehint->getKeyType() instanceof MixedType && $docblockTypehint->getItemType() instanceof MixedType && $docblockTypehint->getKeyType()->isExplicitMixed() && $docblockTypehint->getItemType()->isExplicitMixed()) {
if ($debugContext instanceof ParameterDebugContext) {
return sprintf('%s type is "array". Please provide a more specific @param annotation in the docblock. For instance: @param int[] $%s. Use @param mixed[] $%s if this is really an array of mixed values.', (string) $debugContext, $debugContext->getName(), $debugContext->getName());
return sprintf('%s type is "array". Please provide a more specific @param annotation in the docblock. For instance: @param int[] $%s. Use @param mixed[] $%s if this is really an array of mixed values. More info: http://bit.ly/typehintarray', (string) $debugContext, $debugContext->getName(), $debugContext->getName());
} else {
return sprintf('%s return type is "array". Please provide a more specific @return annotation. For instance: @return int[]. Use @return mixed[] if this is really an array of mixed values.', (string) $debugContext);
return sprintf('%s return type is "array". Please provide a more specific @return annotation. For instance: @return int[]. Use @return mixed[] if this is really an array of mixed values. More info: http://bit.ly/typehintarray', (string) $debugContext);
}
}
}
Expand Down Expand Up @@ -242,19 +242,19 @@ private function analyzeWithoutTypehint(DebugContextInterface $debugContext, Typ
{
if ($docBlockTypeHints instanceof MixedType && $docBlockTypeHints->isExplicitMixed() === false) {
if ($debugContext instanceof ParameterDebugContext) {
return sprintf('%s has no type-hint and no @param annotation.', (string) $debugContext);
return sprintf('%s has no type-hint and no @param annotation. More info: http://bit.ly/usetypehint', (string) $debugContext);
} else {
return sprintf('%s there is no return type and no @return annotation.', (string) $debugContext);
return sprintf('%s there is no return type and no @return annotation. More info: http://bit.ly/usetypehint', (string) $debugContext);
}
}

$nativeTypehint = $this->isNativelyTypehintable($docBlockTypeHints);

if ($nativeTypehint !== null) {
if ($debugContext instanceof ParameterDebugContext) {
return sprintf('%s can be type-hinted to "%s".', (string) $debugContext, $nativeTypehint);
return sprintf('%s can be type-hinted to "%s". More info: http://bit.ly/usetypehint', (string) $debugContext, $nativeTypehint);
} else {
return sprintf('%s a "%s" return type can be added.', (string) $debugContext, $nativeTypehint);
return sprintf('%s a "%s" return type can be added. More info: http://bit.ly/usetypehint', (string) $debugContext, $nativeTypehint);
}
}

Expand Down
28 changes: 14 additions & 14 deletions tests/Rules/TypeHints/MissingTypeHintRuleInFunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,43 @@ public function testCheckCatchedException()

$this->analyse([__DIR__ . '/data/typehints.php'], [
[
'In function "test", parameter $no_type_hint has no type-hint and no @param annotation.',
'In function "test", parameter $no_type_hint has no type-hint and no @param annotation. More info: http://bit.ly/usetypehint',
3,
],
[
'In function "test", there is no return type and no @return annotation.',
'In function "test", there is no return type and no @return annotation. More info: http://bit.ly/usetypehint',
3,
],
[
'In function "test2", parameter $type_hintable can be type-hinted to "?string".',
'In function "test2", parameter $type_hintable can be type-hinted to "?string". More info: http://bit.ly/usetypehint',
11,
],
[
'In function "test2", a "string" return type can be added.',
'In function "test2", a "string" return type can be added. More info: http://bit.ly/usetypehint',
11,
],
[
'In function "test3", parameter $type_hintable can be type-hinted to "\DateTimeInterface".',
'In function "test3", parameter $type_hintable can be type-hinted to "\DateTimeInterface". More info: http://bit.ly/usetypehint',
19,
],
[
'In function "test3", a "\DateTimeInterface" return type can be added.',
'In function "test3", a "\DateTimeInterface" return type can be added. More info: http://bit.ly/usetypehint',
19,
],
[
'In function "test4", parameter $type_hintable can be type-hinted to "array".',
'In function "test4", parameter $type_hintable can be type-hinted to "array". More info: http://bit.ly/usetypehint',
27,
],
[
'In function "test4", a "array" return type can be added.',
'In function "test4", a "array" return type can be added. More info: http://bit.ly/usetypehint',
27,
],
[
'In function "test6", parameter $better_type_hint type is "array". Please provide a @param annotation to further specify the type of the array. For instance: @param int[] $better_type_hint',
'In function "test6", parameter $better_type_hint type is "array". Please provide a @param annotation to further specify the type of the array. For instance: @param int[] $better_type_hint. More info: http://bit.ly/typehintarray',
38,
],
[
'In function "test6", return type is "array". Please provide a @return annotation to further specify the type of the array. For instance: @return int[]',
'In function "test6", return type is "array". Please provide a @return annotation to further specify the type of the array. For instance: @return int[]. More info: http://bit.ly/typehintarray',
38,
],
[
Expand All @@ -67,23 +67,23 @@ public function testCheckCatchedException()
46,
],
[
'In function "test8", parameter $any_array type is "array". Please provide a more specific @param annotation in the docblock. For instance: @param int[] $any_array. Use @param mixed[] $any_array if this is really an array of mixed values.',
'In function "test8", parameter $any_array type is "array". Please provide a more specific @param annotation in the docblock. For instance: @param int[] $any_array. Use @param mixed[] $any_array if this is really an array of mixed values. More info: http://bit.ly/typehintarray',
62,
],
[
'In function "test8", return type is "array". Please provide a more specific @return annotation. For instance: @return int[]. Use @return mixed[] if this is really an array of mixed values.',
'In function "test8", return type is "array". Please provide a more specific @return annotation. For instance: @return int[]. Use @return mixed[] if this is really an array of mixed values. More info: http://bit.ly/typehintarray',
62,
],
[
'In function "test10", parameter $id has no type-hint and no @param annotation.',
'In function "test10", parameter $id has no type-hint and no @param annotation. More info: http://bit.ly/usetypehint',
76,
],
[
'In function "test13", parameter $type_hintable type is type-hinted to "ClassDoesNotExist" but the @param annotation says it is a "array<DateTimeImmutable>". Please fix the @param annotation.',
97,
],
[
'In function "test15", parameter $foo type is "array". Please provide a @param annotation to further specify the type of the array. For instance: @param int[] $foo',
'In function "test15", parameter $foo type is "array". Please provide a @param annotation to further specify the type of the array. For instance: @param int[] $foo. More info: http://bit.ly/typehintarray',
110,
],
[
Expand Down
4 changes: 2 additions & 2 deletions tests/Rules/TypeHints/MissingTypeHintRuleInMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public function testCheckCatchedException()

$this->analyse([__DIR__ . '/data/typehints_in_methods.php'], [
[
'In method "TheCodingMachine\PHPStan\Rules\TypeHints\data\Foo::test", parameter $no_type_hint has no type-hint and no @param annotation.',
'In method "TheCodingMachine\PHPStan\Rules\TypeHints\data\Foo::test", parameter $no_type_hint has no type-hint and no @param annotation. More info: http://bit.ly/usetypehint',
9,
],
[
'In method "TheCodingMachine\PHPStan\Rules\TypeHints\data\BazClass::notInherited", parameter $no_type_hint has no type-hint and no @param annotation.',
'In method "TheCodingMachine\PHPStan\Rules\TypeHints\data\BazClass::notInherited", parameter $no_type_hint has no type-hint and no @param annotation. More info: http://bit.ly/usetypehint',
37,
],

Expand Down

0 comments on commit 444e134

Please sign in to comment.