Skip to content

Commit 4f373c3

Browse files
committed
patch
2 parents 1b49921 + fd4c42c commit 4f373c3

File tree

4 files changed

+101
-5
lines changed

4 files changed

+101
-5
lines changed

src/Illuminate/Container/Util.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,14 @@ public static function getParameterClassName($parameter)
5555

5656
$name = $type->getName();
5757

58-
if ($name === 'self') {
59-
return $parameter->getDeclaringClass()->getName();
58+
if (! is_null($class = $parameter->getDeclaringClass())) {
59+
if ($name === 'self') {
60+
return $class->getName();
61+
}
62+
63+
if ($name === 'parent' && $parent = $class->getParentClass()) {
64+
return $parent->getName();
65+
}
6066
}
6167

6268
return $name;

src/Illuminate/Foundation/Application.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Application extends Container implements ApplicationContract, CachesConfig
3333
*
3434
* @var string
3535
*/
36-
const VERSION = '7.19.0';
36+
const VERSION = '7.19.1';
3737

3838
/**
3939
* The base path for the Laravel installation.

src/Illuminate/Support/Reflector.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,14 @@ public static function getParameterClassName($parameter)
2323

2424
$name = $type->getName();
2525

26-
if ($name === 'self') {
27-
return $parameter->getDeclaringClass()->getName();
26+
if (! is_null($class = $parameter->getDeclaringClass())) {
27+
if ($name === 'self') {
28+
return $class->getName();
29+
}
30+
31+
if ($name === 'parent' && $parent = $class->getParentClass()) {
32+
return $parent->getName();
33+
}
2834
}
2935

3036
return $name;
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
namespace Illuminate\Tests\Support;
4+
5+
use Illuminate\Contracts\Mail\Mailable;
6+
use Illuminate\Database\Eloquent\Model;
7+
use Illuminate\Support\Reflector;
8+
use Illuminate\Support\Testing\Fakes\BusFake;
9+
use Illuminate\Support\Testing\Fakes\MailFake;
10+
use Illuminate\Support\Testing\Fakes\PendingMailFake;
11+
use PHPUnit\Framework\TestCase;
12+
use ReflectionClass;
13+
14+
class SupportReflectorTest extends TestCase
15+
{
16+
public function testGetClassName()
17+
{
18+
$method = (new ReflectionClass(PendingMailFake::class))->getMethod('send');
19+
20+
$this->assertSame(Mailable::class, Reflector::getParameterClassName($method->getParameters()[0]));
21+
}
22+
23+
public function testEmptyClassName()
24+
{
25+
$method = (new ReflectionClass(MailFake::class))->getMethod('assertSent');
26+
27+
$this->assertNull(Reflector::getParameterClassName($method->getParameters()[0]));
28+
}
29+
30+
public function testStringTypeName()
31+
{
32+
$method = (new ReflectionClass(BusFake::class))->getMethod('dispatchedAfterResponse');
33+
34+
$this->assertNull(Reflector::getParameterClassName($method->getParameters()[0]));
35+
}
36+
37+
public function testSelfClassName()
38+
{
39+
$method = (new ReflectionClass(Model::class))->getMethod('newPivot');
40+
41+
$this->assertSame(Model::class, Reflector::getParameterClassName($method->getParameters()[0]));
42+
}
43+
44+
public function testParentClassName()
45+
{
46+
$method = (new ReflectionClass(B::class))->getMethod('f');
47+
48+
$this->assertSame(A::class, Reflector::getParameterClassName($method->getParameters()[0]));
49+
}
50+
51+
/**
52+
* @requires PHP 8
53+
*/
54+
public function testUnionTypeName()
55+
{
56+
$method = (new ReflectionClass(C::class))->getMethod('f');
57+
58+
$this->assertNull(Reflector::getParameterClassName($method->getParameters()[0]));
59+
}
60+
}
61+
62+
class A
63+
{
64+
}
65+
66+
class B extends A
67+
{
68+
public function f(parent $x)
69+
{
70+
}
71+
}
72+
73+
if (PHP_MAJOR_VERSION >= 8) {
74+
eval('
75+
namespace Illuminate\Tests\Support;
76+
77+
class C
78+
{
79+
public function f(A|Model $x)
80+
{
81+
}
82+
}'
83+
);
84+
}

0 commit comments

Comments
 (0)