Skip to content

Commit f3b24e8

Browse files
committed
Merge branch '4.4' into 5.1
* 4.4: Use ::class keyword when possible
2 parents f72fcaf + b224c5b commit f3b24e8

12 files changed

+50
-47
lines changed

Extension/Core/DataTransformer/DateIntervalToArrayTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function transform($dateInterval)
8282
);
8383
}
8484
if (!$dateInterval instanceof \DateInterval) {
85-
throw new UnexpectedTypeException($dateInterval, '\DateInterval');
85+
throw new UnexpectedTypeException($dateInterval, \DateInterval::class);
8686
}
8787
$result = [];
8888
foreach (self::$availableFields as $field => $char) {

Extension/Core/DataTransformer/DateIntervalToStringTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function transform($value)
5151
return '';
5252
}
5353
if (!$value instanceof \DateInterval) {
54-
throw new UnexpectedTypeException($value, '\DateInterval');
54+
throw new UnexpectedTypeException($value, \DateInterval::class);
5555
}
5656

5757
return $value->format($this->format);

Extension/Core/Type/ChoiceType.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Symfony\Component\Form\ChoiceList\Factory\ChoiceListFactoryInterface;
2626
use Symfony\Component\Form\ChoiceList\Factory\DefaultChoiceListFactory;
2727
use Symfony\Component\Form\ChoiceList\Factory\PropertyAccessDecorator;
28+
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
2829
use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView;
2930
use Symfony\Component\Form\ChoiceList\View\ChoiceListView;
3031
use Symfony\Component\Form\ChoiceList\View\ChoiceView;
@@ -343,16 +344,16 @@ public function configureOptions(OptionsResolver $resolver)
343344
$resolver->setNormalizer('placeholder', $placeholderNormalizer);
344345
$resolver->setNormalizer('choice_translation_domain', $choiceTranslationDomainNormalizer);
345346

