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\AdminListBundle\Twig; |
||
4 | |||
5 | use Kunstmaan\AdminListBundle\AdminList\AdminList; |
||
6 | use Kunstmaan\AdminListBundle\Service\ExportService; |
||
7 | use Twig_Environment; |
||
8 | use Twig_Extension; |
||
9 | use Twig_SimpleFunction; |
||
10 | |||
11 | /** |
||
12 | * AdminListTwigExtension |
||
13 | */ |
||
14 | class AdminListTwigExtension extends Twig_Extension |
||
15 | { |
||
16 | /** |
||
17 | * Returns a list of functions to add to the existing list. |
||
18 | * |
||
19 | * @return array An array of functions |
||
20 | */ |
||
21 | View Code Duplication | public function getFunctions() |
|
22 | { |
||
23 | return [ |
||
24 | new Twig_SimpleFunction('adminlist_widget', [$this, 'renderWidget'], ['needs_environment' => true, 'is_safe' => ['html']]), |
||
25 | new Twig_SimpleFunction('adminthumb_widget', [$this, 'renderThumbWidget'], ['needs_environment' => true, 'is_safe' => ['html']]), |
||
26 | new Twig_SimpleFunction('supported_export_extensions', [$this, 'getSupportedExtensions']), |
||
27 | ]; |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * {@inheritdoc} |
||
32 | */ |
||
33 | public function getTests() |
||
34 | { |
||
35 | return [ |
||
36 | new \Twig_SimpleTest('instanceof', [$this, 'isInstanceOf']), |
||
37 | ]; |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * @param object $object |
||
42 | * @param string $class |
||
43 | * |
||
44 | * @return bool |
||
45 | */ |
||
46 | public function isInstanceOf($object, $class) |
||
47 | { |
||
48 | return $object instanceof $class; |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * Renders the HTML for a given view |
||
53 | * |
||
54 | * Example usage in Twig: |
||
55 | * |
||
56 | * {{ form_widget(view) }} |
||
57 | * |
||
58 | * You can pass options during the call: |
||
59 | * |
||
60 | * {{ form_widget(view, {'attr': {'class': 'foo'}}) }} |
||
61 | * |
||
62 | * {{ form_widget(view, {'separator': '+++++'}) }} |
||
63 | * |
||
64 | * @param Twig_Environment $env |
||
65 | * @param AdminList $view The view to render |
||
66 | * @param string $basepath The base path |
||
67 | * @param array $urlparams Additional url params |
||
68 | * @param array $addparams Add params |
||
69 | * |
||
70 | * @return string The html markup |
||
71 | * |
||
72 | * @throws \Throwable |
||
73 | * @throws \Twig_Error_Loader |
||
74 | * @throws \Twig_Error_Runtime |
||
75 | * @throws \Twig_Error_Syntax |
||
76 | */ |
||
77 | View Code Duplication | public function renderWidget(Twig_Environment $env, AdminList $view, $basepath, array $urlparams = [], array $addparams = []) |
|
0 ignored issues
–
show
|
|||
78 | { |
||
79 | $filterBuilder = $view->getFilterBuilder(); |
||
80 | |||
81 | return $env->render( |
||
82 | 'KunstmaanAdminListBundle:AdminListTwigExtension:widget.html.twig', |
||
83 | [ |
||
84 | 'filter' => $filterBuilder, |
||
85 | 'basepath' => $basepath, |
||
86 | 'addparams' => $addparams, |
||
87 | 'extraparams' => $urlparams, |
||
88 | 'adminlist' => $view, |
||
89 | ] |
||
90 | ); |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * Renders the HTML for a given view |
||
95 | * |
||
96 | * Example usage in Twig: |
||
97 | * |
||
98 | * {{ form_widget(view) }} |
||
99 | * |
||
100 | * You can pass options during the call: |
||
101 | * |
||
102 | * {{ form_widget(view, {'attr': {'class': 'foo'}}) }} |
||
103 | * |
||
104 | * {{ form_widget(view, {'separator': '+++++'}) }} |
||
105 | * |
||
106 | * @param Twig_Environment $env |
||
107 | * @param AdminList $view The view to render |
||
108 | * @param string $basepath The base path |
||
109 | * @param array $urlparams Additional url params |
||
110 | * @param array $addparams Add params |
||
111 | * |
||
112 | * @return string The html markup |
||
113 | * |
||
114 | * @throws \Throwable |
||
115 | * @throws \Twig_Error_Loader |
||
116 | * @throws \Twig_Error_Runtime |
||
117 | * @throws \Twig_Error_Syntax |
||
118 | */ |
||
119 | View Code Duplication | public function renderThumbWidget(Twig_Environment $env, AdminList $view, $basepath, array $urlparams = [], array $addparams = []) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
120 | { |
||
121 | $filterBuilder = $view->getFilterBuilder(); |
||
122 | |||
123 | return $env->render( |
||
124 | 'KunstmaanAdminListBundle:AdminListTwigExtension:thumbwidget.html.twig', |
||
125 | [ |
||
126 | 'filter' => $filterBuilder, |
||
127 | 'basepath' => $basepath, |
||
128 | 'addparams' => $addparams, |
||
129 | 'extraparams' => $urlparams, |
||
130 | 'adminlist' => $view, |
||
131 | ] |
||
132 | ); |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * @return array |
||
137 | */ |
||
138 | public function getSupportedExtensions() |
||
139 | { |
||
140 | return ExportService::getSupportedExtensions(); |
||
141 | } |
||
142 | } |
||
143 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.