Completed
Push — master ( ba8ed9...770316 )
by Jeroen
06:11
created

FormToolsExtension::getFunctions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Kunstmaan\AdminBundle\Twig;
4
5
use Kunstmaan\AdminBundle\Helper\FormHelper;
6
use Symfony\Component\Form\FormView;
7
8
/**
9
 * FormToolsExtension
10
 */
11
class FormToolsExtension extends \Twig_Extension
0 ignored issues
show
Deprecated Code introduced by
The class Twig_Extension has been deprecated with message: since Twig 2.7, use "Twig\Extension\AbstractExtension" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
12
{
13
    /**
14
     * @var FormHelper
15
     */
16
    private $formHelper;
17
18
    /**
19
     * @param FormHelper $formHelper
20
     */
21
    public function __construct(FormHelper $formHelper)
22
    {
23
        $this->formHelper = $formHelper;
24
    }
25
26
    /**
27
     * Get Twig functions defined in this extension.
28
     *
29
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use \Twig_SimpleFunction[].

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
30
     */
31
    public function getFunctions()
32
    {
33
        return array(
34
            new \Twig_SimpleFunction('form_errors_recursive', array($this, 'getErrorMessages')),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: since Twig 2.7, use "Twig\TwigFunction" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
35
            new \Twig_SimpleFunction('form_has_errors_recursive', array($this, 'hasErrorMessages')),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: since Twig 2.7, use "Twig\TwigFunction" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
36
        );
37
    }
38
39
    /**
40
     * Return if there are error messages.
41
     *
42
     * @param FormView $formView
43
     *
44
     * @return bool
45
     */
46
    public function hasErrorMessages(FormView $formView)
47
    {
48
        return $this->formHelper->hasRecursiveErrorMessages($formView);
49
    }
50
51
    /**
52
     * Get the error messages.
53
     *
54
     * @param FormView[]|FormView $formViews The form views
55
     * @param array               &$errors   The errors
56
     *
57
     * @return array
58
     */
59
    public function getErrorMessages($formViews, array &$errors = array())
60
    {
61
        return $this->formHelper->getRecursiveErrorMessages($formViews, $errors);
62
    }
63
}
64