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

Articus / DataTransfer / 9052205688

12 May 2024 02:47PM UTC coverage: 82.23% (-1.4%) from 83.617%
9052205688

push

github

Articus
- new configurable strategy and validator to deal with serialized values

24 of 51 new or added lines in 2 files covered. (47.06%)

1106 of 1345 relevant lines covered (82.23%)

8.08 hits per line

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

72.73
/src/Articus/DataTransfer/Validator/SerializableValue.php
1
<?php
2
declare(strict_types=1);
3

4
namespace Articus\DataTransfer\Validator;
5

6
use function is_string;
7

8
/**
9
 * Configurable validator that checks if data is a valid serialized value.
10
 */
11
class SerializableValue implements ValidatorInterface
12
{
13
        public const INVALID = 'serializedValueInvalid';
14
        public const INVALID_INNER = 'serializedValueInvalidInner';
15

16
        /**
17
         * Internal validator for unserialized values
18
         */
19
        protected ValidatorInterface $valueValidator;
20

21
        /**
22
         * A way to decode value from string
23
         * @var callable(string): mixed
24
         */
25
        protected $unserializer;
26

27
        /**
28
         * @param ValidatorInterface $valueValidator
29
         * @param callable $unserializer
30
         */
31
        public function __construct(ValidatorInterface $valueValidator, callable $unserializer)
32
        {
33
                $this->valueValidator = $valueValidator;
2✔
34
                $this->unserializer = $unserializer;
2✔
35
        }
36

37
        /**
38
         * @inheritDoc
39
         */
40
        public function validate($data): array
41
        {
42
                $result = [];
2✔
NEW
43
                if ($data !== null)
×
44
                {
NEW
45
                        if (is_string($data))
×
46
                        {
47
                                $value = ($this->unserializer)($data);
2✔
48
                                $valueViolations = $this->valueValidator->validate($value);
2✔
NEW
49
                                if (!empty($valueViolations))
×
50
                                {
51
                                        $result[self::INVALID_INNER] = $valueViolations;
2✔
52
                                }
53
                        }
54
                        else
55
                        {
56
                                $result[self::INVALID] = 'Invalid data: expecting string.';
2✔
57
                        }
58
                }
59
                return $result;
2✔
60
        }
61
}
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

© 2025 Coveralls, Inc