You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Add aspect ratio support to `Image` rule
* Apply fixes from StyleCI
* Code coverage, mutants
* Add detailed test cases' descriptions in data providers
* Change placeholders
* Work with options
* Work with options 2
* More configuration checks
* Fix logic, add PHPDoc
* Use value object for aspect ratio
* Actualize fix for mutant for absolute margin
* Fix error messages
* Fix new mutants
* Update src/Rule/Image/ImageAspectRatio.php
Co-authored-by: Sergei Predvoditelev <sergei@predvoditelev.ru>
* Do not use dedicated container in tests, fix last mutant
---------
Co-authored-by: StyleCI Bot <bot@styleci.io>
Co-authored-by: Sergei Predvoditelev <sergei@predvoditelev.ru>
* @param int|null $maxWidth Expected maximum width of validated image file.
38
39
* @param int|null $maxHeight Expected maximum height of validated image file.
40
+
* @param ImageAspectRatio|null $aspectRatio Expected aspect ratio of validated image file.
39
41
* @param string $notImageMessage A message used when the validated value is not valid image file.
40
42
*
41
43
* You may use the following placeholders in the message:
@@ -89,6 +91,20 @@ final class Image implements RuleWithOptionsInterface, SkipOnErrorInterface, Whe
89
91
*
90
92
* - `{attribute}`: the translated label of the attribute being validated.
91
93
* - `{limit}`: expected maximum height of validated image file.
94
+
*
95
+
* @param string $invalidAspectRatioMessage A message used when aspect ratio of validated image file is different
96
+
* than {@see ImageAspectRatio::$width}:{@see ImageAspectRatio::$height} with correction based on
97
+
* {@see ImageAspectRatio::$margin}.
98
+
*
99
+
* You may use the following placeholders in the message:
100
+
*
101
+
* - `{attribute}`: the translated label of the attribute being validated.
102
+
* - `{aspectRatioWidth}`: expected width part for aspect ratio. For example, for `4:3` aspect ratio, it will be
103
+
* `4`.
104
+
* - `{aspectRatioHeight}`: expected height part for aspect ratio. For example, for `4:3` aspect ratio, it will be
105
+
* `3`.
106
+
* - `{aspectRatioMargin}`: expected margin for aspect ratio in percents.
107
+
*
92
108
* @param bool|callable|null $skipOnEmpty Whether to skip this rule if the value validated is empty.
93
109
* See {@see SkipOnEmptyInterface}.
94
110
* @param bool $skipOnError Whether to skip this rule if any of the previous rules gave an error.
@@ -105,17 +121,26 @@ public function __construct(
105
121
private ?int$minHeight = null,
106
122
private ?int$maxWidth = null,
107
123
private ?int$maxHeight = null,
124
+
private ?ImageAspectRatio$aspectRatio = null,
108
125
privatestring$notImageMessage = 'The value must be an image.',
109
-
privatestring$notExactWidthMessage = 'The width of image "{attribute}" must be exactly {exactly, number} {exactly, plural, one{pixel} other{pixels}}.',
110
-
privatestring$notExactHeightMessage = 'The height of image "{attribute}" must be exactly {exactly, number} {exactly, plural, one{pixel} other{pixels}}.',
111
-
privatestring$tooSmallWidthMessage = 'The width of image "{attribute}" cannot be smaller than {limit, number} {limit, plural, one{pixel} other{pixels}}.',
112
-
privatestring$tooSmallHeightMessage = 'The height of image "{attribute}" cannot be smaller than {limit, number} {limit, plural, one{pixel} other{pixels}}.',
113
-
privatestring$tooLargeWidthMessage = 'The width of image "{attribute}" cannot be larger than {limit, number} {limit, plural, one{pixel} other{pixels}}.',
114
-
privatestring$tooLargeHeightMessage = 'The height of image "{attribute}" cannot be larger than {limit, number} {limit, plural, one{pixel} other{pixels}}.',
126
+
privatestring$notExactWidthMessage = 'The width must be exactly {exactly, number} {exactly, plural, one{pixel} other{pixels}}.',
127
+
privatestring$notExactHeightMessage = 'The height must be exactly {exactly, number} {exactly, plural, one{pixel} other{pixels}}.',
128
+
privatestring$tooSmallWidthMessage = 'The width cannot be smaller than {limit, number} {limit, plural, one{pixel} other{pixels}}.',
129
+
privatestring$tooSmallHeightMessage = 'The height cannot be smaller than {limit, number} {limit, plural, one{pixel} other{pixels}}.',
130
+
privatestring$tooLargeWidthMessage = 'The width cannot be larger than {limit, number} {limit, plural, one{pixel} other{pixels}}.',
131
+
privatestring$tooLargeHeightMessage = 'The height cannot be larger than {limit, number} {limit, plural, one{pixel} other{pixels}}.',
132
+
privatestring$invalidAspectRatioMessage = 'The aspect ratio must be {aspectRatioWidth, number}:{aspectRatioHeight, number} with margin {aspectRatioMargin, number}%.',
0 commit comments