ImageSanitize::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace LaravelAt\ImageSanitize;
4
5
use Intervention\Image\Image;
6
use Intervention\Image\ImageManager;
7
use LaravelAt\ImageSanitize\Lists\PatternList;
8
9
class ImageSanitize
10
{
11
    public function __construct(
12
        protected ImageManager $imageManager,
13
        protected PatternList $patternList,
14
    ) {
15
    }
16
17
    public function detect(string $content): bool
18
    {
19
        foreach ($this->patternList->get() as $forbiddenPattern) {
20
            if (strpos($content, $forbiddenPattern) !== false) {
21
                return true;
22
            }
23
        }
24
25
        return false;
26
    }
27
28
    public function sanitize(string $content): Image
29
    {
30
        return $this->imageManager->make($content)->encode(null, 100);
31
    }
32
}
33