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

Commit edfa86f

Browse files
committed
Use ::class keyword when possible
1 parent 462dbe3 commit edfa86f

8 files changed

+26
-26
lines changed

DebugClassLoader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ public function getClassLoader()
9090
public static function enable()
9191
{
9292
// Ensures we don't hit https://bugs.php.net/42098
93-
class_exists('Symfony\Component\Debug\ErrorHandler');
94-
class_exists('Psr\Log\LogLevel');
93+
class_exists(\Symfony\Component\Debug\ErrorHandler::class);
94+
class_exists(\Psr\Log\LogLevel::class);
9595

9696
if (!\is_array($functions = spl_autoload_functions())) {
9797
return;

ErrorHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public function __construct(BufferingLogger $bootstrappingLogger = null)
169169
$this->bootstrappingLogger = $bootstrappingLogger;
170170
$this->setDefaultLogger($bootstrappingLogger);
171171
}
172-
$this->traceReflector = new \ReflectionProperty('Exception', 'trace');
172+
$this->traceReflector = new \ReflectionProperty(\Exception::class, 'trace');
173173
$this->traceReflector->setAccessible(true);
174174
}
175175

Exception/FatalErrorException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function __construct(string $message, int $code, int $severity, string $f
7474

7575
protected function setTrace($trace)
7676
{
77-
$traceReflector = new \ReflectionProperty('Exception', 'trace');
77+
$traceReflector = new \ReflectionProperty(\Exception::class, 'trace');
7878
$traceReflector->setAccessible(true);
7979
$traceReflector->setValue($this, $trace);
8080
}

Tests/DebugClassLoaderTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function testIdempotence()
5454
$reflProp = $reflClass->getProperty('classLoader');
5555
$reflProp->setAccessible(true);
5656

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

5959
return;
6060
}
@@ -65,7 +65,7 @@ public function testIdempotence()
6565

6666
public function testThrowingClass()
6767
{
68-
$this->expectException('Exception');
68+
$this->expectException(\Exception::class);
6969
$this->expectExceptionMessage('boo');
7070
try {
7171
class_exists(Fixtures\Throwing::class);
@@ -80,14 +80,14 @@ class_exists(Fixtures\Throwing::class);
8080

8181
public function testNameCaseMismatch()
8282
{
83-
$this->expectException('RuntimeException');
83+
$this->expectException(\RuntimeException::class);
8484
$this->expectExceptionMessage('Case mismatch between loaded and declared class names');
8585
class_exists(TestingCaseMismatch::class, true);
8686
}
8787

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

9999
public function testPsr4CaseMismatch()
100100
{
101-
$this->expectException('RuntimeException');
101+
$this->expectException(\RuntimeException::class);
102102
$this->expectExceptionMessage('Case mismatch between loaded and declared class names');
103103
class_exists(__NAMESPACE__.'\Fixtures\Psr4CaseMismatch', true);
104104
}
@@ -179,7 +179,7 @@ public function testDeprecatedSuperInSameNamespace()
179179
$e = error_reporting(0);
180180
trigger_error('', E_USER_NOTICE);
181181

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

184184
error_reporting($e);
185185
restore_error_handler();

Tests/ErrorHandlerTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function testRegister()
3535
$handler = ErrorHandler::register();
3636

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

4141
$newHandler = new ErrorHandler();
@@ -72,7 +72,7 @@ public function testRegister()
7272

7373
public function testErrorGetLast()
7474
{
75-
$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
75+
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
7676
$handler = ErrorHandler::register();
7777
$handler->setDefaultLogger($logger);
7878
$handler->screamAt(\E_ALL);
@@ -150,7 +150,7 @@ public function testConstruct()
150150
public function testDefaultLogger()
151151
{
152152
try {
153-
$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
153+
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
154154
$handler = ErrorHandler::register();
155155

156156
$handler->setDefaultLogger($logger, \E_NOTICE);
@@ -225,7 +225,7 @@ public function testHandleError()
225225
restore_error_handler();
226226
restore_exception_handler();
227227

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

230230
$warnArgCheck = function ($logLevel, $message, $context) {
231231
$this->assertEquals('info', $logLevel);
@@ -250,7 +250,7 @@ public function testHandleError()
250250
restore_error_handler();
251251
restore_exception_handler();
252252

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

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

358-
$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
358+
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
359359
$logger
360360
->expects($this->once())
361361
->method('log')
@@ -370,7 +370,7 @@ public function testHandleDeprecation()
370370
public function testHandleException()
371371
{
372372
try {
373-
$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
373+
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
374374
$handler = ErrorHandler::register();
375375

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

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

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

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

468-
$mockLogger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
468+
$mockLogger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
469469
$mockLogger->expects($this->once())
470470
->method('log')
471471
->with(LogLevel::CRITICAL, 'Uncaught Exception: Foo message', ['exception' => $exception]);
@@ -480,7 +480,7 @@ public function testSettingLoggerWhenExceptionIsBuffered()
480480
public function testHandleFatalError()
481481
{
482482
try {
483-
$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
483+
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
484484
$handler = ErrorHandler::register();
485485

486486
$error = [
@@ -527,13 +527,13 @@ public function testHandleErrorException()
527527

528528
$handler->handleException($exception);
529529

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

534534
public function testCustomExceptionHandler()
535535
{
536-
$this->expectException('Exception');
536+
$this->expectException(\Exception::class);
537537
$handler = new ErrorHandler();
538538
$handler->setExceptionHandler(function ($e) use ($handler) {
539539
$handler->handleException($e);

Tests/FatalErrorHandler/ClassNotFoundFatalErrorHandlerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function testHandleClassNotFound($error, $translatedMessage, $autoloader
6767
array_map('spl_autoload_register', $autoloaders);
6868
}
6969

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

221-
$this->assertInstanceOf('Symfony\Component\Debug\Exception\ClassNotFoundException', $exception);
221+
$this->assertInstanceOf(\Symfony\Component\Debug\Exception\ClassNotFoundException::class, $exception);
222222
}
223223
}

Tests/FatalErrorHandler/UndefinedFunctionFatalErrorHandlerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function testUndefinedFunction($error, $translatedMessage)
2828
$handler = new UndefinedFunctionFatalErrorHandler();
2929
$exception = $handler->handleError($error, new FatalErrorException('', 0, $error['type'], $error['file'], $error['line']));
3030

31-
$this->assertInstanceOf('Symfony\Component\Debug\Exception\UndefinedFunctionException', $exception);
31+
$this->assertInstanceOf(\Symfony\Component\Debug\Exception\UndefinedFunctionException::class, $exception);
3232
// class names are case insensitive and PHP do not return the same
3333
$this->assertSame(strtolower($translatedMessage), strtolower($exception->getMessage()));
3434
$this->assertSame($error['type'], $exception->getSeverity());

Tests/FatalErrorHandler/UndefinedMethodFatalErrorHandlerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function testUndefinedMethod($error, $translatedMessage)
2828
$handler = new UndefinedMethodFatalErrorHandler();
2929
$exception = $handler->handleError($error, new FatalErrorException('', 0, $error['type'], $error['file'], $error['line']));
3030

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

0 commit comments

Comments
 (0)