8000 minor #20169 Minor fixes & cleanups (nicolas-grekas) · symfony/symfony@962248d · GitHub
[go: up one dir, main page]

Skip to content

Commit 962248d

Browse files
minor #20169 Minor fixes & cleanups (nicolas-grekas)
This PR was merged into the 2.7 branch. Discussion ---------- Minor fixes & cleanups | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Commits ------- dcf601f Minor fixes & cleanups
2 parents a5a91a7 + dcf601f commit 962248d

File tree

2 files changed

+9
-17
lines changed

2 files changed

+9
-17
lines changed

src/Symfony/Component/HttpFoundation/Tests/JsonResponseTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,10 @@ public function testSetContentJsonSerializeError()
216216

217217
public function testSetComplexCallback()
218218
{
219-
$response = JsonResponse::fromJsonString('{foo: "bar"}');
219+
$response = JsonResponse::create(array('foo' => 'bar'));
220220
$response->setCallback('ಠ_ಠ["foo"].bar[0]');
221221

222-
$this->assertEquals('/**/ಠ_ಠ["foo"].bar[0]({foo: "bar"});', $response->getContent());
222+
$this->assertEquals('/**/ಠ_ಠ["foo"].bar[0]({"foo":"bar"});', $response->getContent());
223223
}
224224
}
225225

src/Symfony/Component/VarDumper/Caster/ReflectionCaster.php

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ public static function castFunctionAbstract(\ReflectionFunctionAbstract $c, arra
116116

117117
if (isset($a[$prefix.'returnType'])) {
118118
$v = $a[$prefix.'returnType'];
119-
$a[$prefix.'returnType'] = $v instanceof \ReflectionNamedType ? $v->getName() : $v->__toString();
119+
$v = $v instanceof \ReflectionNamedType ? $v->getName() : $v->__toString();
120+
$a[$prefix.'returnType'] = $a[$prefix.'returnType']->allowsNull() ? '?'.$v : $v;
120121
}
121122
if (isset($a[$prefix.'this'])) {
122123
$a[$prefix.'this'] = new CutStub($a[$prefix.'this']);
@@ -168,21 +169,12 @@ public static function castParameter(\ReflectionParameter $c, array $a, Stub $st
168169
'allowsNull' => 'allowsNull',
169170
));
170171

171-
try {
172-
if (method_exists($c, 'getType')) {
173-
if ($v = $c->getType()) {
174-
$a[$prefix.'typeHint'] = $v instanceof \ReflectionNamedType ? $v->getName() : $v->__toString();
175-
}
176-
} else {
177-
$v = explode(' ', $c->__toString(), 6);
178-
if (isset($v[5]) && 0 === strspn($v[4], '.&$')) {
179-
$a[$prefix.'typeHint'] = $v[4];
180-
}
181-
}
182-
} catch (\ReflectionException $e) {
183-
if (preg_match('/^Class ([^ ]++) does not exist$/', $e->getMessage(), $m)) {
184-
$a[$prefix.'typeHint'] = $m[1];
172+
if (method_exists($c, 'getType')) {
173+
if ($v = $c->getType()) {
174+
$a[$prefix.'typeHint'] = $v instanceof \ReflectionNamedType ? $v->getName() : $v->__toString();
185175
}
176+
} elseif (preg_match('/^(?:[^ ]++ ){4}([a-zA-Z_\x7F-\xFF][^ ]++)/', $c, $v)) {
177+
$a[$prefix.'typeHint'] = $v[1];
186178
}
187179
if (!isset($a[$prefix.'typeHint'])) {
188180
unset($a[$prefix.'allowsNull']);

0 commit comments

Comments
 (0)
0