Conditions | 17 |
Paths | 2058 |
Total Lines | 77 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
67 | public function run() |
||
68 | { |
||
69 | $id = $this->htmlOptions['id']; |
||
70 | |||
71 | echo CHtml::openTag('div', $this->htmlOptions); |
||
72 | |||
73 | foreach ($this->alerts as $type => $alert) |
||
74 | { |
||
75 | if (is_string($alert)) |
||
76 | { |
||
77 | $type = $alert; |
||
78 | $alert = array(); |
||
79 | } |
||
80 | |||
81 | if (isset($alert['visible']) && $alert['visible'] === false) |
||
82 | continue; |
||
83 | |||
84 | if (Yii::app()->user->hasFlash($type)) |
||
85 | { |
||
86 | $classes = array('alert in'); |
||
87 | |||
88 | if (!isset($alert['block'])) |
||
89 | $alert['block'] = $this->block; |
||
90 | |||
91 | if ($alert['block'] === true) |
||
92 | $classes[] = 'alert-block'; |
||
93 | |||
94 | if (!isset($alert['fade'])) |
||
95 | $alert['fade'] = $this->fade; |
||
96 | |||
97 | if ($alert['fade'] === true) |
||
98 | $classes[] = 'fade'; |
||
99 | |||
100 | $validTypes = array(self::TYPE_SUCCESS, self::TYPE_INFO, self::TYPE_WARNING, self::TYPE_ERROR, self::TYPE_DANGER); |
||
101 | |||
102 | if (in_array($type, $validTypes)) |
||
103 | $classes[] = 'alert-'.$type; |
||
104 | |||
105 | if (!isset($alert['htmlOptions'])) |
||
106 | $alert['htmlOptions'] = array(); |
||
107 | |||
108 | $classes = implode(' ', $classes); |
||
109 | if (isset($alert['htmlOptions']['class'])) |
||
110 | $alert['htmlOptions']['class'] .= ' '.$classes; |
||
111 | else |
||
112 | $alert['htmlOptions']['class'] = $classes; |
||
113 | |||
114 | echo CHtml::openTag('div', $alert['htmlOptions']); |
||
115 | |||
116 | if ($this->closeText !== false && !isset($alert['closeText'])) |
||
117 | $alert['closeText'] = $this->closeText; |
||
118 | else |
||
119 | $alert['closeText'] = false; |
||
120 | |||
121 | if ($alert['closeText'] !== false) |
||
122 | echo '<a class="close" data-dismiss="alert">'.$alert['closeText'].'</a>'; |
||
123 | |||
124 | echo Yii::app()->user->getFlash($type); |
||
125 | |||
126 | echo '</div>'; |
||
127 | } |
||
128 | } |
||
129 | |||
130 | echo '</div>'; |
||
131 | |||
132 | $selector = "#{$id} .alert"; |
||
133 | |||
134 | /** @var CClientScript $cs */ |
||
135 | $cs = Yii::app()->getClientScript(); |
||
136 | $cs->registerScript(__CLASS__.'#'.$id, "jQuery('{$selector}').alert().animate({opacity: 0.5}, 5000).fadeOut('fast')"); |
||
137 | |||
138 | foreach ($this->events as $name => $handler) |
||
139 | { |
||
140 | $handler = CJavaScript::encode($handler); |
||
141 | $cs->registerScript(__CLASS__.'#'.$id.'_'.$name, "jQuery('{$selector}').on('{$name}', {$handler});"); |
||
142 | } |
||
143 | } |
||
144 | } |
||
145 |