346-
$resolver->setAllowedTypes('choices', ['null', 'array', '\Traversable']);
347+
$resolver->setAllowedTypes('choices', ['null', 'array', \Traversable::class]);
347348
$resolver->setAllowedTypes('choice_translation_domain', ['null', 'bool', 'string']);
348-
$resolver->setAllowedTypes('choice_loader', ['null', 'Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface', ChoiceLoader::class]);
349+
$resolver->setAllowedTypes('choice_loader', ['null', ChoiceLoaderInterface::class, ChoiceLoader::class]);
349350
$resolver->setAllowedTypes('choice_filter', ['null', 'callable', 'string', PropertyPath::class, ChoiceFilter::class]);
350-
$resolver->setAllowedTypes('choice_label', ['null', 'bool', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath', ChoiceLabel::class]);
351-
$resolver->setAllowedTypes('choice_name', ['null', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath', ChoiceFieldName::class]);
352-
$resolver->setAllowedTypes('choice_value', ['null', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath', ChoiceValue::class]);
353-
$resolver->setAllowedTypes('choice_attr', ['null', 'array', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath', ChoiceAttr::class]);
354-
$resolver->setAllowedTypes('preferred_choices', ['array', '\Traversable', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath', PreferredChoice::class]);
355-
$resolver->setAllowedTypes('group_by', ['null', 'callable', 'string', 'Symfony\Component\PropertyAccess\PropertyPath', GroupBy::class]);
351+
$resolver->setAllowedTypes('choice_label', ['null', 'bool', 'callable', 'string', PropertyPath::class, ChoiceLabel::class]);
352+
$resolver->setAllowedTypes('choice_name', ['null', 'callable', 'string', PropertyPath::class, ChoiceFieldName::class]);
353+
$resolver->setAllowedTypes('choice_value', ['null', 'callable', 'string', PropertyPath::class, ChoiceValue::class]);
354+
$resolver->setAllowedTypes('choice_attr', ['null', 'array', 'callable', 'string', PropertyPath::class, ChoiceAttr::class]);
355+
$resolver->setAllowedTypes('preferred_choices', ['array', '\Traversable', 'callable', 'string', PropertyPath::class, PreferredChoice::class]);
356+
$resolver->setAllowedTypes('group_by', ['null', 'callable', 'string', PropertyPath::class, GroupBy::class]);
356357
}
357358

358359
/**

Tests/ButtonBuilderTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ public function getValidNames()
3636
*/
3737
public function testValidNames($name)
3838
{
39-
$this->assertInstanceOf('\Symfony\Component\Form\ButtonBuilder', new ButtonBuilder($name));
39+
$this->assertInstanceOf(ButtonBuilder::class, new ButtonBuilder($name));
4040
}
4141

4242
public function testNameContainingIllegalCharacters()
4343
{
44-
$this->expectException('Symfony\Component\Form\Exception\InvalidArgumentException');
44+
$this->expectException(InvalidArgumentException::class);
4545
$this->expectExceptionMessage('The name "button[]" contains illegal characters. Names should start with a letter, digit or underscore and only contain letters, digits, numbers, underscores ("_"), hyphens ("-") and colons (":").');
4646

47-
$this->assertInstanceOf('\Symfony\Component\Form\ButtonBuilder', new ButtonBuilder('button[]'));
47+
$this->assertInstanceOf(ButtonBuilder::class, new ButtonBuilder('button[]'));
4848
}
4949

5050
public function getInvalidNames()

Tests/ChoiceList/Factory/PropertyAccessDecoratorTest.php

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function testCreateFromChoicesPropertyPath()
4545

4646
$this->decoratedFactory->expects($this->once())
4747
->method('createListFromChoices')
48-
->with($choices, $this->isInstanceOf('\Closure'))
48+
->with($choices, $this->isInstanceOf(\Closure::class))
4949
->willReturnCallback(function ($choices, $callback) {
5050
return new ArrayChoiceList(array_map($callback, $choices));
5151
});
@@ -59,7 +59,7 @@ public function testCreateFromChoicesPropertyPathInstance()
5959

6060
$this->decoratedFactory->expects($this->once())
6161
->method('createListFromChoices')
62-
->with($choices, $this->isInstanceOf('\Closure'))
62+
->with($choices, $this->isInstanceOf(\Closure::class))
6363
->willReturnCallback(function ($choices, $callback) {
6464
return new ArrayChoiceList(array_map($callback, $choices));
6565
});
@@ -114,7 +114,7 @@ public function testCreateFromLoaderPropertyPath()
114114

115115
$this->decoratedFactory->expects($this->once())
116116
->method('createListFromLoader')
117-
->with($loader, $this->isInstanceOf('\Closure'))
117+
->with($loader, $this->isInstanceOf(\Closure::class))
118118
->willReturnCallback(function ($loader, $callback) {
119119
return new ArrayChoiceList((array) $callback((object) ['property' => 'value']));
120120
});
@@ -149,7 +149,7 @@ public function testCreateFromChoicesAssumeNullIfValuePropertyPathUnreadable()
149149

150150
$this->decoratedFactory->expects($this->once())
151151
->method('createListFromChoices')
152-
->with($choices, $this->isInstanceOf('\Closure'))
152+
->with($choices, $this->isInstanceOf(\Closure::class))
153153
->willReturnCallback(function ($choices, $callback) {
154154
return new ArrayChoiceList(array_map($callback, $choices));
155155
});
@@ -164,7 +164,7 @@ public function testCreateFromChoiceLoaderAssumeNullIfValuePropertyPathUnreadabl
164164

165165
$this->decoratedFactory->expects($this->once())
166166
->method('createListFromLoader')
167-
->with($loader, $this->isInstanceOf('\Closure'))
167+
->with($loader, $this->isInstanceOf(\Closure::class))
168168
->willReturnCallback(function ($loader, $callback) {
169169
return new ArrayChoiceList((array) $callback(null));
170170
});
@@ -178,7 +178,7 @@ public function testCreateFromLoaderPropertyPathInstance()
178178

179179
$this->decoratedFactory->expects($this->once())
180180
->method('createListFromLoader')
181-
->with($loader, $this->isInstanceOf('\Closure'))
181+
->with($loader, $this->isInstanceOf(\Closure::class))
182182
->willReturnCallback(function ($loader, $callback) {
183183
return new ArrayChoiceList((array) $callback((object) ['property' => 'value']));
184184
});
@@ -192,7 +192,7 @@ public function testCreateViewPreferredChoicesAsPropertyPath()
192192

193193
$this->decoratedFactory->expects($this->once())
194194
->method('createView')
195-
->with($list, $this->isInstanceOf('\Closure'))
195+
->with($list, $this->isInstanceOf(\Closure::class))
196196
->willReturnCallback(function ($list, $preferred) {
197197
return new ChoiceListView((array) $preferred((object) ['property' => true]));
198198
});
@@ -206,7 +206,7 @@ public function testCreateViewPreferredChoicesAsPropertyPathInstance()
206206

207207
$this->decoratedFactory->expects($this->once())
208208
->method('createView')
209-
->with($list, $this->isInstanceOf('\Closure'))
209+
->with($list, $this->isInstanceOf(\Closure::class))
210210
->willReturnCallback(function ($list, $preferred) {
211211
return new ChoiceListView((array) $preferred((object) ['property' => true]));
212212
});
@@ -221,7 +221,7 @@ public function testCreateViewAssumeNullIfPreferredChoicesPropertyPathUnreadable
221221

222222
$this->decoratedFactory->expects($this->once())
223223
->method('createView')
224-
->with($list, $this->isInstanceOf('\Closure'))
224+
->with($list, $this->isInstanceOf(\Closure::class))
225225
->willReturnCallback(function ($list, $preferred) {
226226
return new ChoiceListView((array) $preferred((object) ['category' => null]));
227227
});
@@ -235,7 +235,7 @@ public function testCreateViewLabelsAsPropertyPath()
235235

236236
$this->decoratedFactory->expects($this->once())
237237
->method('createView')
238-
->with($list, null, $this->isInstanceOf('\Closure'))
238+
->with($list, null, $this->isInstanceOf(\Closure::class))
239239
->willReturnCallback(function ($list, $preferred, $label) {
240240
return new ChoiceListView((array) $label((object) ['property' => 'label']));
241241
});
@@ -249,7 +249,7 @@ public function testCreateViewLabelsAsPropertyPathInstance()
249249

250250
$this->decoratedFactory->expects($this->once())
251251
->method('createView')
252-
->with($list, null, $this->isInstanceOf('\Closure'))
252+
->with($list, null, $this->isInstanceOf(\Closure::class))
253253
->willReturnCallback(function ($list, $preferred, $label) {
254254
return new ChoiceListView((array) $label((object) ['property' => 'label']));
255255
});
@@ -263,7 +263,7 @@ public function testCreateViewIndicesAsPropertyPath()
263263

264264
$this->decoratedFactory->expects($this->once())
265265
->method('createView')
266-
->with($list, null, null, $this->isInstanceOf('\Closure'))
266+
->with($list, null, null, $this->isInstanceOf(\Closure::class))
267267
->willReturnCallback(function ($list, $preferred, $label, $index) {
268268
return new ChoiceListView((array) $index((object) ['property' => 'index']));
269269
});
@@ -277,7 +277,7 @@ public function testCreateViewIndicesAsPropertyPathInstance()
277277

278278
$this->decoratedFactory->expects($this->once())
279279
->method('createView')
280-
->with($list, null, null, $this->isInstanceOf('\Closure'))
280+
->with($list, null, null, $this->isInstanceOf(\Closure::class))
281281
->willReturnCallback(function ($list, $preferred, $label, $index) {
282282
return new ChoiceListView((array) $index((object) ['property' => 'index']));
283283
});
@@ -291,7 +291,7 @@ public function testCreateViewGroupsAsPropertyPath()
291291

292292
$this->decoratedFactory->expects($this->once())
293293
->method('createView')
294-
->with($list, null, null, null, $this->isInstanceOf('\Closure'))
294+
->with($list, null, null, null, $this->isInstanceOf(\Closure::class))
295295
->willReturnCallback(function ($list, $preferred, $label, $index, $groupBy) {
296296
return new ChoiceListView((array) $groupBy((object) ['property' => 'group']));
297297
});
@@ -305,7 +305,7 @@ public function testCreateViewGroupsAsPropertyPathInstance()
305305

306306
$this->decoratedFactory->expects($this->once())
307307
->method('createView')
308-
->with($list, null, null, null, $this->isInstanceOf('\Closure'))
308+
->with($list, null, null, null, $this->isInstanceOf(\Closure::class))
309309
->willReturnCallback(function ($list, $preferred, $label, $index, $groupBy) {
310310
return new ChoiceListView((array) $groupBy((object) ['property' => 'group']));
311311
});
@@ -320,7 +320,7 @@ public function testCreateViewAssumeNullIfGroupsPropertyPathUnreadable()
320320

321321
$this->decoratedFactory->expects($this->once())
322322
->method('createView')
323-
->with($list, null, null, null, $this->isInstanceOf('\Closure'))
323+
->with($list, null, null, null, $this->isInstanceOf(\Closure::class))
324324
->willReturnCallback(function ($list, $preferred, $label, $index, $groupBy) {
325325
return new ChoiceListView((array) $groupBy((object) ['group' => null]));
326326
});
@@ -334,7 +334,7 @@ public function testCreateViewAttrAsPropertyPath()
334334

335335
$this->decoratedFactory->expects($this->once())
336336
->method('createView')
337-
->with($list, null, null, null, null, $this->isInstanceOf('\Closure'))
337+
->with($list, null, null, null, null, $this->isInstanceOf(\Closure::class))
338338
->willReturnCallback(function ($list, $preferred, $label, $index, $groupBy, $attr) {
339339
return new ChoiceListView((array) $attr((object) ['property' => 'attr']));
340340
});
@@ -348,7 +348,7 @@ public function testCreateViewAttrAsPropertyPathInstance()
348348

349349
$this->decoratedFactory->expects($this->once())
350350
->method('createView')
351-
->with($list, null, null, null, null, $this->isInstanceOf('\Closure'))
351+
->with($list, null, null, null, null, $this->isInstanceOf(\Closure::class))
352352
->willReturnCallback(function ($list, $preferred, $label, $index, $groupBy, $attr) {
353353
return new ChoiceListView((array) $attr((object) ['property' => 'attr']));
354354
});

Tests/ChoiceList/Loader/CallbackChoiceLoaderTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Form\Tests\ChoiceList\Loader;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
1516
use Symfony\Component\Form\ChoiceList\LazyChoiceList;
1617
use Symfony\Component\Form\ChoiceList\Loader\CallbackChoiceLoader;
1718

@@ -63,7 +64,7 @@ public static function setUpBeforeClass(): void
6364

6465
public function testLoadChoiceList()
6566
{
66-
$this->assertInstanceOf('\Symfony\Component\Form\ChoiceList\ChoiceListInterface', self::$loader->loadChoiceList(self::$value));
67+
$this->assertInstanceOf(ChoiceListInterface::class, self::$loader->loadChoiceList(self::$value));
6768
}
6869

6970
public function testLoadChoiceListOnlyOnce()

Tests/CompoundFormTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public function testAddWithoutType()
227227

228228
public function testAddUsingNameButNoType()
229229
{
230-
$this->form = $this->getBuilder('name', null, '\stdClass')
230+
$this->form = $this->getBuilder('name', null, \stdClass::class)
231231
->setCompound(true)
232232
->setDataMapper($this->getDataMapper())
233233
->getForm();
@@ -236,7 +236,7 @@ public function testAddUsingNameButNoType()
236236

237237
$this->factory->expects($this->once())
238238
->method('createForProperty')
239-
->with('\stdClass', 'foo')
239+
->with(\stdClass::class, 'foo')
240240
->willReturn($child);
241241

242242
$this->form->add('foo');
@@ -248,7 +248,7 @@ public function testAddUsingNameButNoType()
248248

249249
public function testAddUsingNameButNoTypeAndOptions()
250250
{
251-
$this->form = $this->getBuilder('name', null, '\stdClass')
251+
$this->form = $this->getBuilder('name', null, \stdClass::class)
252252
->setCompound(true)
253253
->setDataMapper($this->getDataMapper())
254254
->getForm();
@@ -257,7 +257,7 @@ public function testAddUsingNameButNoTypeAndOptions()
257257

258258
$this->factory->expects($this->once())
259259
->method('createForProperty')
260-
->with('\stdClass', 'foo', null, [
260+
->with(\stdClass::class, 'foo', null, [
261261
'bar' => 'baz',
262262
'auto_initialize' => false,
263263
])
@@ -348,7 +348,7 @@ public function testAddMapsViewDataToFormIfInitialized()
348348
$child = $this->getBuilder()->getForm();
349349
$mapper->expects($this->once())
350350
->method('mapDataToForms')
351-
->with('bar', $this->isInstanceOf('\RecursiveIteratorIterator'))
351+
->with('bar', $this->isInstanceOf(\RecursiveIteratorIterator::class))
352352
->willReturnCallback(function ($data, \RecursiveIteratorIterator $iterator) use ($child) {
353353
$this->assertInstanceOf('Symfony\Component\Form\Util\InheritDataAwareIterator', $iterator->getInnerIterator());
354354
$this->assertSame([$child->getName() => $child], iterator_to_array($iterator));
@@ -438,7 +438,7 @@ public function testSetDataMapsViewDataToChildren()
438438

439439
$mapper->expects($this->once())
440440
->method('mapDataToForms')
441-
->with('bar', $this->isInstanceOf('\RecursiveIteratorIterator'))
441+
->with('bar', $this->isInstanceOf(\RecursiveIteratorIterator::class))
442442
->willReturnCallback(function ($data, \RecursiveIteratorIterator $iterator) use ($child1, $child2) {
443443
$this->assertInstanceOf('Symfony\Component\Form\Util\InheritDataAwareIterator', $iterator->getInnerIterator());
444444
$this->assertSame(['firstName' => $child1, 'lastName' => $child2], iterator_to_array($iterator));

Tests/Extension/Core/EventListener/MergeCollectionListenerArrayObjectTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ protected function getData(array $data)
2424

2525
protected function getBuilder($name = 'name')
2626
{
27-
return new FormBuilder($name, '\ArrayObject', new EventDispatcher(), (new FormFactoryBuilder())->getFormFactory());
27+
return new FormBuilder($name, \ArrayObject::class, new EventDispatcher(), (new FormFactoryBuilder())->getFormFactory());
2828
}
2929
}

Tests/Extension/Csrf/EventListener/CsrfValidationListenerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Form\FormBuilder;
1919
use Symfony\Component\Form\FormEvent;
2020
use Symfony\Component\Form\FormFactoryBuilder;
21+
use Symfony\Component\Form\Util\ServerParams;
2122
use Symfony\Component\Security\Csrf\CsrfTokenManager;
2223

2324
class CsrfValidationListenerTest extends TestCase
@@ -76,7 +77,7 @@ public function testArrayCsrfToken()
7677
public function testMaxPostSizeExceeded()
7778
{
7879
$serverParams = $this
79-
->getMockBuilder('\Symfony\Component\Form\Util\ServerParams')
80+
->getMockBuilder(ServerParams::class)
8081
->disableOriginalConstructor()
8182
->getMock()
8283
;

Tests/Guess/GuessTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testGetBestGuessReturnsGuessWithHighestConfidence()
3131

3232
public function testGuessExpectsValidConfidence()
3333
{
34-
$this->expectException('\InvalidArgumentException');
34+
$this->expectException(\InvalidArgumentException::class);
3535
new TestGuess(5);
3636
}
3737
}

Tests/ResolvedFormTypeTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public function testCreateBuilder()
156156
public function testCreateBuilderWithDataClassOption()
157157
{
158158
$givenOptions = ['data_class' => 'Foo'];
159-
$resolvedOptions = ['data_class' => '\stdClass'];
159+
$resolvedOptions = ['data_class' => \stdClass::class];
160160
$optionsResolver = $this->getMockBuilder('Symfony\Component\OptionsResolver\OptionsResolver')->getMock();
161161

162162
$this->resolvedType = $this->getMockBuilder('Symfony\Component\Form\ResolvedFormType')
@@ -178,7 +178,7 @@ public function testCreateBuilderWithDataClassOption()
178178

179179
$this->assertSame($this->resolvedType, $builder->getType());
180180
$this->assertSame($resolvedOptions, $builder->getOptions());
181-
$this->assertSame('\stdClass', $builder->getDataClass());
181+
$this->assertSame(\stdClass::class, $builder->getDataClass());
182182
}
183183

184184
public function testFailsCreateBuilderOnInvalidFormOptionsResolution()

0 commit comments

Comments
 (0)