Skip to content

Commit 4b671a1

Browse files
committed
Use ::class keyword when possible
1 parent fd4db22 commit 4b671a1

37 files changed

+169
-169
lines changed

Command/AboutCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8282
new TableSeparator(),
8383
['Version', \PHP_VERSION],
8484
['Architecture', (\PHP_INT_SIZE * 8).' bits'],
85-
['Intl locale', class_exists('Locale', false) && \Locale::getDefault() ? \Locale::getDefault() : 'n/a'],
85+
['Intl locale', class_exists(\Locale::class, false) && \Locale::getDefault() ? \Locale::getDefault() : 'n/a'],
8686
['Timezone', date_default_timezone_get().' (<comment>'.(new \DateTime())->format(\DateTime::W3C).'</>)'],
8787
['OPcache', \extension_loaded('Zend OPcache') && filter_var(ini_get('opcache.enable'), \FILTER_VALIDATE_BOOLEAN) ? 'true' : 'false'],
8888
['APCu', \extension_loaded('apcu') && filter_var(ini_get('apc.enabled'), \FILTER_VALIDATE_BOOLEAN) ? 'true' : 'false'],

DependencyInjection/FrameworkExtension.php

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

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

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

275275
$this->formConfigEnabled = true;
276276
$this->registerFormConfiguration($config, $container, $loader);
277277

