Skip to content

Commit

Permalink
Style, missing getReflectionProperties()Property() that were renamed.
Browse files Browse the repository at this point in the history
  • Loading branch information
beberlei committed Oct 10, 2024
1 parent 5af3b15 commit a885445
Show file tree
Hide file tree
Showing 12 changed files with 46 additions and 16 deletions.
19 changes: 16 additions & 3 deletions src/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Doctrine\ORM\Cache\Exception\NonCacheableEntityAssociation;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Id\AbstractIdGenerator;
use Doctrine\ORM\Mapping\PropertyAccessors\AccessorFactory;
use Doctrine\ORM\Mapping\PropertyAccessors\EmbeddablePropertyAccessor;
use Doctrine\ORM\Mapping\PropertyAccessors\EnumPropertyAccessor;
use Doctrine\ORM\Mapping\PropertyAccessors\ObjectCastPropertyAccessor;
Expand All @@ -22,7 +21,6 @@
use Doctrine\ORM\Mapping\PropertyAccessors\TypedNoDefaultPropertyAccessor;
use Doctrine\Persistence\Mapping\ClassMetadata as PersistenceClassMetadata;
use Doctrine\Persistence\Mapping\ReflectionService;
use Doctrine\Persistence\Reflection\EnumReflectionProperty;
use InvalidArgumentException;
use LogicException;
use ReflectionClass;
Expand Down Expand Up @@ -571,6 +569,16 @@ public function __construct(public string $name, NamingStrategy|null $namingStra
* @return ReflectionProperty[]|null[] An array of ReflectionProperty instances.
* @psalm-return array<ReflectionProperty|null>

Check failure on line 570 in src/Mapping/ClassMetadata.php

View workflow job for this annotation

GitHub Actions / Static Analysis with Psalm (default)

InvalidReturnType

src/Mapping/ClassMetadata.php:570:22: InvalidReturnType: The declared return type 'array<array-key, ReflectionProperty|null>' for Doctrine\ORM\Mapping\ClassMetadata::getReflectionProperties is incorrect, got 'Doctrine\ORM\Mapping\LegacyReflectionFields<string, ReflectionProperty>|array<string, ReflectionProperty>' (see https://psalm.dev/011)

Check failure on line 570 in src/Mapping/ClassMetadata.php

View workflow job for this annotation

GitHub Actions / Static Analysis with Psalm (3.8.2)

InvalidReturnType

src/Mapping/ClassMetadata.php:570:22: InvalidReturnType: The declared return type 'array<array-key, ReflectionProperty|null>' for Doctrine\ORM\Mapping\ClassMetadata::getReflectionProperties is incorrect, got 'Doctrine\ORM\Mapping\LegacyReflectionFields<string, ReflectionProperty>|array<string, ReflectionProperty>' (see https://psalm.dev/011)
*/
public function getReflectionProperties(): array
{
return $this->reflFields;

Check failure on line 574 in src/Mapping/ClassMetadata.php

View workflow job for this annotation

GitHub Actions / Static Analysis with Psalm (default)

InvalidReturnStatement

src/Mapping/ClassMetadata.php:574:16: InvalidReturnStatement: The inferred type 'Doctrine\ORM\Mapping\LegacyReflectionFields<string, ReflectionProperty>|array<string, ReflectionProperty>' does not match the declared return type 'array<array-key, ReflectionProperty|null>' for Doctrine\ORM\Mapping\ClassMetadata::getReflectionProperties (see https://psalm.dev/128)

Check failure on line 574 in src/Mapping/ClassMetadata.php

View workflow job for this annotation

GitHub Actions / Static Analysis with Psalm (3.8.2)

InvalidReturnStatement

src/Mapping/ClassMetadata.php:574:16: InvalidReturnStatement: The inferred type 'Doctrine\ORM\Mapping\LegacyReflectionFields<string, ReflectionProperty>|array<string, ReflectionProperty>' does not match the declared return type 'array<array-key, ReflectionProperty|null>' for Doctrine\ORM\Mapping\ClassMetadata::getReflectionProperties (see https://psalm.dev/128)
}

/**
* Gets the ReflectionProperties of the mapped class.
*
* @return PropertyAccessor[] An array of PropertyAccessor instances.
*/
public function getPropertyAccessors(): array
{
return $this->propertyAccessors;
Expand All @@ -579,9 +587,14 @@ public function getPropertyAccessors(): array
/**
* Gets a ReflectionProperty for a specific field of the mapped class.
*/
public function getReflectionProperty(string $name): ReflectionProperty|null
{
return $this->reflFields[$name];
}

public function getPropertyAccessor(string $name): PropertyAccessor|null
{
return $this->propertyAccessors[$name];
return $this->propertyAccessors[$name] ?? null;
}

/**
Expand Down
17 changes: 12 additions & 5 deletions src/Mapping/LegacyReflectionFields.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
<?php

declare(strict_types=1);

namespace Doctrine\ORM\Mapping;

use Doctrine\ORM\Mapping\PropertyAccessors\EmbeddablePropertyAccessor;
use ArrayAccess;
use Doctrine\Persistence\Mapping\ReflectionService;
use Doctrine\Persistence\Reflection\EnumReflectionProperty;
use ReflectionClass;
use IteratorAggregate;
use OutOfBoundsException;
use ReflectionProperty;
use Traversable;

class LegacyReflectionFields implements \ArrayAccess, \IteratorAggregate
use function array_keys;
use function str_contains;
use function str_replace;

class LegacyReflectionFields implements ArrayAccess, IteratorAggregate

Check failure on line 19 in src/Mapping/LegacyReflectionFields.php

View workflow job for this annotation

GitHub Actions / Static Analysis with Psalm (default)

MissingTemplateParam

src/Mapping/LegacyReflectionFields.php:19:41: MissingTemplateParam: Doctrine\ORM\Mapping\LegacyReflectionFields has missing template params when extending ArrayAccess, expecting 2 (see https://psalm.dev/182)

Check failure on line 19 in src/Mapping/LegacyReflectionFields.php

View workflow job for this annotation

GitHub Actions / Static Analysis with Psalm (default)

MissingTemplateParam

src/Mapping/LegacyReflectionFields.php:19:54: MissingTemplateParam: Doctrine\ORM\Mapping\LegacyReflectionFields has missing template params when extending IteratorAggregate, expecting 2 (see https://psalm.dev/182)

Check failure on line 19 in src/Mapping/LegacyReflectionFields.php

View workflow job for this annotation

GitHub Actions / Static Analysis with Psalm (3.8.2)

MissingTemplateParam

src/Mapping/LegacyReflectionFields.php:19:41: MissingTemplateParam: Doctrine\ORM\Mapping\LegacyReflectionFields has missing template params when extending ArrayAccess, expecting 2 (see https://psalm.dev/182)

Check failure on line 19 in src/Mapping/LegacyReflectionFields.php

View workflow job for this annotation

GitHub Actions / Static Analysis with Psalm (3.8.2)

MissingTemplateParam

src/Mapping/LegacyReflectionFields.php:19:54: MissingTemplateParam: Doctrine\ORM\Mapping\LegacyReflectionFields has missing template params when extending IteratorAggregate, expecting 2 (see https://psalm.dev/182)
{
private array $reflFields = [];

Check failure on line 21 in src/Mapping/LegacyReflectionFields.php

View workflow job for this annotation

GitHub Actions / coding-standards / Coding Standards (8.3)

@var annotation of property \Doctrine\ORM\Mapping\LegacyReflectionFields::$reflFields does not specify type hint for its items.

Expand Down Expand Up @@ -55,7 +62,7 @@ public function offsetGet($field): mixed
if ($this->classMetadata->fieldMappings[$field]->originalField !== null) {
$parentField = str_replace('.' . $fieldName, '', $field);

if (!str_contains($parentField, '.')) {
if (! str_contains($parentField, '.')) {
$parentClass = $this->classMetadata->name;
} else {
$parentClass = $this->classMetadata->fieldMappings[$parentField]->originalClass;
Expand All @@ -72,7 +79,7 @@ public function offsetGet($field): mixed
return $this->reflFields[$field];
}

throw new \OutOfBoundsException('Unknown field: ' . $this->classMetadata->name .' ::$' . $field);
throw new OutOfBoundsException('Unknown field: ' . $this->classMetadata->name . ' ::$' . $field);
}

public function offsetSet($offset, $value): void

Check failure on line 85 in src/Mapping/LegacyReflectionFields.php

View workflow job for this annotation

GitHub Actions / coding-standards / Coding Standards (8.3)

Method \Doctrine\ORM\Mapping\LegacyReflectionFields::offsetSet() does not have parameter type hint nor @param annotation for its parameter $offset.

Check failure on line 85 in src/Mapping/LegacyReflectionFields.php

View workflow job for this annotation

GitHub Actions / coding-standards / Coding Standards (8.3)

Method \Doctrine\ORM\Mapping\LegacyReflectionFields::offsetSet() does not have parameter type hint nor @param annotation for its parameter $value.
Expand Down
2 changes: 2 additions & 0 deletions src/Mapping/PropertyAccessors/EmbeddablePropertyAccessor.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Doctrine\ORM\Mapping\PropertyAccessors;

use Doctrine\Instantiator\Instantiator;
Expand Down
8 changes: 7 additions & 1 deletion src/Mapping/PropertyAccessors/EnumPropertyAccessor.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
<?php

declare(strict_types=1);

namespace Doctrine\ORM\Mapping\PropertyAccessors;

use BackedEnum;

use function array_map;
use function is_array;
use function reset;

class EnumPropertyAccessor implements PropertyAccessor
{
public function __construct(private PropertyAccessor $parent, private string $enumType)
Expand Down Expand Up @@ -46,7 +52,7 @@ private function fromEnum($enum)
*
* @return ($value is int|string|BackedEnum ? BackedEnum : BackedEnum[])
*/
private function toEnum($value)
private function toEnum(int|string|array|BackedEnum $value)
{
if ($value instanceof BackedEnum) {
return $value;
Expand Down
2 changes: 2 additions & 0 deletions src/Mapping/PropertyAccessors/ObjectCastPropertyAccessor.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Doctrine\ORM\Mapping\PropertyAccessors;

use Doctrine\ORM\Proxy\InternalProxy;
Expand Down
2 changes: 2 additions & 0 deletions src/Mapping/PropertyAccessors/PropertyAccessor.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Doctrine\ORM\Mapping\PropertyAccessors;

interface PropertyAccessor
Expand Down
2 changes: 2 additions & 0 deletions src/Mapping/PropertyAccessors/ReadonlyAccessor.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Doctrine\ORM\Mapping\PropertyAccessors;

use InvalidArgumentException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Doctrine\ORM\Mapping\PropertyAccessors;

use Closure;
Expand Down
1 change: 0 additions & 1 deletion src/Proxy/ProxyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

use function array_combine;
use function array_flip;
use function array_intersect_key;
use function assert;
use function bin2hex;
use function chmod;
Expand Down
5 changes: 0 additions & 5 deletions tests/Tests/ORM/Functional/ValueObjectsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Doctrine\Tests\ORM\Functional;

use DateTime;
use Doctrine\Common\Reflection\RuntimePublicReflectionProperty as CommonRuntimePublicReflectionProperty;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\DiscriminatorColumn;
use Doctrine\ORM\Mapping\DiscriminatorMap;
Expand All @@ -17,15 +16,11 @@
use Doctrine\ORM\Mapping\InheritanceType;
use Doctrine\ORM\Mapping\MappedSuperclass;
use Doctrine\ORM\Mapping\MappingException;
use Doctrine\ORM\Mapping\ReflectionEmbeddedProperty;
use Doctrine\ORM\Query\QueryException;
use Doctrine\Persistence\Reflection\RuntimeReflectionProperty;
use Doctrine\Tests\OrmFunctionalTestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;
use ReflectionProperty;

use function class_exists;
use function sprintf;

#[Group('DDC-93')]
Expand Down
1 change: 0 additions & 1 deletion tests/Tests/ORM/Mapping/ClassMetadataLoadEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Doctrine\ORM\Mapping\Table;
use Doctrine\Tests\OrmTestCase;
use PHPUnit\Framework\Attributes\Group;
use ReflectionProperty;

class ClassMetadataLoadEventTest extends OrmTestCase
{
Expand Down
1 change: 1 addition & 0 deletions tests/Tests/ORM/Mapping/ClassMetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
use ReflectionClass;
use stdClass;

use function array_keys;
use function assert;
use function count;
use function serialize;
Expand Down

0 comments on commit a885445

Please sign in to comment.