Passed
Branch master (875b53)
by Sasaya
02:40
created

WatermarkPlugin   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 2
dl 0
loc 21
ccs 12
cts 14
cp 0.8571
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 5 1
A getWatermark() 0 12 1
1
<?php
2
3
namespace UniSharp\Uploadable\Plugins;
4
5
use Intervention\Image\Facades\Image;
6
use Illuminate\Support\Facades\Storage;
7
8
class WatermarkPlugin
9
{
10 2
    public function handle($path)
11
    {
12 2
        $image = Image::make($path);
13 2
        $image->insert($this->getWatermark($image), 'bottom-right');
14 2
        $image->save();
15 2
    }
16
17 2
    protected function getWatermark($image)
18
    {
19 2
        $storagePath = Storage::disk('local')->getDriver()->getAdapter()->getPathPrefix();
20 2
        $watermarkPath = $storagePath . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'watermark.png';
21 2
        $watermark = Image::make($watermarkPath);
22
23 2
        $watermark->resize($image->getWidth() / 2.5, null, function ($constraint) {
24
            $constraint->aspectRatio();
25
            $constraint->upsize();
26 2
        });
27
28 2
        return $watermark;
29
    }
30
}
31