• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

68publishers / image-storage / 22677854876

04 Mar 2026 04:07PM UTC coverage: 87.038% (-4.3%) from 91.356%
22677854876

push

github

tg666
Added port to Referer header if exists

0 of 3 new or added lines in 1 file covered. (0.0%)

113 existing lines in 8 files now uncovered.

1484 of 1705 relevant lines covered (87.04%)

0.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.0
/src/Modifier/Facade/ModifierFacade.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace SixtyEightPublishers\ImageStorage\Modifier\Facade;
6

7
use Intervention\Image\Image;
8
use SixtyEightPublishers\FileStorage\Config\ConfigInterface;
9
use SixtyEightPublishers\FileStorage\PathInfoInterface;
10
use SixtyEightPublishers\ImageStorage\Exception\InvalidArgumentException;
11
use SixtyEightPublishers\ImageStorage\Modifier\Applicator\ModifierApplicatorInterface;
12
use SixtyEightPublishers\ImageStorage\Modifier\Codec\CodecInterface;
13
use SixtyEightPublishers\ImageStorage\Modifier\Collection\ModifierCollectionInterface;
14
use SixtyEightPublishers\ImageStorage\Modifier\ModifierInterface;
15
use SixtyEightPublishers\ImageStorage\Modifier\Preset\PresetCollectionInterface;
16
use SixtyEightPublishers\ImageStorage\Modifier\Validator\ValidatorInterface;
17
use function is_string;
18
use function sprintf;
19

20
final class ModifierFacade implements ModifierFacadeInterface
21
{
22
    /** @var array<ModifierApplicatorInterface> */
23
    private array $applicators = [];
24

25
    /** @var array<ValidatorInterface> */
26
    private array $validators = [];
27

28
    public function __construct(
1✔
29
        private readonly ConfigInterface $config,
30
        private readonly CodecInterface $codec,
31
        private readonly PresetCollectionInterface $presetCollection,
32
        private readonly ModifierCollectionInterface $modifierCollection,
33
    ) {}
1✔
34

35
    public function setModifiers(array $modifiers): void
36
    {
37
        foreach ($modifiers as $modifier) {
1✔
38
            if (!$modifier instanceof ModifierInterface) {
1✔
39
                throw new InvalidArgumentException(sprintf(
1✔
40
                    'The argument passed into the method %s() must be an array of %s.',
1✔
41
                    __METHOD__,
1✔
42
                    ModifierInterface::class,
1✔
43
                ));
44
            }
45

46
            $this->modifierCollection->add($modifier);
1✔
47
        }
48
    }
1✔
49

50
    public function setPresets(array $presets): void
51
    {
52
        foreach ($presets as $name => $preset) {
1✔
53
            $this->presetCollection->add((string) $name, $preset);
1✔
54
        }
55
    }
1✔
56

57
    public function setApplicators(array $applicators): void
58
    {
59
        foreach ($applicators as $applicator) {
1✔
60
            if (!$applicator instanceof ModifierApplicatorInterface) {
1✔
61
                throw new InvalidArgumentException(sprintf(
1✔
62
                    'The argument passed into the method %s() must be an array of %s.',
1✔
63
                    __METHOD__,
1✔
64
                    ModifierApplicatorInterface::class,
1✔
65
                ));
66
            }
67

68
            $this->applicators[] = $applicator;
1✔
69
        }
70
    }
1✔
71

72
    public function setValidators(array $validators): void
73
    {
74
        foreach ($validators as $validator) {
1✔
75
            if (!$validator instanceof ValidatorInterface) {
1✔
76
                throw new InvalidArgumentException(sprintf(
1✔
77
                    'The argument passed into the method %s() must be an array of %s.',
1✔
78
                    __METHOD__,
1✔
79
                    ValidatorInterface::class,
1✔
80
                ));
81
            }
82

83
            $this->validators[] = $validator;
1✔
84
        }
85
    }
1✔
86

87
    public function getModifierCollection(): ModifierCollectionInterface
88
    {
89
        return $this->modifierCollection;
1✔
90
    }
91

92
    public function getPresetCollection(): PresetCollectionInterface
93
    {
UNCOV
94
        return $this->presetCollection;
×
95
    }
96

97
    public function getCodec(): CodecInterface
98
    {
99
        return $this->codec;
1✔
100
    }
101

102
    public function modifyImage(Image $image, PathInfoInterface $info, string|array $modifiers, bool $stripMeta = false): ModifyResult
103
    {
104
        if (is_string($modifiers)) {
1✔
105
            $codec = $this->getCodec();
1✔
106
            $modifiers = $codec->expandModifiers(value: $modifiers);
1✔
107
        }
108

109
        if (empty($modifiers)) {
1✔
110
            throw new InvalidArgumentException('Unable to modify the image, modifiers are empty.');
1✔
111
        }
112

113
        $values = $this->modifierCollection->parseValues($modifiers);
1✔
114

115
        if ($stripMeta) {
1✔
UNCOV
116
            $values->add('__stripMeta', true);
×
117
        }
118

119
        foreach ($this->validators as $validator) {
1✔
120
            $validator->validate($values, $this->config);
1✔
121
        }
122

123
        $modified = false;
1✔
124
        $encodeFormat = null;
1✔
125
        $encodeQuality = null;
1✔
126

127
        foreach ($this->applicators as $applicator) {
1✔
128
            foreach ($applicator->apply($image, $info, $values, $this->config) as $key => $value) {
1✔
129
                if (ModifierApplicatorInterface::OutImage === $key && $value instanceof Image) {
1✔
130
                    $image = $value;
1✔
131
                    $modified = true;
1✔
132

133
                    continue;
1✔
134
                }
135

UNCOV
136
                if (ModifierApplicatorInterface::OutFormat === $key) {
×
UNCOV
137
                    $encodeFormat = $value;
×
138
                    $modified = true;
×
139

140
                    continue;
×
141
                }
142

UNCOV
143
                if (ModifierApplicatorInterface::OutQuality === $key) {
×
UNCOV
144
                    $encodeQuality = $value;
×
145
                    $modified = true;
×
146
                }
147
            }
148
        }
149

150
        return new ModifyResult(
1✔
151
            image: $image,
1✔
152
            modified: $modified,
153
            encodeFormat: $encodeFormat,
154
            encodeQuality: $encodeQuality,
155
        );
156
    }
157
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc