This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Class templater engine |
||
4 | * This class will use twig as default and do frequently works for us. |
||
5 | * |
||
6 | * Text Domain: va-templater |
||
7 | * |
||
8 | * Usage: |
||
9 | * $template = new VA\Templater($path); |
||
10 | */ |
||
11 | namespace VA; |
||
12 | |||
13 | use \Twig_Loader_Filesystem; |
||
14 | use \Twig_Environment; |
||
15 | use Philo\Blade\Blade; |
||
16 | |||
17 | class Templater { |
||
18 | |||
19 | /** |
||
20 | * Template adapter, it would be twig or any php template lib. |
||
21 | * |
||
22 | * @var $adapter object Template Engine object |
||
23 | */ |
||
24 | private $adapter = []; |
||
25 | |||
26 | /** |
||
27 | * Template adapter, it would be twig or any php template lib. |
||
28 | * |
||
29 | * @var $adapter object Template Engine object |
||
30 | */ |
||
31 | private $dir_path; |
||
32 | |||
33 | /** |
||
34 | * Template adapter name, it would be twig or any php template lib. |
||
35 | * |
||
36 | * @var $adapter object Template Engine object |
||
37 | */ |
||
38 | private $adapter_name; |
||
39 | |||
40 | /** |
||
41 | * Initialize function |
||
42 | * - Load twig as default engine |
||
43 | * |
||
44 | * @var $dir_path string Path to template folder. |
||
45 | */ |
||
46 | public function __construct($dir_path, $adapter_name = 'blade') { |
||
47 | $this->adapter_name = $adapter_name; |
||
48 | $this->dir_path = $dir_path; |
||
49 | $this->loadAdapter($adapter_name); |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * Load Twig as default adapter |
||
54 | * |
||
55 | * @return Twig_Environment |
||
56 | */ |
||
57 | public function loadTwig() { |
||
58 | if(!$this->adapter) { |
||
0 ignored issues
–
show
|
|||
59 | $loader = new Twig_Loader_Filesystem($this->dir_path); |
||
60 | $this->adapter = new Twig_Environment($loader, array( |
||
0 ignored issues
–
show
It seems like
new \Twig_Environment($loader, array()) of type object<Twig_Environment> is incompatible with the declared type array of property $adapter .
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.. ![]() |
|||
61 | |||
62 | )); |
||
63 | } |
||
64 | return $this->adapter; |
||
0 ignored issues
–
show
|
|||
65 | } |
||
66 | |||
67 | /** |
||
68 | * Load Blade |
||
69 | * |
||
70 | * @return Blade |
||
71 | */ |
||
72 | public function loadBlade() { |
||
73 | $this->adapter = new Blade($this->dir_path,'/tmp');//second parameter is where cache view is located. |
||
0 ignored issues
–
show
$this->dir_path is of type string , but the function expects a array .
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);
![]() It seems like
new \Philo\Blade\Blade($this->dir_path, '/tmp') of type object<Philo\Blade\Blade> is incompatible with the declared type array of property $adapter .
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.. ![]() |
|||
74 | return $this->adapter; |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * Add custom functions for Twig |
||
79 | * |
||
80 | * @param string |
||
81 | * @param function |
||
82 | * |
||
83 | * @return Blade |
||
84 | */ |
||
85 | public function addFunction($functionName, $callback) { |
||
86 | if($this->adapter_name == 'twig') { |
||
87 | $this->adapter->addFunction(new \Twig_SimpleFunction($functionName, $callback)); |
||
0 ignored issues
–
show
|
|||
88 | } |
||
89 | return $this; |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * Load adapter, currently we are using 2 adapters: twig and blade |
||
94 | * |
||
95 | * @var $adapter_name string Path to template folder. |
||
96 | * @return mixed |
||
97 | */ |
||
98 | public function loadAdapter($adapter_name) { |
||
99 | if(!$this->adapter) { // |
||
0 ignored issues
–
show
The expression
$this->adapter of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using ![]() |
|||
100 | $method_name = 'load'.ucfirst($adapter_name); |
||
101 | if(method_exists($this, $method_name)) { |
||
102 | $this->$method_name(); |
||
103 | }else{ |
||
104 | throw new \Exception("Could not load adapter $adapter_name"); |
||
105 | } |
||
106 | } |
||
107 | return $this->adapter; |
||
108 | } |
||
109 | |||
110 | /** |
||
111 | * Alias for engine render function |
||
112 | * |
||
113 | * @var $template string Template file name (e.g. test.php, folder/test.phtml...) |
||
114 | * @var $data array Data array. E.g. ['list' => $list] |
||
115 | * |
||
116 | * @return string Rendered HTML/text |
||
117 | */ |
||
118 | public function render($template, $data = []) { |
||
119 | if($this->adapter_name == 'twig') |
||
120 | { |
||
121 | return $this->adapter->render($template, $data); |
||
0 ignored issues
–
show
|
|||
122 | } |
||
123 | elseif($this->adapter_name == 'blade') |
||
124 | { |
||
125 | return $this->adapter->view()->make($template,$data)->render(); |
||
0 ignored issues
–
show
|
|||
126 | } |
||
127 | } |
||
128 | |||
129 | /** |
||
130 | * Setup Wordpress themes support. |
||
131 | * The template engine will find template file in theme folder before find it in plugin/application folder |
||
132 | * 1. /wp-content/themes/{theme-name}/templates/{application-name}/ |
||
133 | * 2. /path/to/application/ |
||
134 | * |
||
135 | * @var $app_name string Your application name, should be lowercase, letters only. |
||
136 | * |
||
137 | * @return object \VA\Templater\Engine |
||
138 | */ |
||
139 | public function setWordPressThemeSupport($app_name) { |
||
140 | // Path to templates folder in wordpress theme |
||
141 | $theme_template_path = get_template_directory() . '/templates/'. $app_name; |
||
142 | |||
143 | // Create folder path if it does not exists. |
||
144 | if(!file_exists($theme_template_path)) { |
||
145 | wp_mkdir_p($theme_template_path); |
||
146 | } |
||
147 | |||
148 | // Preapare template folders |
||
149 | $template_folders = [ |
||
150 | $theme_template_path, // Load this path first |
||
151 | $this->dir_path // Load this path second |
||
152 | ]; |
||
153 | $loader = new \Twig_Loader_Filesystem($template_folders); |
||
154 | $this->adapter->setLoader($loader); |
||
0 ignored issues
–
show
|
|||
155 | return $this; |
||
156 | } |
||
157 | |||
158 | } |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.