Skip to content
This repository has been archived by the owner on Dec 9, 2023. It is now read-only.

Commit

Permalink
Use ::class keyword when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Jan 11, 2021
1 parent 462dbe3 commit edfa86f
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions DebugClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ public function getClassLoader()
public static function enable()
{
// Ensures we don't hit https://bugs.php.net/42098
class_exists('Symfony\Component\Debug\ErrorHandler');
class_exists('Psr\Log\LogLevel');
class_exists(\Symfony\Component\Debug\ErrorHandler::class);
class_exists(\Psr\Log\LogLevel::class);

if (!\is_array($functions = spl_autoload_functions())) {
return;
Expand Down
2 changes: 1 addition & 1 deletion ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function __construct(BufferingLogger $bootstrappingLogger = null)
$this->bootstrappingLogger = $bootstrappingLogger;
$this->setDefaultLogger($bootstrappingLogger);
}
$this->traceReflector = new \ReflectionProperty('Exception', 'trace');
$this->traceReflector = new \ReflectionProperty(\Exception::class, 'trace');
$this->traceReflector->setAccessible(true);
}

Expand Down
2 changes: 1 addition & 1 deletion Exception/FatalErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function __construct(string $message, int $code, int $severity, string $f

protected function setTrace($trace)
{
$traceReflector = new \ReflectionProperty('Exception', 'trace');
$traceReflector = new \ReflectionProperty(\Exception::class, 'trace');
$traceReflector->setAccessible(true);
$traceReflector->setValue($this, $trace);
}
Expand Down
12 changes: 6 additions & 6 deletions Tests/DebugClassLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function testIdempotence()
$reflProp = $reflClass->getProperty('classLoader');
$reflProp->setAccessible(true);

$this->assertNotInstanceOf('Symfony\Component\Debug\DebugClassLoader', $reflProp->getValue($function[0]));
$this->assertNotInstanceOf(DebugClassLoader::class, $reflProp->getValue($function[0]));

return;
}
Expand All @@ -65,7 +65,7 @@ public function testIdempotence()

public function testThrowingClass()
{
$this->expectException('Exception');
$this->expectException(\Exception::class);
$this->expectExceptionMessage('boo');
try {
class_exists(Fixtures\Throwing::class);
Expand All @@ -80,14 +80,14 @@ class_exists(Fixtures\Throwing::class);

public function testNameCaseMismatch()
{
$this->expectException('RuntimeException');
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Case mismatch between loaded and declared class names');
class_exists(TestingCaseMismatch::class, true);
}

public function testFileCaseMismatch()
{
$this->expectException('RuntimeException');
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Case mismatch between class and real file names');
if (!file_exists(__DIR__.'/Fixtures/CaseMismatch.php')) {
$this->markTestSkipped('Can only be run on case insensitive filesystems');
Expand All @@ -98,7 +98,7 @@ class_exists(Fixtures\CaseMismatch::class, true);

public function testPsr4CaseMismatch()
{
$this->expectException('RuntimeException');
$this->expectException(\RuntimeException::class);
$this->expectExceptionMessage('Case mismatch between loaded and declared class names');
class_exists(__NAMESPACE__.'\Fixtures\Psr4CaseMismatch', true);
}
Expand Down Expand Up @@ -179,7 +179,7 @@ public function testDeprecatedSuperInSameNamespace()
$e = error_reporting(0);
trigger_error('', E_USER_NOTICE);

class_exists('Symfony\Bridge\Debug\Tests\Fixtures\ExtendsDeprecatedParent', true);
class_exists(\Symfony\Bridge\Debug\Tests\Fixtures\ExtendsDeprecatedParent::class, true);

error_reporting($e);
restore_error_handler();
Expand Down
24 changes: 12 additions & 12 deletions Tests/ErrorHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function testRegister()
$handler = ErrorHandler::register();

try {
$this->assertInstanceOf('Symfony\Component\Debug\ErrorHandler', $handler);
$this->assertInstanceOf(ErrorHandler::class, $handler);
$this->assertSame($handler, ErrorHandler::register());

$newHandler = new ErrorHandler();
Expand Down Expand Up @@ -72,7 +72,7 @@ public function testRegister()

public function testErrorGetLast()
{
$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
$handler = ErrorHandler::register();
$handler->setDefaultLogger($logger);
$handler->screamAt(\E_ALL);
Expand Down Expand Up @@ -150,7 +150,7 @@ public function testConstruct()
public function testDefaultLogger()
{
try {
$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
$handler = ErrorHandler::register();

$handler->setDefaultLogger($logger, \E_NOTICE);
Expand Down Expand Up @@ -225,7 +225,7 @@ public function testHandleError()
restore_error_handler();
restore_exception_handler();

$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();

$warnArgCheck = function ($logLevel, $message, $context) {
$this->assertEquals('info', $logLevel);
Expand All @@ -250,7 +250,7 @@ public function testHandleError()
restore_error_handler();
restore_exception_handler();

$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();

$line = null;
$logArgCheck = function ($level, $message, $context) use (&$line) {
Expand Down Expand Up @@ -355,7 +355,7 @@ public function testHandleDeprecation()
$this->assertSame('User Deprecated: Foo deprecation', $exception->getMessage());
};

$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
$logger
->expects($this->once())
->method('log')
Expand All @@ -370,7 +370,7 @@ public function testHandleDeprecation()
public function testHandleException()
{
try {
$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
$handler = ErrorHandler::register();

$exception = new \Exception('foo');
Expand Down Expand Up @@ -450,7 +450,7 @@ public function testBootstrappingLogger()

$bootLogger->log(LogLevel::WARNING, 'Foo message', ['exception' => $exception]);

$mockLogger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
$mockLogger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
$mockLogger->expects($this->once())
->method('log')
->with(LogLevel::WARNING, 'Foo message', ['exception' => $exception]);
Expand All @@ -465,7 +465,7 @@ public function testSettingLoggerWhenExceptionIsBuffered()

$exception = new \Exception('Foo message');

$mockLogger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
$mockLogger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
$mockLogger->expects($this->once())
->method('log')
->with(LogLevel::CRITICAL, 'Uncaught Exception: Foo message', ['exception' => $exception]);
Expand All @@ -480,7 +480,7 @@ public function testSettingLoggerWhenExceptionIsBuffered()
public function testHandleFatalError()
{
try {
$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
$handler = ErrorHandler::register();

$error = [
Expand Down Expand Up @@ -527,13 +527,13 @@ public function testHandleErrorException()

$handler->handleException($exception);

$this->assertInstanceOf('Symfony\Component\Debug\Exception\ClassNotFoundException', $args[0]);
$this->assertInstanceOf(\Symfony\Component\Debug\Exception\ClassNotFoundException::class, $args[0]);
$this->assertStringStartsWith("Attempted to load class \"IReallyReallyDoNotExistAnywhereInTheRepositoryISwear\" from the global namespace.\nDid you forget a \"use\" statement", $args[0]->getMessage());
}

public function testCustomExceptionHandler()
{
$this->expectException('Exception');
$this->expectException(\Exception::class);
$handler = new ErrorHandler();
$handler->setExceptionHandler(function ($e) use ($handler) {
$handler->handleException($e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function testHandleClassNotFound($error, $translatedMessage, $autoloader
array_map('spl_autoload_register', $autoloaders);
}

$this->assertInstanceOf('Symfony\Component\Debug\Exception\ClassNotFoundException', $exception);
$this->assertInstanceOf(\Symfony\Component\Debug\Exception\ClassNotFoundException::class, $exception);
$this->assertMatchesRegularExpression($translatedMessage, $exception->getMessage());
$this->assertSame($error['type'], $exception->getSeverity());
$this->assertSame($error['file'], $exception->getFile());
Expand Down Expand Up @@ -218,6 +218,6 @@ public function testCannotRedeclareClass()
$handler = new ClassNotFoundFatalErrorHandler();
$exception = $handler->handleError($error, new FatalErrorException('', 0, $error['type'], $error['file'], $error['line']));

$this->assertInstanceOf('Symfony\Component\Debug\Exception\ClassNotFoundException', $exception);
$this->assertInstanceOf(\Symfony\Component\Debug\Exception\ClassNotFoundException::class, $exception);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testUndefinedFunction($error, $translatedMessage)
$handler = new UndefinedFunctionFatalErrorHandler();
$exception = $handler->handleError($error, new FatalErrorException('', 0, $error['type'], $error['file'], $error['line']));

$this->assertInstanceOf('Symfony\Component\Debug\Exception\UndefinedFunctionException', $exception);
$this->assertInstanceOf(\Symfony\Component\Debug\Exception\UndefinedFunctionException::class, $exception);
// class names are case insensitive and PHP do not return the same
$this->assertSame(strtolower($translatedMessage), strtolower($exception->getMessage()));
$this->assertSame($error['type'], $exception->getSeverity());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testUndefinedMethod($error, $translatedMessage)
$handler = new UndefinedMethodFatalErrorHandler();
$exception = $handler->handleError($error, new FatalErrorException('', 0, $error['type'], $error['file'], $error['line']));

$this->assertInstanceOf('Symfony\Component\Debug\Exception\UndefinedMethodException', $exception);
$this->assertInstanceOf(\Symfony\Component\Debug\Exception\UndefinedMethodException::class, $exception);
$this->assertSame($translatedMessage, $exception->getMessage());
$this->assertSame($error['type'], $exception->getSeverity());
$this->assertSame($error['file'], $exception->getFile());
Expand Down

0 comments on commit edfa86f

Please sign in to comment.