Skip to content

Commit c03bcbe

Browse files
committed
Use ::class keyword when possible
1 parent b65e0bb commit c03bcbe

File tree

3 files changed

+28
-28
lines changed

3 files changed

+28
-28
lines changed

PropertyAccessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ private function getPropertyPath($propertyPath): PropertyPath
667667
*/
668668
public static function createCache(string $namespace, int $defaultLifetime, string $version, LoggerInterface $logger = null)
669669
{
670-
if (!class_exists('Symfony\Component\Cache\Adapter\ApcuAdapter')) {
670+
if (!class_exists(ApcuAdapter::class)) {
671671
throw new \LogicException(sprintf('The Symfony Cache component must be installed to use "%s()".', __METHOD__));
672672
}
673673

Tests/PropertyAccessorCollectionTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public function testSetValueCallsAdderAndRemoverForNestedCollections()
148148

149149
public function testSetValueFailsIfNoAdderNorRemoverFound()
150150
{
151-
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
151+
$this->expectException(\Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException::class);
152152
$this->expectExceptionMessageMatches('/Could not determine access type for property "axes" in class "Mock_PropertyAccessorCollectionTest_CarNoAdderAndRemover_[^"]*"./');
153153
$car = $this->getMockBuilder(__CLASS__.'_CarNoAdderAndRemover')->getMock();
154154
$axesBefore = $this->getContainer([1 => 'second', 3 => 'fourth']);
@@ -187,7 +187,7 @@ public function testIsWritableReturnsFalseIfNoAdderNorRemoverExists()
187187

188188
public function testSetValueFailsIfAdderAndRemoverExistButValueIsNotTraversable()
189189
{
190-
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
190+
$this->expectException(\Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException::class);
191191
$this->expectExceptionMessageMatches('/The property "axes" in class "Symfony\\\Component\\\PropertyAccess\\\Tests\\\PropertyAccessorCollectionTest_Car" can be defined with the methods "addAxis\(\)", "removeAxis\(\)" but the new value must be an array or an instance of \\\Traversable\./');
192192
$car = new PropertyAccessorCollectionTest_Car();
193193

Tests/PropertyAccessorTest.php

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function testGetValue($objectOrArray, $path, $value)
102102
*/
103103
public function testGetValueThrowsExceptionIfPropertyNotFound($objectOrArray, $path)
104104
{
105-
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
105+
$this->expectException(\Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException::class);
106106
$this->propertyAccessor->getValue($objectOrArray, $path);
107107
}
108108

@@ -129,7 +129,7 @@ public function testGetValueThrowsNoExceptionIfIndexNotFound($objectOrArray, $pa
129129
*/
130130
public function testGetValueThrowsExceptionIfIndexNotFoundAndIndexExceptionsEnabled($objectOrArray, $path)
131131
{
132-
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchIndexException');
132+
$this->expectException(NoSuchIndexException::class);
133133
$this->propertyAccessor = new PropertyAccessor(false, true);
134134
$this->propertyAccessor->getValue($objectOrArray, $path);
135135
}
@@ -158,7 +158,7 @@ public function testGetValueThrowsExceptionIfUninitializedPropertyWithGetter()
158158
*/
159159
public function testGetValueThrowsExceptionIfUninitializedPropertyWithGetterOfAnonymousClass()
160160
{
161-
$this->expectException('Symfony\Component\PropertyAccess\Exception\AccessException');
161+
$this->expectException(\Symfony\Component\PropertyAccess\Exception\AccessException::class);
162162
$this->expectExceptionMessage('The method "class@anonymous::getUninitialized()" returned "null", but expected type "array". Did you forget to initialize a property or to make the return type nullable using "?array"?');
163163

164164
$object = eval('return new class() {
@@ -178,7 +178,7 @@ public function getUninitialized(): array
178178
*/
179179
public function testGetValueThrowsExceptionIfUninitializedPropertyWithGetterOfAnonymousStdClass()
180180
{
181-
$this->expectException('Symfony\Component\PropertyAccess\Exception\AccessException');
181+
$this->expectException(\Symfony\Component\PropertyAccess\Exception\AccessException::class);
182182
$this->expectExceptionMessage('The method "stdClass@anonymous::getUninitialized()" returned "null", but expected type "array". Did you forget to initialize a property or to make the return type nullable using "?array"?');
183183

184184
$object = eval('return new class() extends \stdClass {
@@ -198,7 +198,7 @@ public function getUninitialized(): array
198198
*/
199199
public function testGetValueThrowsExceptionIfUninitializedPropertyWithGetterOfAnonymousChildClass()
200200
{
201-
$this->expectException('Symfony\Component\PropertyAccess\Exception\AccessException');
201+
$this->expectException(\Symfony\Component\PropertyAccess\Exception\AccessException::class);
202202
$this->expectExceptionMessage('The method "Symfony\Component\PropertyAccess\Tests\Fixtures\UninitializedPrivateProperty@anonymous::getUninitialized()" returned "null", but expected type "array". Did you forget to initialize a property or to make the return type nullable using "?array"?');
203203

204204
$object = eval('return new class() extends \Symfony\Component\PropertyAccess\Tests\Fixtures\UninitializedPrivateProperty {};');
@@ -208,7 +208,7 @@ public function testGetValueThrowsExceptionIfUninitializedPropertyWithGetterOfAn
208208

209209
public function testGetValueThrowsExceptionIfNotArrayAccess()
210210
{
211-
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchIndexException');
211+
$this->expectException(NoSuchIndexException::class);
212212
$this->propertyAccessor->getValue(new \stdClass(), '[index]');
213213
}
214214

@@ -257,7 +257,7 @@ public function testGetValueNotModifyObjectException()
257257

258258
public function testGetValueDoesNotReadMagicCallByDefault()
259259
{
260-
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
260+
$this->expectException(\Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException::class);
261261
$this->propertyAccessor->getValue(new TestClassMagicCall('Bernhard'), 'magicCallProperty');
262262
}
263263

@@ -281,7 +281,7 @@ public function testGetValueReadsMagicCallThatReturnsConstant()
281281
*/
282282
public function testGetValueThrowsExceptionIfNotObjectOrArray($objectOrArray, $path)
283283
{
284-
$this->expectException('Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException');
284+
$this->expectException(\Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException::class);
285285
$this->expectExceptionMessage('PropertyAccessor requires a graph of objects or arrays to operate on');
286286
$this->propertyAccessor->getValue($objectOrArray, $path);
287287
}
@@ -301,7 +301,7 @@ public function testSetValue($objectOrArray, $path)
301301
*/
302302
public function testSetValueThrowsExceptionIfPropertyNotFound($objectOrArray, $path)
303303
{
304-
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
304+
$this->expectException(\Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException::class);
305305
$this->propertyAccessor->setValue($objectOrArray, $path, 'Updated');
306306
}
307307

@@ -328,7 +328,7 @@ public function testSetValueThrowsNoExceptionIfIndexNotFoundAndIndexExceptionsEn
328328

329329
public function testSetValueThrowsExceptionIfNotArrayAccess()
330330
{
331-
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchIndexException');
331+
$this->expectException(NoSuchIndexException::class);
332332
$object = new \stdClass();
333333

334334
$this->propertyAccessor->setValue($object, '[index]', 'Updated');
@@ -345,15 +345,15 @@ public function testSetValueUpdatesMagicSet()
345345

346346
public function testSetValueThrowsExceptionIfThereAreMissingParameters()
347347
{
348-
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
348+
$this->expectException(\Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException::class);
349349
$object = new TestClass('Bernhard');
350350

351351
$this->propertyAccessor->setValue($object, 'publicAccessorWithMoreRequiredParameters', 'Updated');
352352
}
353353

354354
public function testSetValueDoesNotUpdateMagicCallByDefault()
355355
{
356-
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
356+
$this->expectException(\Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException::class);
357357
$author = new TestClassMagicCall('Bernhard');
358358

359359
$this->propertyAccessor->setValue($author, 'magicCallProperty', 'Updated');
@@ -375,7 +375,7 @@ public function testSetValueUpdatesMagicCallIfEnabled()
375375
*/
376376
public function testSetValueThrowsExceptionIfNotObjectOrArray($objectOrArray, $path)
377377
{
378-
$this->expectException('Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException');
378+
$this->expectException(\Symfony\Component\PropertyAccess\Exception\UnexpectedTypeException::class);
379379
$this->expectExceptionMessage('PropertyAccessor requires a graph of objects or arrays to operate on');
380380
$this->propertyAccessor->setValue($objectOrArray, $path, 'value');
381381
}
@@ -611,7 +611,7 @@ public function testIsWritableForReferenceChainIssue($object, $path, $value)
611611

612612
public function testThrowTypeError()
613613
{
614-
$this->expectException('Symfony\Component\PropertyAccess\Exception\InvalidArgumentException');
614+
$this->expectException(\Symfony\Component\PropertyAccess\Exception\InvalidArgumentException::class);
615615
$this->expectExceptionMessage('Expected argument of type "DateTime", "string" given at property path "date"');
616616
$object = new TypeHinted();
617617

@@ -620,7 +620,7 @@ public function testThrowTypeError()
620620

621621
public function testThrowTypeErrorWithNullArgument()
622622
{
623-
$this->expectException('Symfony\Component\PropertyAccess\Exception\InvalidArgumentException');
623+
$this->expectException(\Symfony\Component\PropertyAccess\Exception\InvalidArgumentException::class);
624624
$this->expectExceptionMessage('Expected argument of type "DateTime", "null" given');
625625
$object = new TypeHinted();
626626

@@ -672,7 +672,7 @@ public function testAttributeWithSpecialChars()
672672

673673
public function testThrowTypeErrorWithInterface()
674674
{
675-
$this->expectException('Symfony\Component\PropertyAccess\Exception\InvalidArgumentException');
675+
$this->expectException(\Symfony\Component\PropertyAccess\Exception\InvalidArgumentException::class);
676676
$this->expectExceptionMessage('Expected argument of type "Countable", "string" given');
677677
$object = new TypeHinted();
678678

@@ -692,7 +692,7 @@ public function testAnonymousClassRead()
692692

693693
public function testAnonymousClassReadThrowExceptionOnInvalidPropertyPath()
694694
{
695-
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
695+
$this->expectException(\Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException::class);
696696
$obj = $this->generateAnonymousClass('bar');
697697

698698
$this->propertyAccessor->getValue($obj, 'invalid_property');
@@ -752,23 +752,23 @@ public function setFoo($foo)
752752

753753
public function testThrowTypeErrorInsideSetterCall()
754754
{
755-
$this->expectException('TypeError');
755+
$this->expectException(\TypeError::class);
756756
$object = new TestClassTypeErrorInsideCall();
757757

758758
$this->propertyAccessor->setValue($object, 'property', 'foo');
759759
}
760760

761761
public function testDoNotDiscardReturnTypeError()
762762
{
763-
$this->expectException('TypeError');
763+
$this->expectException(\TypeError::class);
764764
$object = new ReturnTyped();
765765

766766
$this->propertyAccessor->setValue($object, 'foos', [new \DateTime()]);
767767
}
768768

769769
public function testDoNotDiscardReturnTypeErrorWhenWriterMethodIsMisconfigured()
770770
{
771-
$this->expectException('TypeError');
771+
$this->expectException(\TypeError::class);
772772
$object = new ReturnTyped();
773773

774774
$this->propertyAccessor->setValue($object, 'name', 'foo');
@@ -818,39 +818,39 @@ public function testAdderAndRemoverArePreferredOverSetterForSameSingularAndPlura
818818

819819
public function testAdderWithoutRemover()
820820
{
821-
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
821+
$this->expectException(\Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException::class);
822822
$this->expectExceptionMessageMatches('/.*The add method "addFoo" in class "Symfony\\\Component\\\PropertyAccess\\\Tests\\\Fixtures\\\TestAdderRemoverInvalidMethods" was found, but the corresponding remove method "removeFoo" was not found\./');
823823
$object = new TestAdderRemoverInvalidMethods();
824824
$this->propertyAccessor->setValue($object, 'foos', [1, 2]);
825825
}
826826

827827
public function testRemoverWithoutAdder()
828828
{
829-
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
829+
$this->expectException(\Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException::class);
830830
$this->expectExceptionMessageMatches('/.*The remove method "removeBar" in class "Symfony\\\Component\\\PropertyAccess\\\Tests\\\Fixtures\\\TestAdderRemoverInvalidMethods" was found, but the corresponding add method "addBar" was not found\./');
831831
$object = new TestAdderRemoverInvalidMethods();
832832
$this->propertyAccessor->setValue($object, 'bars', [1, 2]);
833833
}
834834

835835
public function testAdderAndRemoveNeedsTheExactParametersDefined()
836836
{
837-
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
837+
$this->expectException(\Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException::class);
838838
$this->expectExceptionMessageMatches('/.*The method "addFoo" in class "Symfony\\\Component\\\PropertyAccess\\\Tests\\\Fixtures\\\TestAdderRemoverInvalidArgumentLength" requires 0 arguments, but should accept only 1\./');
839839
$object = new TestAdderRemoverInvalidArgumentLength();
840840
$this->propertyAccessor->setValue($object, 'foo', [1, 2]);
841841
}
842842

843843
public function testSetterNeedsTheExactParametersDefined()
844844
{
845-
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
845+
$this->expectException(\Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException::class);
846846
$this->expectExceptionMessageMatches('/.*The method "setBar" in class "Symfony\\\Component\\\PropertyAccess\\\Tests\\\Fixtures\\\TestAdderRemoverInvalidArgumentLength" requires 2 arguments, but should accept only 1\./');
847847
$object = new TestAdderRemoverInvalidArgumentLength();
848848
$this->propertyAccessor->setValue($object, 'bar', [1, 2]);
849849
}
850850

851851
public function testSetterNeedsPublicAccess()
852852
{
853-
$this->expectException('Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException');
853+
$this->expectException(\Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException::class);
854854
$this->expectExceptionMessageMatches('/.*The method "setFoo" in class "Symfony\\\Component\\\PropertyAccess\\\Tests\\\Fixtures\\\TestClassSetValue" was found but does not have public access./');
855855
$object = new TestClassSetValue(0);
856856
$this->propertyAccessor->setValue($object, 'foo', 1);

0 commit comments

Comments
 (0)