Completed
Push — master ( 3ed581...8222a4 )
by Artem
02:07
created

LegacyFormHelper::getType()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 12
rs 9.4285
cc 3
eloc 6
nc 3
nop 1
1
<?php
2
/*
3
 * This file is part of the FreshDoctrineEnumBundle
4
 *
5
 * (c) Artem Genvald <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Fresh\DoctrineEnumBundle\Util;
12
13
/**
14
 * This class was based on LegacyFormHelper in FOSUserBundle:
15
 * https://github.com/FriendsOfSymfony/FOSUserBundle/blob/c533a233b52c1d3843e816a35677561330ddbc74/Util/LegacyFormHelper.php
16
 *
17
 * @internal
18
 *
19
 * @author Gabor Egyed <[email protected]>
20
 * @author Jaik Dean <[email protected]>
21
 */
22
final class LegacyFormHelper
23
{
24
    private static $map = array(
25
        'Symfony\Component\Form\Extension\Core\Type\ChoiceType' => 'choice',
26
    );
27
28
    /**
29
     * Get a form field type compatible with the current version of Symfony
30
     *
31
     * @param string $class
32
     * @return string Class or type name
33
     */
34
    public static function getType($class)
35
    {
36
        if (!self::isLegacy()) {
37
            return $class;
38
        }
39
40
        if (!isset(self::$map[$class])) {
41
            throw new \InvalidArgumentException(sprintf('Form type with class "%s" can not be found. Please check for typos or add it to the map in LegacyFormHelper', $class));
42
        }
43
44
        return self::$map[$class];
45
    }
46
47
    /**
48
     * Check whether to use legacy form behaviour from Symfony <3.0
49
     *
50
     * @return bool
51
     */
52
    public static function isLegacy()
53
    {
54
        return !method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix');
55
    }
56
57
    private function __construct()
58
    {
59
    }
60
61
    private function __clone()
62
    {
63
    }
64
}
65