PagePartAdminTwigExtension::renderWidget()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 2
nc 2
nop 5
1
<?php
2
3
namespace Kunstmaan\PagePartBundle\Twig\Extension;
4
5
use Kunstmaan\PagePartBundle\PagePartAdmin\PagePartAdmin;
6
use Twig\Environment;
7
use Twig\Extension\AbstractExtension;
8
use Twig\TwigFunction;
9
10
/**
11
 * PagePartAdminTwigExtension
12
 *
13
 * @final since 5.4
14
 */
15
class PagePartAdminTwigExtension extends AbstractExtension
16
{
17
    private $usesExtendedPagePartChooser = false;
18
19
    /**
20
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use TwigFunction[].

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...
21
     */
22
    public function getFunctions()
23
    {
24
        return [
25
            new TwigFunction('pagepartadmin_widget', [$this, 'renderWidget'], ['needs_environment' => true, 'is_safe' => ['html']]),
26
        ];
27
    }
28
29
    /**
30
     * Renders the HTML for a given pagepart
31
     *
32
     * Example usage in Twig:
33
     *
34
     *     {{ pagepartadmin_widget(ppAdmin) }}
35
     *
36
     * You can pass options during the call:
37
     *
38
     *     {{ pagepartadmin_widget(ppAdmin, {'attr': {'class': 'foo'}}) }}
39
     *
40
     *     {{ pagepartadmin_widget(ppAdmin, {'separator': '+++++'}) }}
41
     *
42
     * @param Environment   $env
43
     * @param PagePartAdmin $ppAdmin      The pagepart admin to render
44
     * @param Form          $form         The form
0 ignored issues
show
Documentation introduced by
Should the type for parameter $form not be Form|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
45
     * @param array         $parameters   Additional variables passed to the template
46
     * @param string        $templateName
0 ignored issues
show
Documentation introduced by
Should the type for parameter $templateName not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
47
     *
48
     * @return string The html markup
49
     */
50
    public function renderWidget(Environment $env, PagePartAdmin $ppAdmin, $form = null, array $parameters = [], $templateName = null)
51
    {
52
        if ($templateName === null) {
53
            $templateName = '@KunstmaanPagePart/PagePartAdminTwigExtension/widget.html.twig';
54
        }
55
56
        $template = $env->load($templateName);
57
58
        return $template->render(array_merge($parameters, [
59
            'pagepartadmin' => $ppAdmin,
60
            'page' => $ppAdmin->getPage(),
61
            'form' => $form,
62
            'extended' => $this->usesExtendedPagePartChooser,
63
        ]));
64
    }
65
66
    /**
67
     * Get usesExtendedPagePartChooser.
68
     *
69
     * @return usesExtendedPagePartChooser
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
70
     */
71
    public function getUsesExtendedPagePartChooser()
72
    {
73
        return $this->usesExtendedPagePartChooser;
74
    }
75
76
    /**
77
     * Set usesExtendedPagePartChooser.
78
     *
79
     * @param usesExtendedPagePartChooser the value to set
80
     */
81
    public function setUsesExtendedPagePartChooser($usesExtendedPagePartChooser)
82
    {
83
        $this->usesExtendedPagePartChooser = $usesExtendedPagePartChooser;
0 ignored issues
show
Documentation Bug introduced by
It seems like $usesExtendedPagePartChooser of type object<Kunstmaan\PagePar...dle\Twig\Extension\the> is incompatible with the declared type boolean of property $usesExtendedPagePartChooser.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
84
    }
85
}
86