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 | * @author Sergey Glagolev <[email protected]> |
||
4 | * @link https://github.com/shogodev/argilla/ |
||
5 | * @copyright Copyright © 2003-2014 Shogo |
||
6 | * @license http://argilla.ru/LICENSE |
||
7 | * @package frontend.widgets |
||
8 | * Пример использования в формах |
||
9 | * <div> |
||
10 | * 'elements' => array( |
||
11 | * ... |
||
12 | * 'birthday' => array( |
||
13 | * 'type' => 'DateIntervalWidget', |
||
14 | * 'form' => $this, |
||
15 | * 'template' => '<span class="select-container form-size-third date-select">{day}</span> |
||
16 | * <span class="select-container form-size-third date-select">{month}</span> |
||
17 | * <span class="select-container form-size-third date-select">{year}</span>', |
||
18 | * 'attribute' => 'birthday', |
||
19 | * 'rangeYears' => array(intval(date("Y"))-100, intval(date("Y"))-5), |
||
20 | * ), |
||
21 | * ... |
||
22 | * ), |
||
23 | * |
||
24 | * или |
||
25 | * |
||
26 | * 'elements' => array( |
||
27 | * ... |
||
28 | * 'birthday' => array( |
||
29 | * 'type' => 'DateIntervalWidget', |
||
30 | * 'form' => $this, |
||
31 | * 'layout' => '{input}' |
||
32 | * 'template' => '<div class="form-row m20">{label}<div class="form-field"> |
||
33 | * <span class="select-container form-size-third date-select">{day}</span> |
||
34 | * <span class="select-container form-size-third date-select">{month}</span> |
||
35 | * <span class="select-container form-size-third date-select">{year}</span> |
||
36 | * {error}</div></div>', |
||
37 | * 'attribute' => 'birthday', |
||
38 | * 'rangeYears' => array(intval(date("Y"))-100, intval(date("Y"))-5), |
||
39 | * ), |
||
40 | * ... |
||
41 | * ), |
||
42 | * </div> |
||
43 | */ |
||
44 | class DateIntervalWidget extends CWidget |
||
45 | { |
||
46 | public $model; |
||
47 | |||
48 | public $attribute; |
||
49 | |||
50 | /** |
||
51 | * @var FForm |
||
52 | */ |
||
53 | public $form; |
||
54 | |||
55 | public $rangeYears; |
||
56 | |||
57 | /** |
||
58 | * @var FFormInputElement |
||
59 | */ |
||
60 | public $element; |
||
61 | |||
62 | public $hideCalendar = true; |
||
63 | |||
64 | public $template = '{day}{month}{year}{calendar}{input}{error}'; |
||
65 | |||
66 | /** |
||
67 | * @var DateTime |
||
68 | */ |
||
69 | private $selectData; |
||
70 | |||
71 | 1 | public function init() |
|
72 | { |
||
73 | 1 | if( empty($this->rangeYears) ) |
|
74 | 1 | $this->rangeYears = array(intval(date("Y")), intval(date("Y")) + 1); |
|
75 | |||
76 | 1 | if( isset($this->form->elements[$this->attribute]) ) |
|
77 | 1 | $this->element = $this->form->elements[$this->attribute]; |
|
78 | |||
79 | 1 | $this->selectData = DateTime::createFromFormat('d.m.Y', $this->model->{$this->attribute}); |
|
0 ignored issues
–
show
|
|||
80 | 1 | } |
|
81 | |||
82 | 1 | public function run() |
|
83 | { |
||
84 | 1 | echo strtr($this->template, array( |
|
85 | 1 | '{label}' => $this->element->getLabel(), |
|
86 | 1 | '{day}' => $this->getDays(), |
|
87 | 1 | '{month}' => $this->renderMonths(), |
|
88 | 1 | '{year}' => $this->renderYears(), |
|
89 | 1 | '{calendar}' => $this->renderCalendar(), |
|
90 | 1 | '{error}' => $this->errorInMainLayout() ? '' : $this->renderError(), |
|
91 | 1 | )); |
|
92 | 1 | echo $this->renderInput(); |
|
93 | |||
94 | 1 | $this->registerScript(); |
|
95 | 1 | } |
|
96 | |||
97 | 1 | private function renderInput() |
|
98 | { |
||
99 | 1 | $defaultData = !empty($this->form->model->{$this->attribute}) ? $this->form->model->{$this->attribute} : null; |
|
100 | |||
101 | 1 | return CHtml::hiddenField(CHtml::resolveName($this->model, $this->attribute), $defaultData); |
|
102 | } |
||
103 | |||
104 | private function renderError() |
||
105 | { |
||
106 | return $this->form->getActiveFormWidget()->error($this->form->model, $this->attribute); |
||
107 | } |
||
108 | |||
109 | 1 | private function renderCalendar() |
|
110 | { |
||
111 | 1 | $this->registerCalendarScript(); |
|
112 | |||
113 | 1 | return CHtml::tag('div', array('class' => 'calendar m5', 'style' => $this->hideCalendar ? 'display: none;' : ''), true); |
|
114 | } |
||
115 | |||
116 | 1 | private function getDays() |
|
117 | { |
||
118 | 1 | $selectedValue = $this->selectData ? intval($this->selectData->format('d')) : null; |
|
119 | 1 | return CHtml::dropDownList('day', $selectedValue, $this->valToKeys(range(1, 31)), array('class' => $this->getElementCssClass())); |
|
120 | } |
||
121 | |||
122 | 1 | private function renderMonths() |
|
123 | { |
||
124 | 1 | $selectedValue = $this->selectData ? intval($this->selectData->format('m')) : null; |
|
125 | 1 | return CHtml::dropDownList('month', $selectedValue, Yii::app()->locale->getMonthNames(), array('class' => $this->getElementCssClass())); |
|
126 | } |
||
127 | |||
128 | 1 | private function renderYears() |
|
129 | { |
||
130 | 1 | $selectedValue = $this->selectData ? $this->selectData->format('Y') : null; |
|
131 | 1 | return CHtml::dropDownList('year', $selectedValue, $this->valToKeys(range($this->rangeYears[0], $this->rangeYears[1])), array('class' => $this->getElementCssClass())); |
|
132 | } |
||
133 | |||
134 | 1 | private function getElementCssClass() |
|
135 | { |
||
136 | 1 | return CHtml::activeId($this->model, $this->attribute).'_element'; |
|
137 | } |
||
138 | |||
139 | 1 | private function getAttributeId() |
|
140 | { |
||
141 | 1 | return CHtml::getIdByName(CHtml::resolveName($this->model, $this->attribute)); |
|
142 | } |
||
143 | |||
144 | 1 | private function valToKeys($array) |
|
145 | { |
||
146 | 1 | $newArray = array(); |
|
147 | |||
148 | 1 | foreach($array as $value) |
|
149 | 1 | $newArray[$value] = $value; |
|
150 | |||
151 | 1 | return $newArray; |
|
152 | } |
||
153 | |||
154 | 1 | private function errorInMainLayout() |
|
155 | { |
||
156 | 1 | return strpos($this->element->getLayout(), '{error}') !== false; |
|
157 | } |
||
158 | |||
159 | 1 | View Code Duplication | private function registerCalendarScript() |
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. ![]() |
|||
160 | { |
||
161 | 1 | Yii::app()->clientScript->registerScript(__CLASS__.__METHOD__, " |
|
162 | |||
163 | if( $('.calendar').length ) |
||
164 | { |
||
165 | $('.calendar').datePicker({inline:true}).bind('dateSelected', function(e, selectedDate) { |
||
166 | 1 | var selector = '.".$this->getElementCssClass()."'; |
|
167 | $(selector + '[name=day]').val(selectedDate.getDate()).trigger('change'); |
||
168 | $(selector + '[name=month]').val(selectedDate.getMonth() + 1).trigger('change'); |
||
169 | $(selector + '[name=year]').val(selectedDate.getFullYear()).trigger('change'); |
||
170 | |||
171 | 1 | $('#".$this->getAttributeId()."').val(selectedDate.asString('dd.mm.yyyy')).trigger('change'); |
|
172 | }); |
||
173 | } |
||
174 | 1 | "); |
|
175 | 1 | } |
|
176 | |||
177 | 1 | View Code Duplication | private function registerScript() |
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. ![]() |
|||
178 | { |
||
179 | 1 | Yii::app()->clientScript->registerScript(__CLASS__.__METHOD__, " |
|
180 | 1 | $('.".$this->getElementCssClass()."').on('change', function(e) { |
|
181 | 1 | var selector = '.".$this->getElementCssClass()."'; |
|
182 | var date = new Date( |
||
183 | $(selector + '[name=year]').val(), |
||
184 | $(selector + '[name=month]').val() - 1, |
||
185 | $(selector + '[name=day]').val() |
||
186 | ); |
||
187 | |||
188 | 1 | $('#".$this->getAttributeId()."').val(date.asString('dd.mm.yyyy')).trigger('change'); |
|
189 | }); |
||
190 | 1 | "); |
|
191 | } |
||
192 | } |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.