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

68publishers / image-storage / 20785308562

07 Jan 2026 02:46PM UTC coverage: 91.321% (-0.6%) from 91.908%
20785308562

push

github

tg666
Fixed unit test `StripMetaTest` for PHP 8.1

1389 of 1521 relevant lines covered (91.32%)

0.91 hits per line

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

87.1
/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\Codec\Value\PresetValue;
14
use SixtyEightPublishers\ImageStorage\Modifier\Collection\ModifierCollectionInterface;
15
use SixtyEightPublishers\ImageStorage\Modifier\ModifierInterface;
16
use SixtyEightPublishers\ImageStorage\Modifier\Preset\PresetCollectionInterface;
17
use SixtyEightPublishers\ImageStorage\Modifier\Validator\ValidatorInterface;
18
use function is_array;
19
use function sprintf;
20

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

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

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

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

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

51
    public function setPresets(array $presets): void
52
    {
53
        foreach ($presets as $name => $preset) {
1✔
54
            if (!is_array($preset)) {
1✔
55
                throw new InvalidArgumentException(sprintf(
1✔
56
                    'The argument passed into the method %s() must be an array of arrays (a preset name => an array of modifier aliases).',
1✔
57
                    __METHOD__,
1✔
58
                ));
59
            }
60

61
            $this->presetCollection->add((string) $name, $preset);
1✔
62
        }
63
    }
1✔
64

65
    public function setApplicators(array $applicators): void
66
    {
67
        foreach ($applicators as $applicator) {
1✔
68
            if (!$applicator instanceof ModifierApplicatorInterface) {
1✔
69
                throw new InvalidArgumentException(sprintf(
1✔
70
                    'The argument passed into the method %s() must be an array of %s.',
1✔
71
                    __METHOD__,
1✔
72
                    ModifierApplicatorInterface::class,
1✔
73
                ));
74
            }
75

76
            $this->applicators[] = $applicator;
1✔
77
        }
78
    }
1✔
79

80
    public function setValidators(array $validators): void
81
    {
82
        foreach ($validators as $validator) {
1✔
83
            if (!$validator instanceof ValidatorInterface) {
1✔
84
                throw new InvalidArgumentException(sprintf(
1✔
85
                    'The argument passed into the method %s() must be an array of %s.',
1✔
86
                    __METHOD__,
1✔
87
                    ValidatorInterface::class,
1✔
88
                ));
89
            }
90

91
            $this->validators[] = $validator;
1✔
92
        }
93
    }
1✔
94

95
    public function getModifierCollection(): ModifierCollectionInterface
96
    {
97
        return $this->modifierCollection;
1✔
98
    }
99

100
    public function getCodec(): CodecInterface
101
    {
102
        return $this->codec;
1✔
103
    }
104

105
    public function modifyImage(Image $image, PathInfoInterface $info, string|array $modifiers, bool $stripMeta = false): ModifyResult
106
    {
107
        if (!is_array($modifiers)) {
1✔
108
            $modifiers = $this->getCodec()->decode(new PresetValue($modifiers));
1✔
109
        }
110

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

115
        $values = $this->modifierCollection->parseValues($modifiers);
1✔
116

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

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

125
        $modified = false;
1✔
126
        $encodeFormat = null;
1✔
127
        $encodeQuality = null;
1✔
128

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

135
                    continue;
1✔
136
                }
137

138
                if (ModifierApplicatorInterface::OutFormat === $key) {
×
139
                    $encodeFormat = $value;
×
140
                    $modified = true;
×
141

142
                    continue;
×
143
                }
144

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

152
        return new ModifyResult(
1✔
153
            image: $image,
1✔
154
            modified: $modified,
155
            encodeFormat: $encodeFormat,
156
            encodeQuality: $encodeQuality,
157
        );
158
    }
159
}
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