278-
if (class_exists('Symfony\Component\Validator\Validation')) {
278+
if (class_exists(\Symfony\Component\Validator\Validation::class)) {
279279
$config['validation']['enabled'] = true;
280280
} else {
281281
$container->setParameter('validator.translation_domain', 'validators');
@@ -288,7 +288,7 @@ public function load(array $configs, ContainerBuilder $container)
288288
}
289289

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

@@ -298,7 +298,7 @@ public function load(array $configs, ContainerBuilder $container)
298298
if ($this->isConfigEnabled($container, $config['templating'])) {
299299
@trigger_error('Enabling the Templating component is deprecated since version 4.3 and will be removed in 5.0; use Twig instead.', \E_USER_DEPRECATED);
300300

301-
if (!class_exists('Symfony\Component\Templating\PhpEngine')) {
301+
if (!class_exists(\Symfony\Component\Templating\PhpEngine::class)) {
302302
throw new LogicException('Templating support cannot be enabled as the Templating component is not installed. Try running "composer require symfony/templating".');
303303
}
304304

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

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

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

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

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

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

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

@@ -1351,8 +1351,8 @@ private function registerValidatorMapping(ContainerBuilder $container, array $co
13511351
$files['yaml' === $extension ? 'yml' : $extension][] = $path;
13521352
};
13531353

1354-
if (interface_exists('Symfony\Component\Form\FormInterface')) {
1355-
$reflClass = new \ReflectionClass('Symfony\Component\Form\FormInterface');
1354+
if (interface_exists(\Symfony\Component\Form\FormInterface::class)) {
1355+
$reflClass = new \ReflectionClass(\Symfony\Component\Form\FormInterface::class);
13561356
$fileRecorder('xml', \dirname($reflClass->getFileName()).'/Resources/config/validation.xml');
13571357
}
13581358

@@ -1413,7 +1413,7 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
14131413
return;
14141414
}
14151415

1416-
if (!class_exists('Doctrine\Common\Annotations\Annotation')) {
1416+
if (!class_exists(\Doctrine\Common\Annotations\Annotation::class)) {
14171417
throw new LogicException('Annotations cannot be enabled as the Doctrine Annotation library is not installed.');
14181418
}
14191419

@@ -1425,7 +1425,7 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
14251425
}
14261426

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

@@ -1469,7 +1469,7 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
14691469

14701470
private function registerPropertyAccessConfiguration(array $config, ContainerBuilder $container, XmlFileLoader $loader)
14711471
{
1472-
if (!class_exists('Symfony\Component\PropertyAccess\PropertyAccessor')) {
1472+
if (!class_exists(PropertyAccessor::class)) {
14731473
return;
14741474
}
14751475

@@ -1523,7 +1523,7 @@ private function registerSecurityCsrfConfiguration(array $config, ContainerBuild
15231523
return;
15241524
}
15251525

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

@@ -1554,7 +1554,7 @@ private function registerSerializerConfiguration(array $config, ContainerBuilder
15541554

15551555
$chainLoader = $container->getDefinition('serializer.mapping.chain_loader');
15561556

1557-
if (!class_exists('Symfony\Component\PropertyAccess\PropertyAccessor')) {
1557+
if (!class_exists(PropertyAccessor::class)) {
15581558
$container->removeAlias('serializer.property_accessor');
15591559
$container->removeDefinition('serializer.normalizer.object');
15601560
}
@@ -1643,7 +1643,7 @@ private function registerPropertyInfoConfiguration(ContainerBuilder $container,
16431643

16441644
$loader->load('property_info.xml');
16451645

1646-
if (interface_exists('phpDocumentor\Reflection\DocBlockFactoryInterface')) {
1646+
if (interface_exists(\phpDocumentor\Reflection\DocBlockFactoryInterface::class)) {
16471647
$definition = $container->register('property_info.php_doc_extractor', 'Symfony\Component\PropertyInfo\Extractor\PhpDocExtractor');
16481648
$definition->setPrivate(true);
16491649
$definition->addTag('property_info.description_extractor', ['priority' => -1000]);

Tests/CacheWarmer/AnnotationsCacheWarmerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public function testClassAutoloadExceptionWithUnrelatedException()
125125
*/
126126
private function getReadOnlyReader()
127127
{
128-
$readerMock = $this->getMockBuilder('Doctrine\Common\Annotations\Reader')->getMock();
128+
$readerMock = $this->getMockBuilder(Reader::class)->getMock();
129129
$readerMock->expects($this->exactly(0))->method('getClassAnnotations');
130130
$readerMock->expects($this->exactly(0))->method('getClassAnnotation');
131131
$readerMock->expects($this->exactly(0))->method('getMethodAnnotations');

Tests/CacheWarmer/TemplateFinderTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class TemplateFinderTest extends TestCase
2424
public function testFindAllTemplates()
2525
{
2626
$kernel = $this
27-
->getMockBuilder('Symfony\Component\HttpKernel\Kernel')
27+
->getMockBuilder(\Symfony\Component\HttpKernel\Kernel::class)
2828
->disableOriginalConstructor()
2929
->getMock()
3030
;

Tests/Command/CachePoolDeleteCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function testCommandDeleteFailed()
8989
private function getKernel()
9090
{
9191
$container = $this
92-
->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')
92+
->getMockBuilder(\Symfony\Component\DependencyInjection\ContainerInterface::class)
9393
->getMock();
9494

9595
$kernel = $this

Tests/Command/CachePruneCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private function getEmptyRewindableGenerator(): RewindableGenerator
5555
private function getKernel()
5656
{
5757
$container = $this
58-
->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')
58+
->getMockBuilder(\Symfony\Component\DependencyInjection\ContainerInterface::class)
5959
->getMock();
6060

6161
$kernel = $this

Tests/Command/RouterMatchCommandTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private function getRouter()
5555
$routeCollection = new RouteCollection();
5656
$routeCollection->add('foo', new Route('foo'));
5757
$requestContext = new RequestContext();
58-
$router = $this->getMockBuilder('Symfony\Component\Routing\RouterInterface')->getMock();
58+
$router = $this->getMockBuilder(\Symfony\Component\Routing\RouterInterface::class)->getMock();
5959
$router
6060
->expects($this->any())
6161
->method('getRouteCollection')
@@ -70,7 +70,7 @@ private function getRouter()
7070

7171
private function getKernel()
7272
{
73-
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
73+
$container = $this->getMockBuilder(\Symfony\Component\DependencyInjection\ContainerInterface::class)->getMock();
7474
$container
7575
->expects($this->atLeastOnce())
7676
->method('has')

Tests/Command/TranslationDebugCommandTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function testDebugCustomDirectory()
101101
{
102102
$this->fs->mkdir($this->translationDir.'/customDir/translations');
103103
$this->fs->mkdir($this->translationDir.'/customDir/templates');
104-
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock();
104+
$kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\KernelInterface::class)->getMock();
105105
$kernel->expects($this->once())
106106
->method('getBundle')
107107
->with($this->equalTo($this->translationDir.'/customDir'))
@@ -116,8 +116,8 @@ public function testDebugCustomDirectory()
116116

117117
public function testDebugInvalidDirectory()
118118
{
119-
$this->expectException('InvalidArgumentException');
120-
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock();
119+
$this->expectException(\InvalidArgumentException::class);
120+
$kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\KernelInterface::class)->getMock();
121121
$kernel->expects($this->once())
122122
->method('getBundle')
123123
->with($this->equalTo('dir'))
@@ -142,7 +142,7 @@ protected function tearDown(): void
142142

143143
private function createCommandTester($extractedMessages = [], $loadedMessages = [], $kernel = null, array $transPaths = [], array $viewsPaths = []): CommandTester
144144
{
145-
$translator = $this->getMockBuilder('Symfony\Component\Translation\Translator')
145+
$translator = $this->getMockBuilder(\Symfony\Component\Translation\Translator::class)
146146
->disableOriginalConstructor()
147147
->getMock();
148148

@@ -151,7 +151,7 @@ private function createCommandTester($extractedMessages = [], $loadedMessages =
151151
->method('getFallbackLocales')
152152
->willReturn(['en']);
153153

154-
$extractor = $this->getMockBuilder('Symfony\Component\Translation\Extractor\ExtractorInterface')->getMock();
154+
$extractor = $this->getMockBuilder(\Symfony\Component\Translation\Extractor\ExtractorInterface::class)->getMock();
155155
$extractor
156156
->expects($this->any())
157157
->method('extract')
@@ -161,7 +161,7 @@ function ($path, $catalogue) use ($extractedMessages) {
161161
}
162162
);
163163

164-
$loader = $this->getMockBuilder('Symfony\Component\Translation\Reader\TranslationReader')->getMock();
164+
$loader = $this->getMockBuilder(\Symfony\Component\Translation\Reader\TranslationReader::class)->getMock();
165165
$loader
166166
->expects($this->any())
167167
->method('read')
@@ -182,7 +182,7 @@ function ($path, $catalogue) use ($loadedMessages) {
182182
['test', true, $this->getBundle('test')],
183183
];
184184
}
185-
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock();
185+
$kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\KernelInterface::class)->getMock();
186186
$kernel
187187
->expects($this->any())
188188
->method('getBundle')
@@ -212,7 +212,7 @@ function ($path, $catalogue) use ($loadedMessages) {
212212

213213
private function getBundle($path)
214214
{
215-
$bundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\BundleInterface')->getMock();
215+
$bundle = $this->getMockBuilder(\Symfony\Component\HttpKernel\Bundle\BundleInterface::class)->getMock();
216216
$bundle
217217
->expects($this->any())
218218
->method('getPath')

Tests/Command/TranslationUpdateCommandTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ protected function tearDown(): void
154154
*/
155155
private function createCommandTester($extractedMessages = [], $loadedMessages = [], HttpKernel\KernelInterface $kernel = null, array $transPaths = [], array $viewsPaths = [])
156156
{
157-
$translator = $this->getMockBuilder('Symfony\Component\Translation\Translator')
157+
$translator = $this->getMockBuilder(\Symfony\Component\Translation\Translator::class)
158158
->disableOriginalConstructor()
159159
->getMock();
160160

@@ -163,7 +163,7 @@ private function createCommandTester($extractedMessages = [], $loadedMessages =
163163
->method('getFallbackLocales')
164164
->willReturn(['en']);
165165

166-
$extractor = $this->getMockBuilder('Symfony\Component\Translation\Extractor\ExtractorInterface')->getMock();
166+
$extractor = $this->getMockBuilder(\Symfony\Component\Translation\Extractor\ExtractorInterface::class)->getMock();
167167
$extractor
168168
->expects($this->any())
169169
->method('extract')
@@ -175,7 +175,7 @@ function ($path, $catalogue) use ($extractedMessages) {
175175
}
176176
);
177177

178-
$loader = $this->getMockBuilder('Symfony\Component\Translation\Reader\TranslationReader')->getMock();
178+
$loader = $this->getMockBuilder(\Symfony\Component\Translation\Reader\TranslationReader::class)->getMock();
179179
$loader
180180
->expects($this->any())
181181
->method('read')
@@ -185,7 +185,7 @@ function ($path, $catalogue) use ($loadedMessages) {
185185
}
186186
);
187187

188-
$writer = $this->getMockBuilder('Symfony\Component\Translation\Writer\TranslationWriter')->getMock();
188+
$writer = $this->getMockBuilder(\Symfony\Component\Translation\Writer\TranslationWriter::class)->getMock();
189189
$writer
190190
->expects($this->any())
191191
->method('getFormats')
@@ -204,7 +204,7 @@ function ($path, $catalogue) use ($loadedMessages) {
204204
['test', true, $this->getBundle('test')],
205205
];
206206
}
207-
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock();
207+
$kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\KernelInterface::class)->getMock();
208208
$kernel
209209
->expects($this->any())
210210
->method('getBundle')
@@ -233,7 +233,7 @@ function ($path, $catalogue) use ($loadedMessages) {
233233

234234
private function getBundle($path)
235235
{
236-
$bundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\BundleInterface')->getMock();
236+
$bundle = $this->getMockBuilder(\Symfony\Component\HttpKernel\Bundle\BundleInterface::class)->getMock();
237237
$bundle
238238
->expects($this->any())
239239
->method('getPath')

Tests/Command/YamlLintCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function testLintIncorrectFile()
6060

6161
public function testLintFileNotReadable()
6262
{
63-
$this->expectException('RuntimeException');
63+
$this->expectException(\RuntimeException::class);
6464
$tester = $this->createCommandTester();
6565
$filename = $this->createFile('');
6666
unlink($filename);

0 commit comments

Comments
 (0)