-
-
Notifications
You must be signed in to change notification settings - Fork 261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/many to many support #509
Feature/many to many support #509
Conversation
I fixed the cs in #510. We don't work on this library a lot so the more the PR will be small, the easier it will be for us to review ^^ And take a look at the build ;) |
5d79c19
to
ce94043
Compare
I've rebased the code and reverted the style changes. I've also left the deprecation fixes out of this PR as it makes the code harder to review. |
@VincentLanglet I've checked the stan / psalm issues reported by the CI and I can fix them, no problem, but this will make the code changes in this PR even more complex, as there are quite a lot of things to review already. Shall I proceed with the fixes and throw them all in a separate commit? What would be the most convenient way to proceed? |
src/AuditReader.php
Outdated
$tableName = $this->config->getTablePrefix( | ||
).$assoc['joinTable']['name'].$this->config->getTableSuffix(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$tableName = $this->config->getTablePrefix( | |
).$assoc['joinTable']['name'].$this->config->getTableSuffix(); | |
$tableName = $this->config->getTablePrefix() | |
.$assoc['joinTable']['name'] | |
.$this->config->getTableSuffix(); |
src/AuditReader.php
Outdated
$query = 'SELECT '.implode( | ||
', ', | ||
$columnList | ||
).' FROM '.$tableName.' e WHERE '.$whereSQL.' ORDER BY e.'.$this->config->getRevisionFieldName( | ||
).' DESC'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer using sprintf
src/AuditReader.php
Outdated
$tableName = $this->config->getTablePrefix( | ||
).$targetAssoc['joinTable']['name'].$this->config->getTableSuffix(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$tableName = $this->config->getTablePrefix( | |
).$targetAssoc['joinTable']['name'].$this->config->getTableSuffix(); | |
$tableName = $this->config->getTablePrefix() | |
.$targetAssoc['joinTable']['name'] | |
.$this->config->getTableSuffix(); |
src/AuditReader.php
Outdated
$query = 'SELECT '.implode( | ||
', ', | ||
$columnList | ||
).' FROM '.$tableName.' e WHERE '.$whereSQL.' ORDER BY e.'.$this->config->getRevisionFieldName( | ||
).' DESC'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer sprintf
* @return string | ||
* | ||
* @psalm-param ClassMetadata<object> $targetClass | ||
* @psalm-param array{cache?: array, cascade: array<string>, declared?: class-string, fetch: mixed, fieldName: string, id?: bool, inherited?: class-string, indexBy?: string, inversedBy: null|string, isCascadeRemove: bool, isCascadePersist: bool, isCascadeRefresh: bool, isCascadeMerge: bool, isCascadeDetach: bool, isOnDeleteCascade?: bool, isOwningSide: true, joinColumns?: array<array{name: string, referencedColumnName: string, unique?: bool, quoted?: bool, fieldName?: string, onDelete?: string, columnDefinition?: string, nullable?: bool}>, joinColumnFieldNames?: array<string, string>, joinTable?: array, joinTableColumns?: list<mixed>, mappedBy: null|string, orderBy?: array, originalClass?: class-string, originalField?: string, orphanRemoval?: bool, relationToSourceKeyColumns?: array, relationToTargetKeyColumns?: array, sourceEntity: class-string, sourceToTargetKeyColumns?: array<string, string>, targetEntity: class-string, targetToSourceKeyColumns?: array<string, string>, type: int, unique?: bool} $assoc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use @phpstan-import-type AssociationMapping from ... https://github.com/doctrine/orm/blob/2.13.x/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php#L110
instead on the class level.
And then use it in the phpdoc.
@@ -389,6 +426,49 @@ private function getInsertRevisionSQL(ClassMetadata $class): string | |||
return $this->insertRevisionSQL[$class->name]; | |||
} | |||
|
|||
/** | |||
* @param ClassMetadata $class |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @param ClassMetadata $class | |
* @param ClassMetadata<object> $class |
avoid the need of psalm-param
* | ||
* @return string | ||
* | ||
* @psalm-param ClassMetadata<object> $targetClass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We prefer phpstan-param
@@ -403,34 +483,51 @@ private function saveRevisionEntityData(ClassMetadata $class, array $entityData, | |||
if ($class->isInheritanceTypeJoined() && $class->isInheritedAssociation($field)) { | |||
continue; | |||
} | |||
if ( | |||
($assoc['type'] & ClassMetadata::TO_ONE) === 0 | |||
if (!(($assoc['type'] & ClassMetadata::TO_ONE) === 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change !($a || $b ||$c) to !a && !b && !c
Yes please fix the issues. Lot of them where already fix on some others places of the code with some if checks or some assert. You can do the same. |
Oh my, thanks for the ultra fast reply, I didn't mean to push ;) I will fix all issues and will come back to you after everything will pass green |
Could you please rebase your PR and fix merge conflicts? |
Any issue @pietaj ? :) |
Code ported from halilibrahim@862974f thx @halilibrahim§
Code ported from halilibrahim@474a29c thx @halilibrahim
Code ported from halilibrahim@20e703c thx @halilibrahim
ce94043
to
1e5aa67
Compare
My only issue was my day job :) did the requested psalm / phpstan compliance cleanup and the requested changes |
Seems like build is still failing |
That's odd ... both rector and phpstan pass on dev machine. I'll have a closer look |
Tru to update your dependencies maybe ? |
yeah, thanks for the tip. Outdated dependencies, I'll rerun and fix the rest |
@VincentLanglet one of the failing checks is linked with rector, failing with
I did some quick checks and the error is linked with phpstan/phpstan bumping from |
Yes, ignore rector for now. FYI, error already reported: rectorphp/rector#7509, waiting for a fix. (The most you can do is upgrade to rector ^0.14, to ensure we will get the fix. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's ok for me, except some formatting issues.
Is this PR ok for you @jordisala1991 ?
src/AuditReader.php
Outdated
$tableAlias = $classMetadata->isInheritanceTypeJoined() && $classMetadata->isInheritedField( | ||
$field | ||
) && !$classMetadata->isIdentifier($field) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reformatting is weird. I would prefer
$tableAlias = $classMetadata->isInheritanceTypeJoined() && $classMetadata->isInheritedField( | |
$field | |
) && !$classMetadata->isIdentifier($field) | |
$tableAlias = $classMetadata->isInheritanceTypeJoined() | |
&& $classMetadata->isInheritedField($field) | |
&& !$classMetadata->isIdentifier($field) |
src/AuditReader.php
Outdated
$tableAlias = $classMetadata->isInheritanceTypeJoined() && $classMetadata->isInheritedField( | ||
$field | ||
) && !$classMetadata->isIdentifier($field) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$tableAlias = $classMetadata->isInheritanceTypeJoined() && $classMetadata->isInheritedField( | |
$field | |
) && !$classMetadata->isIdentifier($field) | |
$tableAlias = $classMetadata->isInheritanceTypeJoined() | |
&& $classMetadata->isInheritedField($field) | |
&& !$classMetadata->isIdentifier($field) |
src/AuditReader.php
Outdated
'INNER JOIN '.$tableName.' e ON r.id = e.'.$this->config->getRevisionFieldName( | ||
).' WHERE '.$whereSQL.' ORDER BY r.id DESC'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this formatting is weird
src/AuditReader.php
Outdated
$otherEntityAssoc = $this->em->getClassMetadata( | ||
$targetEntity | ||
)->associationMappings[$mappedBy]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this formatting is weird
* @param ClassMetadata $class | ||
* @param array<string, mixed> $assoc | ||
* | ||
* @psalm-param ClassMetadata<object> $targetClass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @psalm-param ClassMetadata<object> $targetClass | |
* @phpstan-param ClassMetadata<object> $targetClass |
&& isset($assoc['relationToSourceKeyColumns'], $assoc['relationToTargetKeyColumns'], $assoc['joinTable']['name'])) { | ||
$placeholders = ['?', '?']; | ||
|
||
// $tableName = $this->config->getTableName($class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why adding a code commented ? can we remove it ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need more information on the readme, or should we only remove the last todo?
This Pr also needs a changelog. |
The version bump is necessary because phpstan/phpstan bump 1.8.5 => 1.8.6 breaks rector < 0.14.4 @see rectorphp/rector#7509
e2f14fd
to
66f7124
Compare
Thanks @pietaj |
I guess the todo list on the readme should be updated too. |
I am targeting this branch, because the bundle does not support m:n auditing and the subject was already mentioned
here #302, and here #321 but was never finished
Changelog