-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1fa16cd
commit b543e8f
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters