mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 15:51:48 +03:00
Add missing null check to ControllerReflector::getReflectionMethod (#1918)
* add null check https://github.com/nelmio/NelmioApiDocBundle/issues/1909 * less code is better * add tests for ControllerReflection::getReflectionMethod() * lint fix * style_ci fixes Co-authored-by: Alexey <alshenestky@icloud.com>
This commit is contained in:
parent
babf788636
commit
7de49bb4a8
29
Tests/Util/ControllerReflectorTest.php
Normal file
29
Tests/Util/ControllerReflectorTest.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Nelmio\ApiDocBundle\Tests\Util;
|
||||
|
||||
use Nelmio\ApiDocBundle\Tests\Functional\Controller\BazingaController;
|
||||
use Nelmio\ApiDocBundle\Util\ControllerReflector;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use ReflectionMethod;
|
||||
use Symfony\Component\DependencyInjection\Container;
|
||||
|
||||
class ControllerReflectorTest extends TestCase
|
||||
{
|
||||
public function testGetReflectionMethod(): void
|
||||
{
|
||||
$controllerReflector = new ControllerReflector(new Container());
|
||||
$this->assertEquals(
|
||||
ReflectionMethod::class,
|
||||
get_class($controllerReflector->getReflectionMethod([BazingaController::class, 'userAction']))
|
||||
);
|
||||
$this->assertEquals(
|
||||
ReflectionMethod::class,
|
||||
get_class($controllerReflector->getReflectionMethod(BazingaController::class.'::userAction'))
|
||||
);
|
||||
$this->assertNull(
|
||||
$controllerReflector->getReflectionMethod('UnknownController::userAction')
|
||||
);
|
||||
$this->assertNull($controllerReflector->getReflectionMethod(null));
|
||||
}
|
||||
}
|
@ -38,15 +38,16 @@ class ControllerReflector
|
||||
/**
|
||||
* Returns the ReflectionMethod for the given controller string.
|
||||
*
|
||||
* @return \ReflectionMethod|null
|
||||
* @return \ReflectionMethod|null
|
||||
*/
|
||||
public function getReflectionMethod($controller)
|
||||
{
|
||||
if (is_string($controller)) {
|
||||
$controller = $this->getClassAndMethod($controller);
|
||||
if (null === $controller) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (null === $controller) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->geReflectionMethodByClassNameAndMethodName(...$controller);
|
||||
@ -122,7 +123,7 @@ class ControllerReflector
|
||||
if (!isset($class) || !isset($method)) {
|
||||
$this->controllers[$controller] = null;
|
||||
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->controllers[$controller] = [$class, $method];
|
||||
|
Loading…
x
Reference in New Issue
Block a user