Completed
Push — develop ( d42c3f...ac22da )
by Freddie
02:15
created

AbstractBuilder::parseOptions()   F

Complexity

Conditions 20
Paths 128

Size

Total Lines 83
Code Lines 55

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 20
eloc 55
c 0
b 0
f 0
nc 128
nop 1
dl 0
loc 83
rs 3.9333

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace FlexPHP\Inputs\Builder;
4
5
use Symfony\Component\Form\FormBuilderInterface;
6
7
abstract class AbstractBuilder implements BuilderInterface
8
{
9
    protected $name;
10
    protected $options;
11
12
    public function getName(): string
13
    {
14
        return preg_replace('/(\s)+/', '_', trim($this->name)) ?? $this->name;
15
    }
16
17
    public function getOptions(): array
18
    {
19
        return $this->options;
20
    }
21
22
    abstract protected function factory(): FormBuilderInterface;
23
24
    protected function twig()
25
    {
26
        $appVariableReflection = new \ReflectionClass('\Symfony\Bridge\Twig\AppVariable');
27
        $vendorTwigBridgeDirectory = dirname((string)$appVariableReflection->getFileName());
28
29
        $loader = new \Twig\Loader\FilesystemLoader([
30
            $vendorTwigBridgeDirectory . '/Resources/views/Form',
31
        ]);
32
33
        $twig = new \Twig\Environment($loader);
34
        $twig->addExtension(new \Symfony\Bridge\Twig\Extension\FormExtension());
35
        $twig->addExtension(new \Symfony\Bridge\Twig\Extension\TranslationExtension(
36
            new \Symfony\Component\Translation\Translator('en')
37
        ));
38
39
        $formEngine = new \Symfony\Bridge\Twig\Form\TwigRendererEngine(['bootstrap_4_layout.html.twig'], $twig);
40
        $twig->addRuntimeLoader(new \Twig\RuntimeLoader\FactoryRuntimeLoader([
41
            \Symfony\Component\Form\FormRenderer::class => function () use ($formEngine) {
42
                return new \Symfony\Component\Form\FormRenderer($formEngine);
43
            },
44
        ]));
45
46
        return $twig;
47
    }
48
}
49