Skip to content

Commit b543e8f

Browse files
herndlmondrejmirtes
authored andcommitted
Add regression test
1 parent 1fa16cd commit b543e8f

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Bug3300;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
/**
8+
* Class FormTypeHelper.
9+
*/
10+
class FormTypeHelper
11+
{
12+
private const TYPE_TO_CLASS_MAP = [
13+
'text' => 'TextType::class',
14+
'group' => 'EntityManagerFormType::class',
15+
'number' => 'IntegerType::class',
16+
'select' => 'ChoiceType::class',
17+
'radio' => 'ChoiceType::class',
18+
'checkbox' => 'ChoiceType::class',
19+
'bool' => 'CheckboxType::class',
20+
];
21+
22+
/**
23+
* @param string $class
24+
*
25+
* @return string
26+
*
27+
* @throws \Exception
28+
*/
29+
public static function getTypeFromClass(string $class): string
30+
{
31+
$type = array_keys(self::TYPE_TO_CLASS_MAP, $class, true);
32+
33+
if (0 === count($type)) {
34+
throw new \Exception(sprintf('No type matched class %s', $class));
35+
}
36+
if (1 < count($type)) {
37+
throw new \Exception(
38+
sprintf('Multiple types found, did you mean any of %s', implode(', ', $type))
39+
);
40+
}
41+
42+
return $type[0];
43+
}
44+
}

tests/PHPStan/Rules/Comparison/StrictComparisonOfDifferentTypesRuleTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,4 +1016,10 @@ public function testBug8366(): void
10161016
$this->analyse([__DIR__ . '/../../Analyser/data/bug-8366.php'], []);
10171017
}
10181018

1019+
public function testBug3300(): void
1020+
{
1021+
$this->checkAlwaysTrueStrictComparison = true;
1022+
$this->analyse([__DIR__ . '/../../Analyser/data/bug-3300.php'], []);
1023+
}
1024+
10191025
}

0 commit comments

Comments
 (0)