Skip to content

Commit fdf759d

Browse files
committed
Merge branch '5.1' into 5.2
* 5.1: Use ::class keyword when possible
2 parents 9ebc4cf + ece742b commit fdf759d

File tree

10 files changed

+91
-91
lines changed

10 files changed

+91
-91
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public function load(array $configs, ContainerBuilder $container)
230230
// default in the Form and Validator component). If disabled, an identity
231231
// translator will be used and everything will still work as expected.
232232
if ($this->isConfigEnabled($container, $config['translator']) || $this->isConfigEnabled($container, $config['form']) || $this->isConfigEnabled($container, $config['validation'])) {
233-
if (!class_exists('Symfony\Component\Translation\Translator') && $this->isConfigEnabled($container, $config['translator'])) {
233+
if (!class_exists(Translator::class) && $this->isConfigEnabled($container, $config['translator'])) {
234234
throw new LogicException('Translation support cannot be enabled as the Translation component is not installed. Try running "composer require symfony/translation".');
235235
}
236236

@@ -318,14 +318,14 @@ public function load(array $configs, ContainerBuilder $container)
318318
$this->registerSecurityCsrfConfiguration($config['csrf_protection'], $container, $loader);
319319

320320
if ($this->isConfigEnabled($container, $config['form'])) {
321-
if (!class_exists('Symfony\Component\Form\Form')) {
321+
if (!class_exists(\Symfony\Component\Form\Form::class)) {
322322
throw new LogicException('Form support cannot be enabled as the Form component is not installed. Try running "composer require symfony/form".');
323323
}
324324

325325
$this->formConfigEnabled = true;
326326
$this->registerFormConfiguration($config, $container, $loader);
327327

328-
if (class_exists('Symfony\Component\Validator\Validation')) {
328+
if (class_exists(\Symfony\Component\Validator\Validation::class)) {
329329
$config['validation']['enabled'] = true;
330330
} else {
331331
$container->setParameter('validator.translation_domain', 'validators');
@@ -338,7 +338,7 @@ public function load(array $configs, ContainerBuilder $container)
338338
}
339339

340340
if ($this->isConfigEnabled($container, $config['assets'])) {
341-
if (!class_exists('Symfony\Component\Asset\Package')) {
341+
if (!class_exists(\Symfony\Component\Asset\Package::class)) {
342342
throw new LogicException('Asset support cannot be enabled as the Asset component is not installed. Try running "composer require symfony/asset".');
343343
}
344344

@@ -406,7 +406,7 @@ public function load(array $configs, ContainerBuilder $container)
406406
$this->registerSecretsConfiguration($config['secrets'], $container, $loader);
407407

408408
if ($this->isConfigEnabled($container, $config['serializer'])) {
409-
if (!class_exists('Symfony\Component\Serializer\Serializer')) {
409+
if (!class_exists(\Symfony\Component\Serializer\Serializer::class)) {
410410
throw new LogicException('Serializer support cannot be enabled as the Serializer component is not installed. Try running "composer require symfony/serializer-pack".');
411411
}
412412

@@ -1171,18 +1171,18 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
11711171
$dirs = [];
11721172
$transPaths = [];
11731173
$nonExistingDirs = [];
1174-
if (class_exists('Symfony\Component\Validator\Validation')) {
1175-
$r = new \ReflectionClass('Symfony\Component\Validator\Validation');
1174+
if (class_exists(\Symfony\Component\Validator\Validation::class)) {
1175+
$r = new \ReflectionClass(\Symfony\Component\Validator\Validation::class);
11761176

11771177
$dirs[] = $transPaths[] = \dirname($r->getFileName()).'/Resources/translations';
11781178
}
1179-
if (class_exists('Symfony\Component\Form\Form')) {
1180-
$r = new \ReflectionClass('Symfony\Component\Form\Form');
1179+
if (class_exists(\Symfony\Component\Form\Form::class)) {
1180+
$r = new \ReflectionClass(\Symfony\Component\Form\Form::class);
11811181

11821182
$dirs[] = $transPaths[] = \dirname($r->getFileName()).'/Resources/translations';
11831183
}
1184-
if (class_exists('Symfony\Component\Security\Core\Exception\AuthenticationException')) {
1185-
$r = new \ReflectionClass('Symfony\Component\Security\Core\Exception\AuthenticationException');
1184+
if (class_exists(\Symfony\Component\Security\Core\Exception\AuthenticationException::class)) {
1185+
$r = new \ReflectionClass(\Symfony\Component\Security\Core\Exception\AuthenticationException::class);
11861186

11871187
$dirs[] = $transPaths[] = \dirname($r->getFileName(), 2).'/Resources/translations';
11881188
}
@@ -1280,7 +1280,7 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
12801280
return;
12811281
}
12821282

1283-
if (!class_exists('Symfony\Component\Validator\Validation')) {
1283+
if (!class_exists(\Symfony\Component\Validator\Validation::class)) {
12841284
throw new LogicException('Validation support cannot be enabled as the Validator component is not installed. Try running "composer require symfony/validator".');
12851285
}
12861286

@@ -1347,8 +1347,8 @@ private function registerValidatorMapping(ContainerBuilder $container, array $co
13471347
$files['yaml' === $extension ? 'yml' : $extension][] = $path;
13481348
};
13491349

1350-
if (interface_exists('Symfony\Component\Form\FormInterface')) {
1351-
$reflClass = new \ReflectionClass('Symfony\Component\Form\FormInterface');
1350+
if (interface_exists(\Symfony\Component\Form\FormInterface::class)) {
1351+
$reflClass = new \ReflectionClass(\Symfony\Component\Form\FormInterface::class);
13521352
$fileRecorder('xml', \dirname($reflClass->getFileName()).'/Resources/config/validation.xml');
13531353
}
13541354

@@ -1409,7 +1409,7 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
14091409
return;
14101410
}
14111411

1412-
if (!class_exists('Doctrine\Common\Annotations\Annotation')) {
1412+
if (!class_exists(\Doctrine\Common\Annotations\Annotation::class)) {
14131413
throw new LogicException('Annotations cannot be enabled as the Doctrine Annotation library is not installed.');
14141414
}
14151415

@@ -1421,7 +1421,7 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
14211421
}
14221422

14231423
if ('none' !== $config['cache']) {
1424-
if (!class_exists('Doctrine\Common\Cache\CacheProvider')) {
1424+
if (!class_exists(\Doctrine\Common\Cache\CacheProvider::class)) {
14251425
throw new LogicException('Annotations cannot be enabled as the Doctrine Cache library is not installed.');
14261426
}
14271427

@@ -1532,7 +1532,7 @@ private function registerSecurityCsrfConfiguration(array $config, ContainerBuild
15321532
return;
15331533
}
15341534

1535-
if (!class_exists('Symfony\Component\Security\Csrf\CsrfToken')) {
1535+
if (!class_exists(\Symfony\Component\Security\Csrf\CsrfToken::class)) {
15361536
throw new LogicException('CSRF support cannot be enabled as the Security CSRF component is not installed. Try running "composer require symfony/security-csrf".');
15371537
}
15381538

@@ -1647,7 +1647,7 @@ private function registerPropertyInfoConfiguration(ContainerBuilder $container,
16471647

16481648
$loader->load('property_info.php');
16491649

1650-
if (interface_exists('phpDocumentor\Reflection\DocBlockFactoryInterface')) {
1650+
if (interface_exists(\phpDocumentor\Reflection\DocBlockFactoryInterface::class)) {
16511651
$definition = $container->register('property_info.php_doc_extractor', 'Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor');
16521652
$definition->addTag('property_info.description_extractor', ['priority' => -1000]);
16531653
$definition->addTag('property_info.type_extractor', ['priority' => -1001]);

Tests/Command/TranslationDebugCommandTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function testDebugCustomDirectory()
9292
{
9393
$this->fs->mkdir($this->translationDir.'/customDir/translations');
9494
$this->fs->mkdir($this->translationDir.'/customDir/templates');
95-
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock();
95+
$kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\KernelInterface::class)->getMock();
9696
$kernel->expects($this->once())
9797
->method('getBundle')
9898
->with($this->equalTo($this->translationDir.'/customDir'))
@@ -110,8 +110,8 @@ public function testDebugCustomDirectory()
110110

111111
public function testDebugInvalidDirectory()
112112
{
113-
$this->expectException('InvalidArgumentException');
114-
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock();
113+
$this->expectException(\InvalidArgumentException::class);
114+
$kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\KernelInterface::class)->getMock();
115115
$kernel->expects($this->once())
116116
->method('getBundle')
117117
->with($this->equalTo('dir'))
@@ -136,7 +136,7 @@ protected function tearDown(): void
136136

137137
private function createCommandTester($extractedMessages = [], $loadedMessages = [], $kernel = null, array $transPaths = [], array $viewsPaths = []): CommandTester
138138
{
139-
$translator = $this->getMockBuilder('Symfony\Component\Translation\Translator')
139+
$translator = $this->getMockBuilder(\Symfony\Component\Translation\Translator::class)
140140
->disableOriginalConstructor()
141141
->getMock();
142142

@@ -145,7 +145,7 @@ private function createCommandTester($extractedMessages = [], $loadedMessages =
145145
->method('getFallbackLocales')
146146
->willReturn(['en']);
147147

148-
$extractor = $this->getMockBuilder('Symfony\Component\Translation\Extractor\ExtractorInterface')->getMock();
148+
$extractor = $this->getMockBuilder(\Symfony\Component\Translation\Extractor\ExtractorInterface::class)->getMock();
149149
$extractor
150150
->expects($this->any())
151151
->method('extract')
@@ -155,7 +155,7 @@ function ($path, $catalogue) use ($extractedMessages) {
155155
}
156156
);
157157

158-
$loader = $this->getMockBuilder('Symfony\Component\Translation\Reader\TranslationReader')->getMock();
158+
$loader = $this->getMockBuilder(\Symfony\Component\Translation\Reader\TranslationReader::class)->getMock();
159159
$loader
160160
->expects($this->any())
161161
->method('read')
@@ -170,7 +170,7 @@ function ($path, $catalogue) use ($loadedMessages) {
170170
['foo', $this->getBundle($this->translationDir)],
171171
['test', $this->getBundle('test')],
172172
];
173-
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock();
173+
$kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\KernelInterface::class)->getMock();
174174
$kernel
175175
->expects($this->any())
176176
->method('getBundle')
@@ -198,7 +198,7 @@ function ($path, $catalogue) use ($loadedMessages) {
198198

199199
private function getBundle($path)
200200
{
201-
$bundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\BundleInterface')->getMock();
201+
$bundle = $this->getMockBuilder(\Symfony\Component\HttpKernel\Bundle\BundleInterface::class)->getMock();
202202
$bundle
203203
->expects($this->any())
204204
->method('getPath')

Tests/Command/TranslationUpdateCommandTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ protected function tearDown(): void
145145
*/
146146
private function createCommandTester($extractedMessages = [], $loadedMessages = [], HttpKernel\KernelInterface $kernel = null, array $transPaths = [], array $viewsPaths = [])
147147
{
148-
$translator = $this->getMockBuilder('Symfony\Component\Translation\Translator')
148+
$translator = $this->getMockBuilder(\Symfony\Component\Translation\Translator::class)
149149
->disableOriginalConstructor()
150150
->getMock();
151151

@@ -154,7 +154,7 @@ private function createCommandTester($extractedMessages = [], $loadedMessages =
154154
->method('getFallbackLocales')
155155
->willReturn(['en']);
156156

157-
$extractor = $this->getMockBuilder('Symfony\Component\Translation\Extractor\ExtractorInterface')->getMock();
157+
$extractor = $this->getMockBuilder(\Symfony\Component\Translation\Extractor\ExtractorInterface::class)->getMock();
158158
$extractor
159159
->expects($this->any())
160160
->method('extract')
@@ -166,7 +166,7 @@ function ($path, $catalogue) use ($extractedMessages) {
166166
}
167167
);
168168

169-
$loader = $this->getMockBuilder('Symfony\Component\Translation\Reader\TranslationReader')->getMock();
169+
$loader = $this->getMockBuilder(\Symfony\Component\Translation\Reader\TranslationReader::class)->getMock();
170170
$loader
171171
->expects($this->any())
172172
->method('read')
@@ -176,7 +176,7 @@ function ($path, $catalogue) use ($loadedMessages) {
176176
}
177177
);
178178

179-
$writer = $this->getMockBuilder('Symfony\Component\Translation\Writer\TranslationWriter')->getMock();
179+
$writer = $this->getMockBuilder(\Symfony\Component\Translation\Writer\TranslationWriter::class)->getMock();
180180
$writer
181181
->expects($this->any())
182182
->method('getFormats')
@@ -189,7 +189,7 @@ function ($path, $catalogue) use ($loadedMessages) {
189189
['foo', $this->getBundle($this->translationDir)],
190190
['test', $this->getBundle('test')],
191191
];
192-
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock();
192+
$kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\KernelInterface::class)->getMock();
193193
$kernel
194194
->expects($this->any())
195195
->method('getBundle')
@@ -217,7 +217,7 @@ function ($path, $catalogue) use ($loadedMessages) {
217217

218218
private function getBundle($path)
219219
{
220-
$bundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\BundleInterface')->getMock();
220+
$bundle = $this->getMockBuilder(\Symfony\Component\HttpKernel\Bundle\BundleInterface::class)->getMock();
221221
$bundle
222222
->expects($this->any())
223223
->method('getPath')

Tests/Console/ApplicationTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ApplicationTest extends TestCase
3030
{
3131
public function testBundleInterfaceImplementation()
3232
{
33-
$bundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\BundleInterface')->getMock();
33+
$bundle = $this->getMockBuilder(\Symfony\Component\HttpKernel\Bundle\BundleInterface::class)->getMock();
3434

3535
$kernel = $this->getKernel([$bundle], true);
3636

@@ -236,10 +236,10 @@ private function createEventForSuggestingPackages(string $command, array $altern
236236

237237
private function getKernel(array $bundles, $useDispatcher = false)
238238
{
239-
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
239+
$container = $this->getMockBuilder(\Symfony\Component\DependencyInjection\ContainerInterface::class)->getMock();
240240

241241
if ($useDispatcher) {
242-
$dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')->getMock();
242+
$dispatcher = $this->getMockBuilder(\Symfony\Component\EventDispatcher\EventDispatcherInterface::class)->getMock();
243243
$dispatcher
244244
->expects($this->atLeastOnce())
245245
->method('dispatch')
@@ -264,7 +264,7 @@ private function getKernel(array $bundles, $useDispatcher = false)
264264
->willReturnOnConsecutiveCalls([], [])
265265
;
266266

267-
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock();
267+
$kernel = $this->getMockBuilder(KernelInterface::class)->getMock();
268268
$kernel->expects($this->once())->method('boot');
269269
$kernel
270270
->expects($this->any())
@@ -282,7 +282,7 @@ private function getKernel(array $bundles, $useDispatcher = false)
282282

283283
private function createBundleMock(array $commands)
284284
{
285-
$bundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\Bundle')->getMock();
285+
$bundle = $this->getMockBuilder(\Symfony\Component\HttpKernel\Bundle\Bundle::class)->getMock();
286286
$bundle
287287
->expects($this->once())
288288
->method('registerCommands')

0 commit comments

Comments
 (0)