Conditions | 2 |
Paths | 2 |
Total Lines | 26 |
Code Lines | 6 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 0 |
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
1 | <?php |
||
15 | protected function imageCopyMergeAlpha( |
||
16 | \GdImage $dst_im, |
||
17 | \GdImage $src_im, |
||
18 | int $dst_x, |
||
19 | int $dst_y, |
||
20 | int $src_x, |
||
21 | int $src_y, |
||
22 | int $src_w, |
||
23 | int $src_h, |
||
24 | int $pct |
||
25 | ): void { |
||
26 | // creating a cut resource |
||
27 | $cut = imagecreatetruecolor($src_w, $src_h); |
||
28 | |||
29 | if ($cut instanceof \GdImage === false) { |
||
30 | throw new ImageTrueColorCreationFailedException(); |
||
31 | } |
||
32 | |||
33 | // copying relevant section from background to the cut resource |
||
34 | imagecopy($cut, $dst_im, 0, 0, $dst_x, $dst_y, $src_w, $src_h); |
||
35 | |||
36 | // copying relevant section from watermark to the cut resource |
||
37 | imagecopy($cut, $src_im, 0, 0, $src_x, $src_y, $src_w, $src_h); |
||
38 | |||
39 | // insert cut resource to destination image |
||
40 | imagecopymerge($dst_im, $cut, $dst_x, $dst_y, 0, 0, $src_w, $src_h, $pct); |
||
41 | } |
||
43 |