TwigBridge::addExtension()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 15
rs 9.4285
cc 1
eloc 8
nc 1
nop 2
1
<?php
2
3
/*
4
 * This file is part of the WPSymfonyForm plugin.
5
 *
6
 * Copyright (c) 2015-2016 LIN3S <[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 LIN3S\WPSymfonyForm\Twig;
13
14
use LIN3S\WPSymfonyForm\Translation\Translator;
15
use Symfony\Bridge\Twig\Extension\FormExtension;
16
use Symfony\Bridge\Twig\Extension\TranslationExtension;
17
use Symfony\Bridge\Twig\Form\TwigRenderer;
18
use Symfony\Bridge\Twig\Form\TwigRendererEngine;
19
20
/**
21
 * Twig bridge class.
22
 *
23
 * @author Gorka Laucirica <[email protected]>
24
 */
25
class TwigBridge
26
{
27
    /**
28
     * @param \Twig_Environment $twig      The twig
29
     * @param string            $formTheme The form theme
30
     *
31
     * @return mixed
32
     */
33
    public static function addExtension(\Twig_Environment $twig, $formTheme = 'form_div_layout.html.twig')
34
    {
35
        $formEngine = new TwigRendererEngine([$formTheme]);
36
        $twig->addExtension(
37
            new FormExtension(new TwigRenderer($formEngine))
38
        );
39
40
        $twig->addExtension(
41
            new TranslationExtension(
42
                Translator::instance()
0 ignored issues
show
Documentation introduced by
\LIN3S\WPSymfonyForm\Tra...\Translator::instance() is of type object<LIN3S\WPSymfonyFo...Translation\Translator>, but the function expects a object<Symfony\Component...on\TranslatorInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
43
            )
44
        );
45
46
        return $twig;
47
    }
48
}
49