Skip to content

Commit

Permalink
fix: if xml value is set, change value in class metadata (doctrine-ex…
Browse files Browse the repository at this point in the history
  • Loading branch information
gfuentesboost authored and phansys committed Sep 3, 2023
1 parent 52e6411 commit 95f7c90
Show file tree
Hide file tree
Showing 41 changed files with 320 additions and 121 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ a release.
## [Unreleased]
### Changed
- Add conflict with "doctrine/orm" >=2.16 (temporary change until code is fixed)
### Fixed
- References: fixed condition in `XML` Driver that did not allow to retrieve from the entity definition the `mappedBy` and `inversedBy` fields.

### Fixed
- Fix bug collecting metadata for inherited mapped classes
Expand Down
7 changes: 6 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ includes:
- vendor/phpstan/phpstan-phpunit/extension.neon

parameters:
level: 5
level: 6
paths:
- src
- tests
Expand All @@ -13,10 +13,15 @@ parameters:
treatPhpDocTypesAsCertain: false
checkMissingVarTagTypehint: true
checkMissingTypehints: true
# @todo: Remove the "checkGenericClassInNonGenericObjectType" definition.
checkGenericClassInNonGenericObjectType: false
ignoreErrors:
- '#^Property Gedmo\\Tests\\.+\\Fixture\\[^:]+::\$\w+ is never written, only read\.$#'
- '#^Property Gedmo\\Tests\\.+\\Fixture\\[^:]+::\$\w+ is never read, only written\.$#'
- '#^Property Gedmo\\Tests\\.+\\Fixture\\[^:]+::\$\w+ is unused\.$#'
# @todo: Remove the following ignored error when the parameters are correctly declared.
- '#^Method Gedmo\\[^:]+::[^\(]+\(\) has parameter \$\w+ with no value type specified in iterable type array\.$#'

rules:
- PHPStan\Rules\Constants\MissingClassConstantTypehintRule
- PHPStan\Rules\Functions\MissingFunctionParameterTypehintRule
Expand Down
2 changes: 2 additions & 0 deletions schemas/orm/doctrine-extensions-mapping-2-2.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<xs:element name="loggable" type="gedmo:loggable"/>
<xs:element name="soft-deleteable" type="gedmo:soft-deleteable"/>
<xs:element name="uploadable" type="gedmo:uploadable"/>
<xs:element name="reference" type="gedmo:reference"/>
<!-- field -->
<xs:element name="slug" type="gedmo:slug"/>
<xs:element name="translatable" type="gedmo:translatable"/>
Expand Down Expand Up @@ -65,6 +66,7 @@
<xs:complexType name="reference">
<xs:attribute name="type" type="gedmo:reference-type" use="required" />
<xs:attribute name="field" type="xs:string" use="required" />
<xs:attribute name="reference" type="xs:string" use="required" />
<xs:attribute name="identifier" type="xs:string" use="required" />
<xs:attribute name="class" type="xs:string" use="required" />
<xs:attribute name="mappedBy" type="xs:string" use="optional" />
Expand Down
1 change: 1 addition & 0 deletions src/Mapping/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ interface Driver
* Read the extended metadata configuration for a single mapped class.
*
* @param ClassMetadata&(OdmClassMetadata|OrmClassMetadata) $meta
* @param array<string, mixed> $config
*
* @return void
*
Expand Down
4 changes: 4 additions & 0 deletions src/Mapping/Driver/AbstractAnnotationDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ protected function isValidField($meta, $field)
* @param string $name the related object class name
*
* @return string related class name or empty string if does not exist
*
* @phpstan-param class-string|string $name
*
* @phpstan-return class-string|''
*/
protected function getRelatedClassName($metadata, $name)
{
Expand Down
12 changes: 10 additions & 2 deletions src/Mapping/Driver/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ public function setOriginalDriver($driver)
*
* @param string $file the mapping file to load
*
* @return array
* @return array<string, array<string, mixed>|object|null>
*
* @phpstan-return array<class-string, array<string, mixed>|object|null>
*/
abstract protected function _loadMappingFile($file);

Expand All @@ -112,7 +114,9 @@ abstract protected function _loadMappingFile($file);
*
* @param string $className
*
* @return array|object|null
* @return array<string, mixed>|object|null
*
* @phpstan-param class-string $className
*/
protected function _getMapping($className)
{
Expand Down Expand Up @@ -140,6 +144,10 @@ protected function _getMapping($className)
* @param string $name the related object class name
*
* @return string related class name or empty string if does not exist
*
* @phpstan-param class-string|string $name
*
* @phpstan-return class-string|''
*/
protected function getRelatedClassName($metadata, $name)
{
Expand Down
10 changes: 6 additions & 4 deletions src/Mapping/Event/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ public function getObjectState($uow, $object);
* @param ORMUnitOfWork|MongoDBUnitOfWork $uow The UnitOfWork as provided by the object manager
* @param object $object
*
* @return array
* @return array<string, array<int, mixed>|object>
*
* @phpstan-return array<string, array{0: mixed, 1: mixed}|object>
*/
public function getObjectChangeSet($uow, $object);

Expand Down Expand Up @@ -123,7 +125,7 @@ public function recomputeSingleObjectChangeSet($uow, $meta, $object);
*
* @param ORMUnitOfWork|MongoDBUnitOfWork $uow The UnitOfWork as provided by the object manager
*
* @return array
* @return array<int|string, object>
*/
public function getScheduledObjectUpdates($uow);

Expand All @@ -132,7 +134,7 @@ public function getScheduledObjectUpdates($uow);
*
* @param ORMUnitOfWork|MongoDBUnitOfWork $uow The UnitOfWork as provided by the object manager
*
* @return array
* @return array<int|string, object>
*/
public function getScheduledObjectInsertions($uow);

Expand All @@ -141,7 +143,7 @@ public function getScheduledObjectInsertions($uow);
*
* @param ORMUnitOfWork|MongoDBUnitOfWork $uow The UnitOfWork as provided by the object manager
*
* @return array
* @return array<int|string, object>
*/
public function getScheduledObjectDeletions($uow);

Expand Down
2 changes: 1 addition & 1 deletion src/Mapping/ExtensionMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public function __construct(ObjectManager $objectManager, string $extensionNames
*
* @param ClassMetadata&(DocumentClassMetadata|EntityClassMetadata) $meta
*
* @return array the metatada configuration
* @return array<string, mixed> the metatada configuration
*/
public function getExtensionMetadata($meta)
{
Expand Down
4 changes: 3 additions & 1 deletion src/ReferenceIntegrity/Mapping/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ class Validator
/**
* Returns a list of available integrity actions
*
* @return array
* @return string[]
*
* @phpstan-return array<int, self::NULLIFY|self::PULL|self::RESTRICT>
*/
public function getIntegrityActions()
{
Expand Down
4 changes: 2 additions & 2 deletions src/References/Mapping/Driver/Xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ public function readExtendedMetadata($meta, array &$config)
'identifier' => $identifier,
];

if (!$this->_isAttributeSet($element, 'mappedBy')) {
if ($this->_isAttributeSet($element, 'mappedBy')) {
$config[$reference][$field]['mappedBy'] = $this->_getAttribute($element, 'mappedBy');
}
if (!$this->_isAttributeSet($element, 'inversedBy')) {
if ($this->_isAttributeSet($element, 'inversedBy')) {
$config[$reference][$field]['inversedBy'] = $this->_getAttribute($element, 'inversedBy');
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/References/Mapping/Event/ReferencesAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface ReferencesAdapter extends AdapterInterface
* @param object $object
* @param bool $single
*
* @return array|string|int|null array or single identifier
* @return array<int|string, mixed>|string|int|null array or single identifier
*/
public function getIdentifier($om, $object, $single = true);

Expand All @@ -52,7 +52,7 @@ public function getSingleReference($om, $class, $identifier);
* @param object $object
* @param bool $single
*
* @return array|string|int|null array or single identifier
* @return array<int|string, mixed>|string|int|null array or single identifier
*/
public function extractIdentifier($om, $object, $single = true);
}
2 changes: 1 addition & 1 deletion src/Sluggable/Mapping/Event/SluggableAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ interface SluggableAdapter extends AdapterInterface
* @param string $slug
* @phpstan-param SluggableConfiguration $config
*
* @return array
* @return array<int, array<string, mixed>>
*/
public function getSimilarSlugs($object, $meta, array $config, $slug);

Expand Down
6 changes: 4 additions & 2 deletions src/SoftDeleteable/Filter/ODM/SoftDeleteableFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ class SoftDeleteableFilter extends BsonFilter
/**
* Gets the criteria part to add to a query.
*
* @return array The criteria array, if there is available, empty array otherwise
* @return array<string, array<int, array<string, array<string, \DateTime>|null>>|null> The criteria array, if there is available, empty array otherwise
*
* @phpstan-return array<string, array<int, array<string, array{'$gt': \DateTime}|null>>|null>
*/
public function addFilterCriteria(ClassMetadata $targetEntity): array
{
Expand Down Expand Up @@ -96,7 +98,7 @@ public function enableForDocument($class)
}

/**
* @return SoftDeleteableListener|null
* @return SoftDeleteableListener
*/
protected function getListener()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Sortable/Entity/Repository/SortableRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function getBySortableGroupsQueryBuilder(array $groupValues = [])
}

/**
* @return array
* @return array<int, object>
*/
public function getBySortableGroups(array $groupValues = [])
{
Expand Down
3 changes: 3 additions & 0 deletions src/Sortable/Mapping/Driver/Yaml.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ protected function isValidField($meta, $field)
return $mapping && in_array($mapping['type'], self::VALID_TYPES, true);
}

/**
* @param iterable<string, array<string, mixed>> $mapping
*/
private function readSortableGroups(iterable $mapping, array &$config): void
{
foreach ($mapping as $field => $fieldMapping) {
Expand Down
3 changes: 3 additions & 0 deletions src/Sortable/Mapping/Event/Adapter/ORM.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ public function updatePositions($relocation, $delta, $config)
$q->getSingleScalarResult();
}

/**
* @param iterable<string, mixed> $groups
*/
private function addGroupWhere(QueryBuilder $qb, ClassMetadata $metadata, iterable $groups): void
{
$i = 1;
Expand Down
10 changes: 5 additions & 5 deletions src/Sortable/SortableListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ protected function persistRelocations(SortableAdapter $ea)
}

/**
* @param array $groups
* @param array<string, mixed> $groups
*
* @return string
*/
Expand Down Expand Up @@ -668,11 +668,11 @@ protected function addRelocation($hash, $class, $groups, $start, $stop, $delta,
}

/**
* @param array $config
* @param ClassMetadata $meta
* @param object $object
* @param ClassMetadata $meta
* @param array<string, array<string, string>> $config
* @param object $object
*
* @return array
* @return array<string, mixed>
*/
protected function getGroups($meta, $config, $object)
{
Expand Down
8 changes: 8 additions & 0 deletions src/Tool/Logging/DBAL/QueryAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ public function getExecutionTimes()

/**
* Create the SQL with mapped parameters
*
* @param array<int|string, mixed>|null $params
* @param array<int|string, string|Type>|null $types
*/
private function generateSql(string $sql, ?array $params, ?array $types): string
{
Expand All @@ -210,6 +213,11 @@ private function generateSql(string $sql, ?array $params, ?array $types): string

/**
* Get the converted parameter list
*
* @param array<int|string, mixed> $params
* @param array<int|string, string|Type> $types
*
* @return array<int|string, mixed>
*/
private function getConvertedParams(array $params, array $types): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function translate($document, $field, $locale, $value)
*
* @param object $document
*
* @return array list of translations in locale groups
* @return array<string, array<string, string>> list of translations in locale groups
*/
public function findTranslations($document)
{
Expand Down Expand Up @@ -203,7 +203,7 @@ public function findObjectByTranslatedField($field, $value, $class)
*
* @param mixed $id primary key value of document
*
* @return array
* @return array<string, array<string, string>>
*/
public function findTranslationsByObjectId($id)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Translatable/Entity/Repository/TranslationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function translate($entity, $field, $locale, $value)
*
* @param object $entity Must implement Translatable
*
* @return array list of translations in locale groups
* @return array<string, array<string, string>> list of translations in locale groups
*/
public function findTranslations($entity)
{
Expand Down Expand Up @@ -199,7 +199,7 @@ public function findObjectByTranslatedField($field, $value, $class)
*
* @param mixed $id primary key value of an entity
*
* @return array
* @return array<string, array<string, string>>
*/
public function findTranslationsByObjectId($id)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Translatable/Mapping/Event/TranslatableAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function getDefaultTranslationClass();
* @phpstan-param class-string $translationClass
* @phpstan-param class-string $objectClass
*
* @return array
* @return array<int, array<string, mixed>>
*/
public function loadTranslations($object, $translationClass, $locale, $objectClass);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function getRootNodesQuery($sortByField = null, $direction = 'asc')

public function getRootNodes($sortByField = null, $direction = 'asc')
{
return $this->getRootNodesQuery($sortByField, $direction)->execute();
return $this->getRootNodesQuery($sortByField, $direction)->getIterator();
}

public function childCount($node = null, $direct = false)
Expand Down Expand Up @@ -137,7 +137,7 @@ public function getChildrenQueryBuilder($node = null, $direct = false, $sortByFi
$qb->field($config['path'])->equals(new Regex($regex));
}

$qb->sort($sortByField ?? $config['path'], 'asc' === $direction ? 'asc' : 'desc');
$qb->sort($sortByField ?? $config['path'], 'asc' === strtolower($direction) ? 'asc' : 'desc');

return $qb;
}
Expand All @@ -150,7 +150,7 @@ public function getChildrenQuery($node = null, $direct = false, $sortByField = n
return $this->getChildrenQueryBuilder($node, $direct, $sortByField, $direction, $includeNode)->getQuery();
}

public function getChildren($node = null, $direct = false, $sortByField = null, $direction = 'asc', $includeNode = false)
public function getChildren($node = null, $direct = false, $sortByField = null, $direction = 'ASC', $includeNode = false)
{
return $this->getChildrenQuery($node, $direct, $sortByField, $direction, $includeNode)->execute();
}
Expand Down
8 changes: 6 additions & 2 deletions src/Tree/Entity/Repository/AbstractTreeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,12 @@ abstract public function getNodesHierarchyQuery($node = null, $direct = false, a
* @param object|null $node If null, all tree nodes will be taken
* @param bool $direct True to take only direct children
* @param string|string[]|null $sortByField Field name or array of fields names to sort by
* @param string|string[] $direction Sort order ('ASC'|'DESC'). If $sortByField is an array, this may also be an array with matching number of elements
* @param string|string[] $direction Sort order ('asc'|'desc'|'ASC'|'DESC'). If $sortByField is an array, this may also be an array with matching number of elements
* @param bool $includeNode Include the root node in results?
*
* @return QueryBuilder QueryBuilder object
*
* @phpstan-param 'asc'|'desc'|'ASC'|'DESC'|array<int, 'asc'|'desc'|'ASC'|'DESC'> $direction
*/
abstract public function getChildrenQueryBuilder($node = null, $direct = false, $sortByField = null, $direction = 'ASC', $includeNode = false);

Expand All @@ -225,10 +227,12 @@ abstract public function getChildrenQueryBuilder($node = null, $direct = false,
* @param object|null $node If null, all tree nodes will be taken
* @param bool $direct True to take only direct children
* @param string|string[]|null $sortByField Field name or array of fields names to sort by
* @param string|string[] $direction Sort order ('ASC'|'DESC'). If $sortByField is an array, this may also be an array with matching number of elements
* @param string|string[] $direction Sort order ('asc'|'desc'|'ASC'|'DESC'). If $sortByField is an array, this may also be an array with matching number of elements
* @param bool $includeNode Include the root node in results?
*
* @return Query Query object
*
* @phpstan-param 'asc'|'desc'|'ASC'|'DESC'|array<int, 'asc'|'desc'|'ASC'|'DESC'> $direction
*/
abstract public function getChildrenQuery($node = null, $direct = false, $sortByField = null, $direction = 'ASC', $includeNode = false);

Expand Down
Loading

0 comments on commit 95f7c90

Please sign in to comment.