ImageManipulation::imageCopyMergeAlpha()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 26
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 6
dl 0
loc 26
rs 10
c 1
b 1
f 0
cc 2
nc 2
nop 9

How to fix   Many Parameters   

Many Parameters

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
2
3
declare(strict_types=1);
4
5
namespace Minepic\Image;
6
7
use Minepic\Image\Exceptions\ImageTrueColorCreationFailedException;
8
9
trait ImageManipulation
10
{
11
    /**
12
     * @see https://www.php.net/manual/en/function.imagecopymerge.php#92787
13
     * @throws ImageTrueColorCreationFailedException
14
     */
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
    }
42
}
43