Conditions | 3 |
Paths | 3 |
Total Lines | 53 |
Code Lines | 32 |
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 namespace EvolutionCMS\Support; |
||
79 | public function drawText() { |
||
80 | $dir = dir($this->dir_font); |
||
81 | $fontstmp = array(); |
||
82 | while (false !== ($file = $dir->read())) { |
||
83 | if(substr($file, -4) == '.ttf') { |
||
84 | $fontstmp[] = $this->dir_font.$file; |
||
85 | } |
||
86 | } |
||
87 | $dir->close(); |
||
88 | $text_font = (string) $fontstmp[array_rand($fontstmp)]; |
||
89 | |||
90 | /* angle for text inclination */ |
||
91 | $text_angle = rand(-9,9); |
||
92 | /* initial text size */ |
||
93 | $text_size = 30; |
||
94 | /* calculate text width and height */ |
||
95 | $box = imagettfbbox ( $text_size, $text_angle, $text_font, $this->word); |
||
96 | $text_width = $box[2]-$box[0]; //text width |
||
97 | $text_height= $box[5]-$box[3]; //text height |
||
98 | |||
99 | /* adjust text size */ |
||
100 | $text_size = round((20 * $this->im_width)/$text_width); |
||
101 | |||
102 | /* recalculate text width and height */ |
||
103 | $box = imagettfbbox ( $text_size, $text_angle, $text_font, $this->word); |
||
104 | $text_width = $box[2]-$box[0]; //text width |
||
105 | $text_height= $box[5]-$box[3]; //text height |
||
106 | |||
107 | /* calculate center position of text */ |
||
108 | $text_x = ($this->im_width - $text_width)/2; |
||
109 | $text_y = ($this->im_height - $text_height)/2; |
||
110 | |||
111 | /* create canvas for text drawing */ |
||
112 | $im_text = imagecreate ($this->im_width, $this->im_height); |
||
113 | $bg_color = imagecolorallocate ($im_text, 255, 255, 255); |
||
114 | |||
115 | /* pick color for text */ |
||
116 | $text_color = imagecolorallocate ($im_text, 0, 51, 153); |
||
117 | |||
118 | /* draw text into canvas */ |
||
119 | imagettftext ( $im_text, |
||
120 | $text_size, |
||
121 | $text_angle, |
||
122 | $text_x, |
||
123 | $text_y, |
||
124 | $text_color, |
||
125 | $text_font, |
||
126 | $this->word); |
||
127 | |||
128 | /* remove background color */ |
||
129 | imagecolortransparent($im_text, $bg_color); |
||
130 | return $im_text; |
||
131 | } |
||
132 | |||
169 |
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString
.