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

Add regression test #3066

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'], []);
}

}
Loading