Skip to content

Commit

Permalink
Add regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
herndlm authored and ondrejmirtes committed May 30, 2024
1 parent 1fa16cd commit b543e8f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/PHPStan/Analyser/data/bug-3300.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php declare(strict_types=1);

namespace Bug3300;

use function PHPStan\Testing\assertType;

/**
* Class FormTypeHelper.
*/
class FormTypeHelper
{
private const TYPE_TO_CLASS_MAP = [
'text' => 'TextType::class',
'group' => 'EntityManagerFormType::class',
'number' => 'IntegerType::class',
'select' => 'ChoiceType::class',
'radio' => 'ChoiceType::class',
'checkbox' => 'ChoiceType::class',
'bool' => 'CheckboxType::class',
];

/**
* @param string $class
*
* @return string
*
* @throws \Exception
*/
public static function getTypeFromClass(string $class): string
{
$type = array_keys(self::TYPE_TO_CLASS_MAP, $class, true);

if (0 === count($type)) {
throw new \Exception(sprintf('No type matched class %s', $class));
}
if (1 < count($type)) {
throw new \Exception(
sprintf('Multiple types found, did you mean any of %s', implode(', ', $type))
);
}

return $type[0];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1016,4 +1016,10 @@ public function testBug8366(): void
$this->analyse([__DIR__ . '/../../Analyser/data/bug-8366.php'], []);
}

public function testBug3300(): void
{
$this->checkAlwaysTrueStrictComparison = true;
$this->analyse([__DIR__ . '/../../Analyser/data/bug-3300.php'], []);
}

}

0 comments on commit b543e8f

Please sign in to comment.