Skip to content

Commit 361f15a

Browse files
committed
minor #39775 [WIP] Use ::class keyword when possible (fabpot)
This PR was merged into the 4.4 branch. Discussion ---------- [WIP] Use ::class keyword when possible | Q | A | ------------- | --- | Branch? | 4.4 <!-- see below --> | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | n/a <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT | Doc PR | n/a Commits ------- 036a36cb14 Use ::class keyword when possible
2 parents 1636082 + 46315a4 commit 361f15a

File tree

9 files changed

+13
-11
lines changed

9 files changed

+13
-11
lines changed

Tests/Compiler/ResolveClassPassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function provideInvalidClassId()
5555
{
5656
yield [\stdClass::class];
5757
yield ['bar'];
58-
yield ['\DateTime'];
58+
yield [\DateTime::class];
5959
}
6060

6161
public function testNonFqcnChildDefinition()

Tests/ContainerBuilderTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ public function testCreateServiceClass()
412412
$builder = new ContainerBuilder();
413413
$builder->register('foo1', '%class%');
414414
$builder->setParameter('class', 'stdClass');
415-
$this->assertInstanceOf('\stdClass', $builder->get('foo1'), '->createService() replaces parameters in the class provided by the service definition');
415+
$this->assertInstanceOf(\stdClass::class, $builder->get('foo1'), '->createService() replaces parameters in the class provided by the service definition');
416416
}
417417

418418
public function testCreateServiceArguments()
@@ -511,7 +511,7 @@ public function testCreateServiceWithIteratorArgument()
511511
foreach ($lazyContext->lazyValues as $k => $v) {
512512
++$i;
513513
$this->assertEquals('k1', $k);
514-
$this->assertInstanceOf('\stdClass', $v);
514+
$this->assertInstanceOf(\stdClass::class, $v);
515515
}
516516

517517
// The second argument should have been ignored.

Tests/ContainerTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\DependencyInjection\Container;
1616
use Symfony\Component\DependencyInjection\ContainerInterface;
17+
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
1718
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
1819
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
1920
use Symfony\Contracts\Service\ResetInterface;
@@ -116,7 +117,7 @@ public function testGetSetParameter()
116117
$sc->getParameter('baba');
117118
$this->fail('->getParameter() thrown an \InvalidArgumentException if the key does not exist');
118119
} catch (\Exception $e) {
119-
$this->assertInstanceOf('\InvalidArgumentException', $e, '->getParameter() thrown an \InvalidArgumentException if the key does not exist');
120+
$this->assertInstanceOf(\InvalidArgumentException::class, $e, '->getParameter() thrown an \InvalidArgumentException if the key does not exist');
120121
$this->assertEquals('You have requested a non-existent parameter "baba".', $e->getMessage(), '->getParameter() thrown an \InvalidArgumentException if the key does not exist');
121122
}
122123
}
@@ -252,7 +253,7 @@ public function testGetCircularReference()
252253
$sc->get('circular');
253254
$this->fail('->get() throws a ServiceCircularReferenceException if it contains circular reference');
254255
} catch (\Exception $e) {
255-
$this->assertInstanceOf('\Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException', $e, '->get() throws a ServiceCircularReferenceException if it contains circular reference');
256+
$this->assertInstanceOf(ServiceCircularReferenceException::class, $e, '->get() throws a ServiceCircularReferenceException if it contains circular reference');
256257
$this->assertStringStartsWith('Circular reference detected for service "circular"', $e->getMessage(), '->get() throws a \LogicException if it contains circular reference');
257258
}
258259
}

Tests/Dumper/PhpDumperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public function testAddService()
211211
$dumper->dump();
212212
$this->fail('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
213213
} catch (\Exception $e) {
214-
$this->assertInstanceOf('\Symfony\Component\DependencyInjection\Exception\RuntimeException', $e, '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
214+
$this->assertInstanceOf(RuntimeException::class, $e, '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
215215
$this->assertEquals('Unable to dump a service container if a parameter is an object or a resource.', $e->getMessage(), '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
216216
}
217217
}

Tests/Dumper/XmlDumperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function testAddService()
6464
$dumper->dump();
6565
$this->fail('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
6666
} catch (\Exception $e) {
67-
$this->assertInstanceOf('\RuntimeException', $e, '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
67+
$this->assertInstanceOf(\RuntimeException::class, $e, '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
6868
$this->assertEquals('Unable to dump a service container if a parameter is an object or a resource.', $e->getMessage(), '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
6969
}
7070
}

Tests/Dumper/YamlDumperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function testAddService()
5959
$dumper->dump();
6060
$this->fail('->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
6161
} catch (\Exception $e) {
62-
$this->assertInstanceOf('\RuntimeException', $e, '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
62+
$this->assertInstanceOf(\RuntimeException::class, $e, '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
6363
$this->assertEquals('Unable to dump a service container if a parameter is an object or a resource.', $e->getMessage(), '->dump() throws a RuntimeException if the container to be dumped has reference to objects or resources');
6464
}
6565
}

Tests/Fixtures/containers/container9.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require_once __DIR__.'/../includes/classes.php';
44
require_once __DIR__.'/../includes/foo.php';
55

6+
use Bar\FooClass;
67
use Symfony\Component\DependencyInjection\Argument\IteratorArgument;
78
use Symfony\Component\DependencyInjection\Argument\TaggedIteratorArgument;
89
use Symfony\Component\DependencyInjection\ContainerBuilder;
@@ -13,7 +14,7 @@
1314

1415
$container = new ContainerBuilder();
1516
$container
16-
->register('foo', '\Bar\FooClass')
17+
->register('foo', FooClass::class)
1718
->addTag('foo', ['foo' => 'foo'])
1819
->addTag('foo', ['bar' => 'bar', 'baz' => 'baz'])
1920
->setFactory(['Bar\\FooClass', 'getInstance'])

Tests/Loader/XmlFileLoaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ public function testExtensions()
507507
$loader->load('extensions/services4.xml');
508508
$this->fail('->load() throws an InvalidArgumentException if the tag is not valid');
509509
} catch (\Exception $e) {
510-
$this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the tag is not valid');
510+
$this->assertInstanceOf(\InvalidArgumentException::class, $e, '->load() throws an InvalidArgumentException if the tag is not valid');
511511
$this->assertStringStartsWith('There is no extension able to load the configuration for "project:bar" (in', $e->getMessage(), '->load() throws an InvalidArgumentException if the tag is not valid');
512512
}
513513
}

Tests/Loader/YamlFileLoaderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ public function testExtensions()
285285
$loader->load('services11.yml');
286286
$this->fail('->load() throws an InvalidArgumentException if the tag is not valid');
287287
} catch (\Exception $e) {
288-
$this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the tag is not valid');
288+
$this->assertInstanceOf(\InvalidArgumentException::class, $e, '->load() throws an InvalidArgumentException if the tag is not valid');
289289
$this->assertStringStartsWith('There is no extension able to load the configuration for "foobarfoobar" (in', $e->getMessage(), '->load() throws an InvalidArgumentException if the tag is not valid');
290290
}
291291
}

0 commit comments

Comments
 (0)