Skip to content

Commit 1f7bd4b

Browse files
committed
TypeHintHelper: Fixed internal error
1 parent 7876032 commit 1f7bd4b

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

SlevomatCodingStandard/Helpers/TypeHintHelper.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ public static function isTemplate(File $phpcsFile, int $docCommentOpenPointer, s
103103

104104
$classPointer = ClassHelper::getClassPointer($phpcsFile, $pointerToFindClass);
105105

106+
if ($classPointer === null) {
107+
return false;
108+
}
109+
106110
$classDocCommentOpenPointer = DocCommentHelper::findDocCommentOpenToken($phpcsFile, $classPointer);
107111
if ($classDocCommentOpenPointer === null) {
108112
return false;

tests/Helpers/TypeHintHelperTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace SlevomatCodingStandard\Helpers;
44

55
use function preg_split;
6+
use const T_DOC_COMMENT_OPEN_TAG;
67

78
class TypeHintHelperTest extends TestCase
89
{
@@ -283,4 +284,30 @@ public function testMethodParameterTypeHintWithoutNamespace(): void
283284
self::assertSame('\Doctrine\ORM\Mapping\Id', TypeHintHelper::getFullyQualifiedTypeHint($phpcsFile, $methodPointer, $parameterTypeHint->getTypeHint()));
284285
}
285286

287+
/**
288+
* @return mixed[][]
289+
*/
290+
public function dataIsTemplate(): array
291+
{
292+
return [
293+
['Whatever', false],
294+
];
295+
}
296+
297+
/**
298+
* @dataProvider dataIsTemplate
299+
* @param string $typeHintName
300+
* @param bool $isTemplate
301+
*/
302+
public function testIsTemplate(string $typeHintName, bool $isTemplate): void
303+
{
304+
$phpcsFile = $this->getCodeSnifferFile(__DIR__ . '/data/typeHintTemplates.php');
305+
306+
$docCommentOpenPointer = $this->findPointerByLineAndType($phpcsFile, 3, T_DOC_COMMENT_OPEN_TAG);
307+
308+
self::assertNotNull($docCommentOpenPointer);
309+
310+
self::assertSame($isTemplate, TypeHintHelper::isTemplate($phpcsFile, $docCommentOpenPointer, $typeHintName));
311+
}
312+
286313
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
/**
4+
* @return Whatever
5+
*/
6+
function simpleFunction() {
7+
8+
}

0 commit comments

Comments
 (0)