Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5a5236e

Browse files
committed
Improve formating options
1 parent 850942b commit 5a5236e

File tree

2 files changed

+75
-26
lines changed

2 files changed

+75
-26
lines changed

src/Symfony/Component/Validator/Command/DebugCommand.php

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,14 @@ private function dumpValidatorsForClass(InputInterface $input, OutputInterface $
8787

8888
foreach ($this->getConstrainedPropertiesData($class) as $propertyName => $constraintsData) {
8989
foreach ($constraintsData as $data) {
90-
$rows[] = [$propertyName, $data['class'], implode(', ', $data['groups']), json_encode($data['options'])];
90+
$options = $this->formatOptions($data['options']);
91+
92+
$rows[] = [
93+
$propertyName,
94+
$data['class'],
95+
implode(', ', $data['groups']),
96+
implode("\n", $options),
97+
];
9198
}
9299
}
93100

@@ -194,4 +201,35 @@ private function getResourcesByPath(string $path): array
194201

195202
return $classes;
196203
}
204+
205+
private function formatOptions(array $options): array
206+
{
207+
array_walk($options, function (&$optionValue, $key) {
208+
$optionValue = $this->formatOptionValue($optionValue);
209+
$optionValue = sprintf('%s: %s', $key, $optionValue);
210+
});
211+
212+
return $options;
213+
}
214+
215+
private function formatOptionValue($value): string
216+
{
217+
if (null == $value) {
218+
return 'null';
219+
}
220+
221+
if (\is_bool($value)) {
222+
return $value ? 'true' : 'false';
223+
}
224+
225+
if (\is_array($value)) {
226+
return implode(', ', $value);
227+
}
228+
229+
if (\is_int($value)) {
230+
return (string) $value;
231+
}
232+
233+
return $value;
234+
}
197235
}

src/Symfony/Component/Validator/Tests/Command/DebugCommandTest.php

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,18 @@ public function testOutputWithClassArgument(): void
6868
Validation information for class "Symfony\Component\Validator\Tests\Dummy\DummyClassOne"
6969
========================================================================================
7070
71-
+---------------+--------------------------------------------------+---------+----------------------------------------------------------------------------------+
72-
| Property | Name | Groups | Options |
73-
+---------------+--------------------------------------------------+---------+----------------------------------------------------------------------------------+
74-
| firstArgument | Symfony\Component\Validator\Constraints\NotBlank | Default | {"message":"This value should not be blank.","allowNull":false,"normalizer":null |
75-
| | | | ,"payload":null} |
76-
| firstArgument | Symfony\Component\Validator\Constraints\Email | Default | {"message":"This value is not a valid email address.","mode":null,"normalizer":n |
77-
| | | | ull,"payload":null} |
78-
+---------------+--------------------------------------------------+---------+----------------------------------------------------------------------------------+
71+
+---------------+--------------------------------------------------+---------+---------------------------------------------------+
72+
| Property | Name | Groups | Options |
73+
+---------------+--------------------------------------------------+---------+---------------------------------------------------+
74+
| firstArgument | Symfony\Component\Validator\Constraints\NotBlank | Default | message: This value should not be blank. |
75+
| | | | allowNull: null |
76+
| | | | normalizer: null |
77+
| | | | payload: null |
78+
| firstArgument | Symfony\Component\Validator\Constraints\Email | Default | message: This value is not a valid email address. |
79+
| | | | mode: null |
80+
| | | | normalizer: null |
81+
| | | | payload: null |
82+
+---------------+--------------------------------------------------+---------+---------------------------------------------------+
7983
8084
TXT
8185
, $tester->getDisplay(true)
@@ -86,7 +90,6 @@ public function testOutputWithPathArgument(): void
8690
{
8791
$validator = $this->createMock(ValidatorInterface::class);
8892
$classMetadata = $this->createMock(ClassMetadataInterface::class);
89-
$secondClassMetadata = $this->createMock(ClassMetadataInterface::class);
9093
$propertyMetadata = $this->createMock(PropertyMetadataInterface::class);
9194

9295
$validator
@@ -122,26 +125,34 @@ public function testOutputWithPathArgument(): void
122125
Validation information for class "Symfony\Component\Validator\Tests\Dummy\DummyClassOne"
123126
========================================================================================
124127
125-
+---------------+--------------------------------------------------+---------+----------------------------------------------------------------------------------+
126-
| Property | Name | Groups | Options |
127-
+---------------+--------------------------------------------------+---------+----------------------------------------------------------------------------------+
128-
| firstArgument | Symfony\Component\Validator\Constraints\NotBlank | Default | {"message":"This value should not be blank.","allowNull":false,"normalizer":null |
129-
| | | | ,"payload":null} |
130-
| firstArgument | Symfony\Component\Validator\Constraints\Email | Default | {"message":"This value is not a valid email address.","mode":null,"normalizer":n |
131-
| | | | ull,"payload":null} |
132-
+---------------+--------------------------------------------------+---------+----------------------------------------------------------------------------------+
128+
+---------------+--------------------------------------------------+---------+---------------------------------------------------+
129+
| Property | Name | Groups | Options |
130+
+---------------+--------------------------------------------------+---------+---------------------------------------------------+
131+
| firstArgument | Symfony\Component\Validator\Constraints\NotBlank | Default | message: This value should not be blank. |
132+
| | | | allowNull: null |
133+
| | | | normalizer: null |
134+
| | | | payload: null |
135+
| firstArgument | Symfony\Component\Validator\Constraints\Email | Default | message: This value is not a valid email address. |
136+
| | | | mode: null |
137+
| | | | normalizer: null |
138+
| | | | payload: null |
139+
+---------------+--------------------------------------------------+---------+---------------------------------------------------+
133140
134141
Validation information for class "Symfony\Component\Validator\Tests\Dummy\DummyClassTwo"
135142
========================================================================================
136143
137-
+---------------+--------------------------------------------------+---------+----------------------------------------------------------------------------------+
138-
| Property | Name | Groups | Options |
139-
+---------------+--------------------------------------------------+---------+----------------------------------------------------------------------------------+
140-
| firstArgument | Symfony\Component\Validator\Constraints\NotBlank | Default | {"message":"This value should not be blank.","allowNull":false,"normalizer":null |
141-
| | | | ,"payload":null} |
142-
| firstArgument | Symfony\Component\Validator\Constraints\Email | Default | {"message":"This value is not a valid email address.","mode":null,"normalizer":n |
143-
| | | | ull,"payload":null} |
144-
+---------------+--------------------------------------------------+---------+----------------------------------------------------------------------------------+
144+
+---------------+--------------------------------------------------+---------+---------------------------------------------------+
145+
| Property | Name | Groups | Options |
146+
+---------------+--------------------------------------------------+---------+---------------------------------------------------+
147+
| firstArgument | Symfony\Component\Validator\Constraints\NotBlank | Default | message: This value should not be blank. |
148+
| | | | allowNull: null |
149+
| | | | normalizer: null |
150+
| | | | payload: null |
151+
| firstArgument | Symfony\Component\Validator\Constraints\Email | Default | message: This value is not a valid email address. |
152+
| | | | mode: null |
153+
| | | | normalizer: null |
154+
| | | | payload: null |
155+
+---------------+--------------------------------------------------+---------+---------------------------------------------------+
145156
146157
TXT
147158
, $tester->getDisplay(true)

0 commit comments

Comments
 (0)