Conditions | 7 |
Paths | 7 |
Total Lines | 53 |
Lines | 7 |
Ratio | 13.21 % |
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 |
||
125 | public function pages( $args = array() ) { |
||
126 | /* |
||
127 | Call this with arguments: |
||
128 | $args = array( |
||
129 | "pdf" => $pdfData, |
||
130 | "pages" => "1-r2" // removes the last page; |
||
131 | ); |
||
132 | */ |
||
133 | if (!sizeof($args)) { |
||
134 | return false; |
||
135 | } |
||
136 | |||
137 | $inputs = array(); |
||
138 | |||
139 | $tempFile = tempnam( $this->config['temp'], 'pdftk-input-' ); |
||
140 | if ( !$tempFile ) { |
||
141 | return ar_error::raiseError( "pdftk: could not create a temporary input file", 202 ); |
||
142 | } |
||
143 | $inputs['pdf'] = $tempFile; |
||
144 | file_put_contents($tempFile, $args['pdf']); |
||
145 | |||
146 | $outputFile = tempnam( $this->config['temp'], 'pdftk-output-' ); |
||
147 | if ( !$outputFile ) { |
||
148 | return ar_error::raiseError( "pdftk: could not create a temporary output file", 204 ); |
||
149 | } |
||
150 | |||
151 | // pdftk in1.pdf cat 1-r2 output out1.pdf |
||
152 | // system("pdftk.exe \"$frontpage\" background $frontpage_file output \"$wm_frontpage\""); |
||
153 | $execString = $this->config['cmd']; |
||
154 | $execString .= " " . $inputs["pdf"]; |
||
155 | $execString .= " cat " . escapeshellcmd($args["pages"]) . " output $outputFile"; |
||
156 | |||
157 | $execOutput = array(); |
||
158 | $execResult = 0; |
||
159 | |||
160 | exec( $execString, $execOutput, $execResult ); |
||
161 | |||
162 | View Code Duplication | if ( $execResult != 0 ) { |
|
163 | foreach ($inputs as $file) { |
||
164 | @unlink($file); |
||
165 | } |
||
166 | @unlink($outputFile); |
||
167 | return ar_error::raiseError( "pdftk: error ($execResult) while trying to generate PDF: " . implode( "\n", (array) $execOutput ), 203 ); |
||
168 | } |
||
169 | |||
170 | $result = file_get_contents( $outputFile ); |
||
171 | |||
172 | foreach ($inputs as $file) { |
||
173 | @unlink($file); |
||
174 | } |
||
175 | @unlink($outputFile); |
||
176 | return $result; |
||
177 | } |
||
178 | } |
||
203 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.