Skip to content

Commit 80d5743

Browse files
committed
Use ::class keyword when possible
1 parent 40f14df commit 80d5743

21 files changed

+107
-107
lines changed

Matcher/Dumper/CompiledUrlMatcherDumper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ private function compileRoute(Route $route, string $name, $vars, bool $hasTraili
446446
private function getExpressionLanguage(): ExpressionLanguage
447447
{
448448
if (null === $this->expressionLanguage) {
449-
if (!class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage')) {
449+
if (!class_exists(ExpressionLanguage::class)) {
450450
throw new \LogicException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.');
451451
}
452452
$this->expressionLanguage = new ExpressionLanguage(null, $this->expressionLanguageProviders);

Matcher/UrlMatcher.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ protected function mergeDefaults($params, $defaults)
262262
protected function getExpressionLanguage()
263263
{
264264
if (null === $this->expressionLanguage) {
265-
if (!class_exists('Symfony\Component\ExpressionLanguage\ExpressionLanguage')) {
265+
if (!class_exists(ExpressionLanguage::class)) {
266266
throw new \LogicException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.');
267267
}
268268
$this->expressionLanguage = new ExpressionLanguage(null, $this->expressionLanguageProviders);
@@ -276,7 +276,7 @@ protected function getExpressionLanguage()
276276
*/
277277
protected function createRequest(string $pathinfo): ?Request
278278
{
279-
if (!class_exists('Symfony\Component\HttpFoundation\Request')) {
279+
if (!class_exists(Request::class)) {
280280
return null;
281281
}
282282

Tests/Annotation/RouteTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ class RouteTest extends TestCase
1818
{
1919
public function testInvalidRouteParameter()
2020
{
21-
$this->expectException('BadMethodCallException');
21+
$this->expectException(\BadMethodCallException::class);
2222
new Route(['foo' => 'bar']);
2323
}
2424

2525
public function testTryingToSetLocalesDirectly()
2626
{
27-
$this->expectException('BadMethodCallException');
27+
$this->expectException(\BadMethodCallException::class);
2828
new Route(['locales' => ['nl' => 'bar']]);
2929
}
3030

Tests/Generator/Dumper/CompiledUrlGeneratorDumperTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function testDumpWithSimpleLocalizedRoutes()
118118

119119
public function testDumpWithRouteNotFoundLocalizedRoutes()
120120
{
121-
$this->expectException('Symfony\Component\Routing\Exception\RouteNotFoundException');
121+
$this->expectException(\Symfony\Component\Routing\Exception\RouteNotFoundException::class);
122122
$this->expectExceptionMessage('Unable to generate a URL for the named route "test" as such route does not exist.');
123123
$this->routeCollection->add('test.en', (new Route('/testing/is/fun'))->setDefault('_locale', 'en')->setDefault('_canonical_route', 'test')->setRequirement('_locale', 'en'));
124124

@@ -178,7 +178,7 @@ public function testDumpWithTooManyRoutes()
178178

179179
public function testDumpWithoutRoutes()
180180
{
181-
$this->expectException('InvalidArgumentException');
181+
$this->expectException(\InvalidArgumentException::class);
182182
file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump());
183183

184184
$projectUrlGenerator = new CompiledUrlGenerator(require $this->testTmpFilepath, new RequestContext('/app.php'));
@@ -188,7 +188,7 @@ public function testDumpWithoutRoutes()
188188

189189
public function testGenerateNonExistingRoute()
190190
{
191-
$this->expectException('Symfony\Component\Routing\Exception\RouteNotFoundException');
191+
$this->expectException(\Symfony\Component\Routing\Exception\RouteNotFoundException::class);
192192
$this->routeCollection->add('Test', new Route('/test'));
193193

194194
file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump());

Tests/Generator/Dumper/PhpGeneratorDumperTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function testDumpWithSimpleLocalizedRoutes()
124124

125125
public function testDumpWithRouteNotFoundLocalizedRoutes()
126126
{
127-
$this->expectException('Symfony\Component\Routing\Exception\RouteNotFoundException');
127+
$this->expectException(\Symfony\Component\Routing\Exception\RouteNotFoundException::class);
128128
$this->expectExceptionMessage('Unable to generate a URL for the named route "test" as such route does not exist.');
129129
$this->routeCollection->add('test.en', (new Route('/testing/is/fun'))->setDefault('_locale', 'en')->setDefault('_canonical_route', 'test')->setRequirement('_locale', 'en'));
130130

@@ -193,7 +193,7 @@ public function testDumpWithTooManyRoutes()
193193

194194
public function testDumpWithoutRoutes()
195195
{
196-
$this->expectException('InvalidArgumentException');
196+
$this->expectException(\InvalidArgumentException::class);
197197
file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump(['class' => 'WithoutRoutesUrlGenerator']));
198198
include $this->testTmpFilepath;
199199

@@ -204,7 +204,7 @@ public function testDumpWithoutRoutes()
204204

205205
public function testGenerateNonExistingRoute()
206206
{
207-
$this->expectException('Symfony\Component\Routing\Exception\RouteNotFoundException');
207+
$this->expectException(\Symfony\Component\Routing\Exception\RouteNotFoundException::class);
208208
$this->routeCollection->add('Test', new Route('/test'));
209209

210210
file_put_contents($this->testTmpFilepath, $this->generatorDumper->dump(['class' => 'NonExistingRoutesUrlGenerator']));

Tests/Generator/UrlGeneratorTest.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public function testRelativeUrlWithNullParameter()
7878

7979
public function testRelativeUrlWithNullParameterButNotOptional()
8080
{
81-
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
81+
$this->expectException(\Symfony\Component\Routing\Exception\InvalidParameterException::class);
8282
$routes = $this->getRoutes('test', new Route('/testing/{foo}/bar', ['foo' => null]));
8383
// This must raise an exception because the default requirement for "foo" is "[^/]+" which is not met with these params.
8484
// Generating path "/testing//bar" would be wrong as matching this route would fail.
@@ -264,14 +264,14 @@ public function testDumpWithLocalizedRoutesPreserveTheGoodLocaleInTheUrl()
264264

265265
public function testGenerateWithoutRoutes()
266266
{
267-
$this->expectException('Symfony\Component\Routing\Exception\RouteNotFoundException');
267+
$this->expectException(\Symfony\Component\Routing\Exception\RouteNotFoundException::class);
268268
$routes = $this->getRoutes('foo', new Route('/testing/{foo}'));
269269
$this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL);
270270
}
271271

272272
public function testGenerateWithInvalidLocale()
273273
{
274-
$this->expectException('Symfony\Component\Routing\Exception\RouteNotFoundException');
274+
$this->expectException(\Symfony\Component\Routing\Exception\RouteNotFoundException::class);
275275
$routes = new RouteCollection();
276276

277277
$route = new Route('');
@@ -293,21 +293,21 @@ public function testGenerateWithInvalidLocale()
293293

294294
public function testGenerateForRouteWithoutMandatoryParameter()
295295
{
296-
$this->expectException('Symfony\Component\Routing\Exception\MissingMandatoryParametersException');
296+
$this->expectException(\Symfony\Component\Routing\Exception\MissingMandatoryParametersException::class);
297297
$routes = $this->getRoutes('test', new Route('/testing/{foo}'));
298298
$this->getGenerator($routes)->generate('test', [], UrlGeneratorInterface::ABSOLUTE_URL);
299299
}
300300

301301
public function testGenerateForRouteWithInvalidOptionalParameter()
302302
{
303-
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
303+
$this->expectException(\Symfony\Component\Routing\Exception\InvalidParameterException::class);
304304
$routes = $this->getRoutes('test', new Route('/testing/{foo}', ['foo' => '1'], ['foo' => 'd+']));
305305
$this->getGenerator($routes)->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_URL);
306306
}
307307

308308
public function testGenerateForRouteWithInvalidParameter()
309309
{
310-
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
310+
$this->expectException(\Symfony\Component\Routing\Exception\InvalidParameterException::class);
311311
$routes = $this->getRoutes('test', new Route('/testing/{foo}', [], ['foo' => '1|2']));
312312
$this->getGenerator($routes)->generate('test', ['foo' => '0'], UrlGeneratorInterface::ABSOLUTE_URL);
313313
}
@@ -323,7 +323,7 @@ public function testGenerateForRouteWithInvalidOptionalParameterNonStrict()
323323
public function testGenerateForRouteWithInvalidOptionalParameterNonStrictWithLogger()
324324
{
325325
$routes = $this->getRoutes('test', new Route('/testing/{foo}', ['foo' => '1'], ['foo' => 'd+']));
326-
$logger = $this->getMockBuilder('Psr\Log\LoggerInterface')->getMock();
326+
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
327327
$logger->expects($this->once())
328328
->method('error');
329329
$generator = $this->getGenerator($routes, [], $logger);
@@ -341,21 +341,21 @@ public function testGenerateForRouteWithInvalidParameterButDisabledRequirementsC
341341

342342
public function testGenerateForRouteWithInvalidMandatoryParameter()
343343
{
344-
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
344+
$this->expectException(\Symfony\Component\Routing\Exception\InvalidParameterException::class);
345345
$routes = $this->getRoutes('test', new Route('/testing/{foo}', [], ['foo' => 'd+']));
346346
$this->getGenerator($routes)->generate('test', ['foo' => 'bar'], UrlGeneratorInterface::ABSOLUTE_URL);
347347
}
348348

349349
public function testGenerateForRouteWithInvalidUtf8Parameter()
350350
{
351-
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
351+
$this->expectException(\Symfony\Component\Routing\Exception\InvalidParameterException::class);
352352
$routes = $this->getRoutes('test', new Route('/testing/{foo}', [], ['foo' => '\pL+'], ['utf8' => true]));
353353
$this->getGenerator($routes)->generate('test', ['foo' => 'abc123'], UrlGeneratorInterface::ABSOLUTE_URL);
354354
}
355355

356356
public function testRequiredParamAndEmptyPassed()
357357
{
358-
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
358+
$this->expectException(\Symfony\Component\Routing\Exception\InvalidParameterException::class);
359359
$routes = $this->getRoutes('test', new Route('/{slug}', [], ['slug' => '.+']));
360360
$this->getGenerator($routes)->generate('test', ['slug' => '']);
361361
}
@@ -476,7 +476,7 @@ public function testAdjacentVariables()
476476

477477
// The default requirement for 'x' should not allow the separator '.' in this case because it would otherwise match everything
478478
// and following optional variables like _format could never match.
479-
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
479+
$this->expectException(\Symfony\Component\Routing\Exception\InvalidParameterException::class);
480480
$generator->generate('test', ['x' => 'do.t', 'y' => '123', 'z' => 'bar', '_format' => 'xml']);
481481
}
482482

@@ -517,7 +517,7 @@ public function testImportantVariable()
517517

518518
public function testImportantVariableWithNoDefault()
519519
{
520-
$this->expectException('Symfony\Component\Routing\Exception\MissingMandatoryParametersException');
520+
$this->expectException(\Symfony\Component\Routing\Exception\MissingMandatoryParametersException::class);
521521
$routes = $this->getRoutes('test', new Route('/{page}.{!_format}'));
522522
$generator = $this->getGenerator($routes);
523523

@@ -526,14 +526,14 @@ public function testImportantVariableWithNoDefault()
526526

527527
public function testDefaultRequirementOfVariableDisallowsSlash()
528528
{
529-
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
529+
$this->expectException(\Symfony\Component\Routing\Exception\InvalidParameterException::class);
530530
$routes = $this->getRoutes('test', new Route('/{page}.{_format}'));
531531
$this->getGenerator($routes)->generate('test', ['page' => 'index', '_format' => 'sl/ash']);
532532
}
533533

534534
public function testDefaultRequirementOfVariableDisallowsNextSeparator()
535535
{
536-
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
536+
$this->expectException(\Symfony\Component\Routing\Exception\InvalidParameterException::class);
537537
$routes = $this->getRoutes('test', new Route('/{page}.{_format}'));
538538
$this->getGenerator($routes)->generate('test', ['page' => 'do.t', '_format' => 'html']);
539539
}
@@ -561,21 +561,21 @@ public function testWithHostSameAsContextAndAbsolute()
561561

562562
public function testUrlWithInvalidParameterInHost()
563563
{
564-
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
564+
$this->expectException(\Symfony\Component\Routing\Exception\InvalidParameterException::class);
565565
$routes = $this->getRoutes('test', new Route('/', [], ['foo' => 'bar'], [], '{foo}.example.com'));
566566
$this->getGenerator($routes)->generate('test', ['foo' => 'baz'], UrlGeneratorInterface::ABSOLUTE_PATH);
567567
}
568568

569569
public function testUrlWithInvalidParameterInHostWhenParamHasADefaultValue()
570570
{
571-
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
571+
$this->expectException(\Symfony\Component\Routing\Exception\InvalidParameterException::class);
572572
$routes = $this->getRoutes('test', new Route('/', ['foo' => 'bar'], ['foo' => 'bar'], [], '{foo}.example.com'));
573573
$this->getGenerator($routes)->generate('test', ['foo' => 'baz'], UrlGeneratorInterface::ABSOLUTE_PATH);
574574
}
575575

576576
public function testUrlWithInvalidParameterEqualsDefaultValueInHost()
577577
{
578-
$this->expectException('Symfony\Component\Routing\Exception\InvalidParameterException');
578+
$this->expectException(\Symfony\Component\Routing\Exception\InvalidParameterException::class);
579579
$routes = $this->getRoutes('test', new Route('/', ['foo' => 'baz'], ['foo' => 'bar'], [], '{foo}.example.com'));
580580
$this->getGenerator($routes)->generate('test', ['foo' => 'baz'], UrlGeneratorInterface::ABSOLUTE_PATH);
581581
}

Tests/Loader/AbstractAnnotationLoaderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ abstract class AbstractAnnotationLoaderTest extends TestCase
1717
{
1818
public function getReader()
1919
{
20-
return $this->getMockBuilder('Doctrine\Common\Annotations\Reader')
20+
return $this->getMockBuilder(\Doctrine\Common\Annotations\Reader::class)
2121
->disableOriginalConstructor()
2222
->getMock()
2323
;
2424
}
2525

2626
public function getClassLoader($reader)
2727
{
28-
return $this->getMockBuilder('Symfony\Component\Routing\Loader\AnnotationClassLoader')
28+
return $this->getMockBuilder(\Symfony\Component\Routing\Loader\AnnotationClassLoader::class)
2929
->setConstructorArgs([$reader])
3030
->getMockForAbstractClass()
3131
;

Tests/Loader/AnnotationFileLoaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function testLoadTraitWithClassConstant()
4444

4545
public function testLoadFileWithoutStartTag()
4646
{
47-
$this->expectException('InvalidArgumentException');
47+
$this->expectException(\InvalidArgumentException::class);
4848
$this->expectExceptionMessage('Did you forgot to add the "<?php" start tag at the beginning of the file?');
4949
$this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/NoStartTagClass.php');
5050
}

Tests/Loader/ObjectLoaderTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function testLoadCallsServiceAndReturnsCollection()
4545
*/
4646
public function testExceptionWithoutSyntax(string $resourceString)
4747
{
48-
$this->expectException('InvalidArgumentException');
48+
$this->expectException(\InvalidArgumentException::class);
4949
$loader = new TestObjectLoader();
5050
$loader->load($resourceString);
5151
}
@@ -72,16 +72,16 @@ public function testExceptionOnNoObjectReturned()
7272

7373
public function testExceptionOnBadMethod()
7474
{
75-
$this->expectException('BadMethodCallException');
75+
$this->expectException(\BadMethodCallException::class);
7676
$loader = new TestObjectLoader();
7777
$loader->loaderMap = ['my_service' => new \stdClass()];
7878
$loader->load('my_service::method');
7979
}
8080

8181
public function testExceptionOnMethodNotReturningCollection()
8282
{
83-
$this->expectException('LogicException');
84-
$service = $this->getMockBuilder('stdClass')
83+
$this->expectException(\LogicException::class);
84+
$service = $this->getMockBuilder(\stdClass::class)
8585
->setMethods(['loadRoutes'])
8686
->getMock();
8787
$service->expects($this->once())

Tests/Loader/ObjectRouteLoaderTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function testLoadCallsServiceAndReturnsCollection()
7373
*/
7474
public function testExceptionWithoutSyntax(string $resourceString)
7575
{
76-
$this->expectException('InvalidArgumentException');
76+
$this->expectException(\InvalidArgumentException::class);
7777
$loader = new TestObjectRouteLoader();
7878
$loader->load($resourceString);
7979
}
@@ -100,16 +100,16 @@ public function testExceptionOnNoObjectReturned()
100100

101101
public function testExceptionOnBadMethod()
102102
{
103-
$this->expectException('BadMethodCallException');
103+
$this->expectException(\BadMethodCallException::class);
104104
$loader = new TestObjectRouteLoader();
105105
$loader->loaderMap = ['my_service' => new \stdClass()];
106106
$loader->load('my_service::method');
107107
}
108108

109109
public function testExceptionOnMethodNotReturningCollection()
110110
{
111-
$this->expectException('LogicException');
112-
$service = $this->getMockBuilder('stdClass')
111+
$this->expectException(\LogicException::class);
112+
$service = $this->getMockBuilder(\stdClass::class)
113113
->setMethods(['loadRoutes'])
114114
->getMock();
115115
$service->expects($this->once())

Tests/Loader/PhpFileLoaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class PhpFileLoaderTest extends TestCase
2222
{
2323
public function testSupports()
2424
{
25-
$loader = new PhpFileLoader($this->getMockBuilder('Symfony\Component\Config\FileLocator')->getMock());
25+
$loader = new PhpFileLoader($this->getMockBuilder(FileLocator::class)->getMock());
2626

2727
$this->assertTrue($loader->supports('foo.php'), '->supports() returns true if the resource is loadable');
2828
$this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');

0 commit comments

Comments
 (0)