Completed
Pull Request — master (#5)
by Tadas
12:30
created

LegacyFormHelper::isLegacy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Tadcka package.
5
 *
6
 * (c) Tadas Gliaubicas <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tadcka\Bundle\RoutingBundle\Form\Util;
13
14
use Tadcka\Bundle\RoutingBundle\Form\Exception\InvalidArgumentException;
15
16
/**
17
 * Class LegacyFormHelper.
18
 * 
19
 * @package Tadcka\Bundle\RoutingBundle\Form\Util
20
 */
21
class LegacyFormHelper
22
{
23
    private static $map = [
24
        'Tadcka\Bundle\RoutingBundle\Form\Type\RouteChoiceType' => 'tadcka_route_choice',
25
        'Symfony\Component\Form\Extension\Core\Type\CheckboxType' => 'checkbox',
26
        'Symfony\Component\Form\Extension\Core\Type\ChoiceType' => 'choice',
27
        'Symfony\Component\Form\Extension\Core\Type\TextType' => 'text',
28
    ];
29
30
    /**
31
     * @param string $class
32
     *
33
     * @return string
34
     *
35
     * @throws InvalidArgumentException
36
     */
37
    public static function getType($class)
38
    {
39
        if (false === self::isLegacy()) {
40
            return $class;
41
        }
42
43
        if (false === isset(self::$map[$class])) {
44
            throw InvalidArgumentException::create($class);
45
        }
46
47
        return self::$map[$class];
48
    }
49
50
    /**
51
     * @return bool
52
     */
53
    public static function isLegacy()
54
    {
55
        return !method_exists('Symfony\Component\Form\AbstractType', 'getBlockPrefix');
56
    }
57
}
58