SaveResourceMiddleware::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 3
crap 2
1
<?php
2
namespace Staticus\Resources\Png;
3
4
use League\Flysystem\FilesystemInterface;
5
use Staticus\Config\ConfigInterface;
6
use Staticus\Resources\Exceptions\SaveResourceErrorException;
7
use Staticus\Resources\Middlewares\Image\SaveImageMiddlewareAbstract;
8
9
class SaveResourceMiddleware extends SaveImageMiddlewareAbstract
10
{
11
    public function __construct(ResourceDO $resourceDO, FilesystemInterface $filesystem, ConfigInterface $config)
12
    {
13
        parent::__construct($resourceDO, $filesystem, $config);
14
    }
15
    protected function writeFile($filePath, $content)
16
    {
17
        if (!imagepng($content, $filePath)) {
18
            imagedestroy($content);
19
            throw new SaveResourceErrorException('File cannot be written to the path ' . $filePath);
20
        }
21
        imagedestroy($content);
22
    }
23
}
24