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
This commit is contained in:
Nicolas Grekas 2016-10-06 10:55:03 +02:00
commit 962248dbd9
2 changed files with 9 additions and 17 deletions

View File

@ -216,10 +216,10 @@ class JsonResponseTest extends \PHPUnit_Framework_TestCase
public function testSetComplexCallback()
{
$response = JsonResponse::fromJsonString('{foo: "bar"}');
$response = JsonResponse::create(array('foo' => 'bar'));
$response->setCallback('ಠ_ಠ["foo"].bar[0]');
$this->assertEquals('/**/ಠ_ಠ["foo"].bar[0]({foo: "bar"});', $response->getContent());
$this->assertEquals('/**/ಠ_ಠ["foo"].bar[0]({"foo":"bar"});', $response->getContent());
}
}

View File

@ -116,7 +116,8 @@ class ReflectionCaster
if (isset($a[$prefix.'returnType'])) {
$v = $a[$prefix.'returnType'];
$a[$prefix.'returnType'] = $v instanceof \ReflectionNamedType ? $v->getName() : $v->__toString();
$v = $v instanceof \ReflectionNamedType ? $v->getName() : $v->__toString();
$a[$prefix.'returnType'] = $a[$prefix.'returnType']->allowsNull() ? '?'.$v : $v;
}
if (isset($a[$prefix.'this'])) {
$a[$prefix.'this'] = new CutStub($a[$prefix.'this']);
@ -168,21 +169,12 @@ class ReflectionCaster
'allowsNull' => 'allowsNull',
));
try {
if (method_exists($c, 'getType')) {
if ($v = $c->getType()) {
$a[$prefix.'typeHint'] = $v instanceof \ReflectionNamedType ? $v->getName() : $v->__toString();
}
} else {
$v = explode(' ', $c->__toString(), 6);
if (isset($v[5]) && 0 === strspn($v[4], '.&$')) {
$a[$prefix.'typeHint'] = $v[4];
}
}
} catch (\ReflectionException $e) {
if (preg_match('/^Class ([^ ]++) does not exist$/', $e->getMessage(), $m)) {
$a[$prefix.'typeHint'] = $m[1];
if (method_exists($c, 'getType')) {
if ($v = $c->getType()) {
$a[$prefix.'typeHint'] = $v instanceof \ReflectionNamedType ? $v->getName() : $v->__toString();
}
} elseif (preg_match('/^(?:[^ ]++ ){4}([a-zA-Z_\x7F-\xFF][^ ]++)/', $c, $v)) {
$a[$prefix.'typeHint'] = $v[1];
}
if (!isset($a[$prefix.'typeHint'])) {
unset($a[$prefix.'allowsNull']);