Completed
Push — master ( 1de9b7...830752 )
by Kristof
38:46 queued 24:09
created

Kunstmaan/AdminBundle/Twig/FormToolsExtension.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
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
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')),
35
            new \Twig_SimpleFunction('form_has_errors_recursive', array($this, 'hasErrorMessages')),
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