Completed
Push — feature/forms ( c101c1...11cafa )
by Tadas
27:31 queued 12:33
created

LegacyFormHelper   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 37
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getType() 0 12 3
A isLegacy() 0 4 1
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