Conditions | 14 |
Paths | 36 |
Total Lines | 81 |
Code Lines | 47 |
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 |
||
76 | public function getWidth($pdf) { |
||
77 | // Setup the style name, a font must be selected to calculate the width |
||
78 | $pdf->setCurrentStyle('footnotenum'); |
||
79 | |||
80 | // Check for the largest font size in the box |
||
81 | $fsize = $pdf->getCurrentStyleHeight(); |
||
82 | if ($fsize > $pdf->largestFontHeight) { |
||
83 | $pdf->largestFontHeight = $fsize; |
||
84 | } |
||
85 | |||
86 | // Returns the Object if already numbered else false |
||
87 | if (empty($this->num)) { |
||
88 | $pdf->checkFootnote($this); |
||
89 | } |
||
90 | |||
91 | // Get the line width |
||
92 | $lw = ceil($pdf->GetStringWidth($this->numText)); |
||
93 | // Line Feed counter - Number of lines in the text |
||
94 | $lfct = substr_count($this->numText, "\n") + 1; |
||
95 | // If there is still remaining wrap width... |
||
96 | if ($this->wrapWidthRemaining > 0) { |
||
97 | // Check with line counter too! |
||
98 | // but floor the $wrapWidthRemaining first to keep it bugfree! |
||
99 | $wrapWidthRemaining = (int) ($this->wrapWidthRemaining); |
||
100 | if ($lw >= $wrapWidthRemaining || $lfct > 1) { |
||
101 | $newtext = ''; |
||
102 | $lines = explode("\n", $this->numText); |
||
103 | // Go throught the text line by line |
||
104 | foreach ($lines as $line) { |
||
105 | // Line width in points |
||
106 | $lw = ceil($pdf->GetStringWidth($line)); |
||
107 | // If the line has to be wraped |
||
108 | if ($lw >= $wrapWidthRemaining) { |
||
109 | $words = explode(' ', $line); |
||
110 | $addspace = count($words); |
||
111 | $lw = 0; |
||
112 | foreach ($words as $word) { |
||
113 | $addspace--; |
||
114 | $lw += ceil($pdf->GetStringWidth($word . ' ')); |
||
115 | if ($lw < $wrapWidthRemaining) { |
||
116 | $newtext .= $word; |
||
117 | if ($addspace != 0) { |
||
118 | $newtext .= ' '; |
||
119 | } |
||
120 | } else { |
||
121 | $lw = $pdf->GetStringWidth($word . ' '); |
||
122 | $newtext .= "\n$word"; |
||
123 | if ($addspace != 0) { |
||
124 | $newtext .= ' '; |
||
125 | } |
||
126 | // Reset the wrap width to the cell width |
||
127 | $wrapWidthRemaining = $this->wrapWidthCell; |
||
128 | } |
||
129 | } |
||
130 | } else { |
||
131 | $newtext .= $line; |
||
132 | } |
||
133 | // Check the Line Feed counter |
||
134 | if ($lfct > 1) { |
||
135 | // Add a new line feed as long as it’s not the last line |
||
136 | $newtext .= "\n"; |
||
137 | // Reset the line width |
||
138 | $lw = 0; |
||
139 | // Reset the wrap width to the cell width |
||
140 | $wrapWidthRemaining = $this->wrapWidthCell; |
||
141 | } |
||
142 | $lfct--; |
||
143 | } |
||
144 | $this->numText = $newtext; |
||
145 | $lfct = substr_count($this->numText, "\n"); |
||
146 | |||
147 | return [$lw, 1, $lfct]; |
||
148 | } |
||
149 | } |
||
150 | $l = 0; |
||
151 | $lfct = substr_count($this->numText, "\n"); |
||
152 | if ($lfct > 0) { |
||
153 | $l = 2; |
||
154 | } |
||
155 | |||
156 | return [$lw, $l, $lfct]; |
||
157 | } |
||
159 |