Skip to content

Commit ece742b

Browse files
committed
Use ::class keyword when possible
1 parent 2fa1d9e commit ece742b

11 files changed

+103
-103
lines changed

DependencyInjection/FrameworkExtension.php

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

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

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

296296
$this->formConfigEnabled = true;
297297
$this->registerFormConfiguration($config, $container, $loader);
298298

299-
if (class_exists('Symfony\Component\Validator\Validation')) {
299+
if (class_exists(\Symfony\Component\Validator\Validation::class)) {
300300
$config['validation']['enabled'] = true;
301301
} else {
302302
$container->setParameter('validator.translation_domain', 'validators');
@@ -309,7 +309,7 @@ public function load(array $configs, ContainerBuilder $container)
309309
}
310310

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

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

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

@@ -1114,18 +1114,18 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder
11141114
$dirs = [];
11151115
$transPaths = [];
11161116
$nonExistingDirs = [];
1117-
if (class_exists('Symfony\Component\Validator\Validation')) {
1118-
$r = new \ReflectionClass('Symfony\Component\Validator\Validation');
1117+
if (class_exists(\Symfony\Component\Validator\Validation::class)) {
1118+
$r = new \ReflectionClass(\Symfony\Component\Validator\Validation::class);
11191119

11201120
$dirs[] = $transPaths[] = \dirname($r->getFileName()).'/Resources/translations';
11211121
}
1122-
if (class_exists('Symfony\Component\Form\Form')) {
1123-
$r = new \ReflectionClass('Symfony\Component\Form\Form');
1122+
if (class_exists(\Symfony\Component\Form\Form::class)) {
1123+
$r = new \ReflectionClass(\Symfony\Component\Form\Form::class);
11241124

11251125
$dirs[] = $transPaths[] = \dirname($r->getFileName()).'/Resources/translations';
11261126
}
1127-
if (class_exists('Symfony\Component\Security\Core\Exception\AuthenticationException')) {
1128-
$r = new \ReflectionClass('Symfony\Component\Security\Core\Exception\AuthenticationException');
1127+
if (class_exists(\Symfony\Component\Security\Core\Exception\AuthenticationException::class)) {
1128+
$r = new \ReflectionClass(\Symfony\Component\Security\Core\Exception\AuthenticationException::class);
11291129

11301130
$dirs[] = $transPaths[] = \dirname($r->getFileName(), 2).'/Resources/translations';
11311131
}
@@ -1208,7 +1208,7 @@ private function registerValidationConfiguration(array $config, ContainerBuilder
12081208
return;
12091209
}
12101210

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

@@ -1272,8 +1272,8 @@ private function registerValidatorMapping(ContainerBuilder $container, array $co
12721272
$files['yaml' === $extension ? 'yml' : $extension][] = $path;
12731273
};
12741274

1275-
if (interface_exists('Symfony\Component\Form\FormInterface')) {
1276-
$reflClass = new \ReflectionClass('Symfony\Component\Form\FormInterface');
1275+
if (interface_exists(\Symfony\Component\Form\FormInterface::class)) {
1276+
$reflClass = new \ReflectionClass(\Symfony\Component\Form\FormInterface::class);
12771277
$fileRecorder('xml', \dirname($reflClass->getFileName()).'/Resources/config/validation.xml');
12781278
}
12791279

@@ -1334,7 +1334,7 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
13341334
return;
13351335
}
13361336

1337-
if (!class_exists('Doctrine\Common\Annotations\Annotation')) {
1337+
if (!class_exists(\Doctrine\Common\Annotations\Annotation::class)) {
13381338
throw new LogicException('Annotations cannot be enabled as the Doctrine Annotation library is not installed.');
13391339
}
13401340

@@ -1346,7 +1346,7 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
13461346
}
13471347

13481348
if ('none' !== $config['cache']) {
1349-
if (!class_exists('Doctrine\Common\Cache\CacheProvider')) {
1349+
if (!class_exists(\Doctrine\Common\Cache\CacheProvider::class)) {
13501350
throw new LogicException('Annotations cannot be enabled as the Doctrine Cache library is not installed.');
13511351
}
13521352

@@ -1452,7 +1452,7 @@ private function registerSecurityCsrfConfiguration(array $config, ContainerBuild
14521452
return;
14531453
}
14541454

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

@@ -1563,7 +1563,7 @@ private function registerPropertyInfoConfiguration(ContainerBuilder $container,
15631563

15641564
$loader->load('property_info.xml');
15651565

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

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
@@ -137,7 +137,7 @@ protected function tearDown(): void
137137
*/
138138
private function createCommandTester($extractedMessages = [], $loadedMessages = [], HttpKernel\KernelInterface $kernel = null, array $transPaths = [], array $viewsPaths = [])
139139
{
140-
$translator = $this->getMockBuilder('Symfony\Component\Translation\Translator')
140+
$translator = $this->getMockBuilder(\Symfony\Component\Translation\Translator::class)
141141
->disableOriginalConstructor()
142142
->getMock();
143143

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

149-
$extractor = $this->getMockBuilder('Symfony\Component\Translation\Extractor\ExtractorInterface')->getMock();
149+
$extractor = $this->getMockBuilder(\Symfony\Component\Translation\Extractor\ExtractorInterface::class)->getMock();
150150
$extractor
151151
->expects($this->any())
152152
->method('extract')
@@ -158,7 +158,7 @@ function ($path, $catalogue) use ($extractedMessages) {
158158
}
159159
);
160160

161-
$loader = $this->getMockBuilder('Symfony\Component\Translation\Reader\TranslationReader')->getMock();
161+
$loader = $this->getMockBuilder(\Symfony\Component\Translation\Reader\TranslationReader::class)->getMock();
162162
$loader
163163
->expects($this->any())
164164
->method('read')
@@ -168,7 +168,7 @@ function ($path, $catalogue) use ($loadedMessages) {
168168
}
169169
);
170170

171-
$writer = $this->getMockBuilder('Symfony\Component\Translation\Writer\TranslationWriter')->getMock();
171+
$writer = $this->getMockBuilder(\Symfony\Component\Translation\Writer\TranslationWriter::class)->getMock();
172172
$writer
173173
->expects($this->any())
174174
->method('getFormats')
@@ -181,7 +181,7 @@ function ($path, $catalogue) use ($loadedMessages) {
181181
['foo', $this->getBundle($this->translationDir)],
182182
['test', $this->getBundle('test')],
183183
];
184-
$kernel = $this->getMockBuilder('Symfony\Component\HttpKernel\KernelInterface')->getMock();
184+
$kernel = $this->getMockBuilder(\Symfony\Component\HttpKernel\KernelInterface::class)->getMock();
185185
$kernel
186186
->expects($this->any())
187187
->method('getBundle')
@@ -209,7 +209,7 @@ function ($path, $catalogue) use ($loadedMessages) {
209209

210210
private function getBundle($path)
211211
{
212-
$bundle = $this->getMockBuilder('Symfony\Component\HttpKernel\Bundle\BundleInterface')->getMock();
212+
$bundle = $this->getMockBuilder(\Symfony\Component\HttpKernel\Bundle\BundleInterface::class)->getMock();
213213
$bundle
214214
->expects($this->any())
215215
->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)