Code Duplication    Length = 20-27 lines in 2 locations

src/UI/Resolver/Validator/PragmaticRawValueValidator.php 2 locations

@@ 29-55 (lines=27) @@
26
     *
27
     * @return mixed Untouched value
28
     */
29
    public function mustBeStringNotEmpty($value, string $propertyPath = null, UIValidatorInterface $parentValidator = null, string $exceptionMessage = null)
30
    {
31
        $this->validationEngine->validateFieldValue(
32
            $parentValidator ?: $this,
33
            function() use ($value, $propertyPath, $exceptionMessage) {
34
                if (!empty($value)) {
35
                    return;
36
                }
37
38
                if (null === $exceptionMessage) {
39
                    $exceptionMessage = sprintf(
40
                        'Value "%s" is empty.',
41
                        $value
42
                    );
43
                }
44
45
                throw new InvalidArgumentException(
46
                    $exceptionMessage,
47
                    0,
48
                    $propertyPath,
49
                    $value
50
                );
51
            }
52
        );
53
54
        return $value;
55
    }
56
57
    /**
58
     * Domain should be responsible for email format
@@ 101-120 (lines=20) @@
98
     *
99
     * @return mixed Untouched value
100
     */
101
    public function mustBeValidAgainstRegex($value, string $pattern, string $propertyPath = null, UIValidatorInterface $parentValidator = null, string $exceptionMessage = null)
102
    {
103
        $this->validationEngine->validateFieldValue(
104
            $parentValidator ?: $this,
105
            function() use ($value, $pattern, $propertyPath, $exceptionMessage) {
106
                if (preg_match($pattern, $value)) {
107
                    return;
108
                }
109
110
                throw new InvalidArgumentException(
111
                    $exceptionMessage ?: sprintf('Value "%s" not valid against regex "%s".', $value, $pattern),
112
                    0,
113
                    $propertyPath,
114
                    $value
115
                );
116
            }
117
        );
118
119
        return $value;
120
    }
121
}
122