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

68publishers / image-storage / 22296382066

23 Feb 2026 07:14AM UTC coverage: 87.603% (-3.8%) from 91.356%
22296382066

Pull #61

github

web-flow
Merge 9d5a8b32a into 57d73edfb
Pull Request #61: Better Presets

148 of 227 new or added lines in 17 files covered. (65.2%)

4 existing lines in 1 file now uncovered.

1484 of 1694 relevant lines covered (87.6%)

0.88 hits per line

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

92.0
/src/Modifier/Codec/Codec.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace SixtyEightPublishers\ImageStorage\Modifier\Codec;
6

7
use SixtyEightPublishers\FileStorage\Config\ConfigInterface;
8
use SixtyEightPublishers\ImageStorage\Config\Config;
9
use SixtyEightPublishers\ImageStorage\Exception\InvalidArgumentException;
10
use SixtyEightPublishers\ImageStorage\Modifier\Collection\ModifierCollectionInterface;
11
use SixtyEightPublishers\ImageStorage\Modifier\ParsableModifierInterface;
12
use function assert;
13
use function count;
14
use function explode;
15
use function implode;
16
use function is_array;
17
use function is_string;
18
use function ksort;
19
use function sprintf;
20

21
final class Codec implements CodecInterface
22
{
23
    public function __construct(
1✔
24
        private readonly ConfigInterface $config,
25
        private readonly ModifierCollectionInterface $modifierCollection,
26
    ) {}
1✔
27

28
    public function modifiersToPath(string|array $value): string
29
    {
30
        if (!is_array($value)) {
1✔
31
            throw new InvalidArgumentException(
1✔
32
                message: 'Can not decode value of type string, the value must be array<string, string|numeric|bool>.',
1✔
33
            );
34
        }
35

36
        if (empty($value)) {
1✔
37
            throw new InvalidArgumentException('Value can not be an empty array.');
1✔
38
        }
39

40
        $assigner = $this->config[Config::MODIFIER_ASSIGNER];
1✔
41
        $separator = $this->config[Config::MODIFIER_SEPARATOR];
1✔
42

43
        $assigner = empty($assigner) ? ':' : $assigner;
1✔
44
        $separator = empty($separator) ? ',' : $separator;
1✔
45

46
        $result = [];
1✔
47
        assert(is_string($assigner) && is_string($separator));
48

49
        ksort($value);
1✔
50

51
        foreach ($value as $k => $v) {
1✔
52
            $modifier = $this->modifierCollection->getByAlias($k);
1✔
53

54
            if (!$modifier instanceof ParsableModifierInterface) {
1✔
55
                if (true === (bool) $v) {
1✔
56
                    $result[] = $k;
1✔
57
                }
58

59
                continue;
1✔
60
            }
61

62
            $result[] = $k . $assigner . $v;
1✔
63
        }
64

65
        return implode($separator, $result);
1✔
66
    }
67

68
    public function pathToModifiers(string $value): array
69
    {
70
        if (empty($value)) {
1✔
71
            throw new InvalidArgumentException('Value can not be an empty string.');
1✔
72
        }
73

74
        $parameters = [];
1✔
75
        $assigner = $this->config[Config::MODIFIER_ASSIGNER];
1✔
76
        $separator = $this->config[Config::MODIFIER_SEPARATOR];
1✔
77
        assert(is_string($assigner) && is_string($separator));
78

79
        $assigner = empty($assigner) ? ':' : $assigner;
1✔
80
        $separator = empty($separator) ? ',' : $separator;
1✔
81

82
        foreach (explode($separator, $value) as $modifier) {
1✔
83
            $modifier = explode($assigner, $modifier);
1✔
84
            $count = count($modifier);
1✔
85

86
            if (2 < $count) {
1✔
87
                throw new InvalidArgumentException(sprintf(
1✔
88
                    'An invalid path "%s" passed, the modifier "%s" has an invalid format.',
1✔
89
                    $value,
90
                    implode($assigner, $modifier),
1✔
91
                ));
92
            }
93

94
            $modifierObject = $this->modifierCollection->getByAlias($modifier[0]);
1✔
95

96
            if (1 === $count && $modifierObject instanceof ParsableModifierInterface) {
1✔
97
                throw new InvalidArgumentException(sprintf(
1✔
98
                    'An invalid path "%s" passed, the modifier "%s" must have a value.',
1✔
99
                    $value,
100
                    $modifierObject->getAlias(),
1✔
101
                ));
102
            }
103

104
            if (2 === $count && !$modifierObject instanceof ParsableModifierInterface) {
1✔
105
                throw new InvalidArgumentException(sprintf(
1✔
106
                    'An invalid path "%s" passed, the modifier "%s" can not have a value.',
1✔
107
                    $value,
108
                    $modifierObject->getAlias(),
1✔
109
                ));
110
            }
111

112
            $parameters[$modifierObject->getAlias()] = 2 === $count ? $modifier[1] : true;
1✔
113
        }
114

115
        return $parameters;
1✔
116
    }
117

118
    public function expandModifiers(array|string $value): array
119
    {
NEW
120
        if (!is_array($value)) {
×
NEW
121
            throw new InvalidArgumentException(
×
NEW
122
                message: 'Can not expand value of type string, the value must be array<string, string|numeric|bool>.',
×
123
            );
124
        }
125

NEW
126
        return $value;
×
127
    }
128
}
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