Skip to content

Commit 38f8c5c

Browse files
authored
Merge 1.x into 2.x
2 parents 01250e4 + 162fe00 commit 38f8c5c

12 files changed

+356
-53
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
All notable changes to this project will be documented in this file.
33
This project adheres to [Semantic Versioning](http://semver.org/).
44

5+
## [1.17.1](https://github.com/sonata-project/EntityAuditBundle/compare/1.17.0...1.17.1) - 2024-04-17
6+
### Fixed
7+
- [[#617](https://github.com/sonata-project/EntityAuditBundle/pull/617)] Fix getting table name when the table schema is an empty string ([@X-Coder264](https://github.com/X-Coder264))
8+
- [[#615](https://github.com/sonata-project/EntityAuditBundle/pull/615)] Allow multiple relationships to the same target entity. ([@mikeyudin](https://github.com/mikeyudin))
9+
510
## [1.17.0](https://github.com/sonata-project/EntityAuditBundle/compare/1.16.1...1.17.0) - 2024-04-13
611
### Changed
712
- [[#612](https://github.com/sonata-project/EntityAuditBundle/pull/612)] Multiple queries to tables have been replaced with a single one ([@SavageDays](https://github.com/SavageDays))

composer.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@
4747
"symfony/security-bundle": "^5.4 || ^6.2 || ^7.0",
4848
"symfony/twig-bundle": "^5.4 || ^6.2 || ^7.0",
4949
"symfony/var-dumper": "^5.4 || ^6.2 || ^7.0",
50-
"vimeo/psalm": "^5.7",
51-
"weirdan/doctrine-psalm-plugin": "^2.8"
50+
"vimeo/psalm": "^5.7"
5251
},
5352
"conflict": {
5453
"doctrine/doctrine-bundle": "<2.7",

psalm.xml

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
<plugins>
1111
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
1212
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
13-
<pluginClass class="Weirdan\DoctrinePsalmPlugin\Plugin"/>
1413
</plugins>
1514
<issueHandlers>
1615
<!-- Psalm equivalent of PHPStan config `treatPhpDocTypesAsCertain: false` -->

src/AuditConfiguration.php

+34-3
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,19 @@ class AuditConfiguration
3333
*/
3434
private array $globalIgnoreColumns = [];
3535

36+
/** @phpstan-var literal-string */
3637
private string $tablePrefix = '';
3738

39+
/** @phpstan-var literal-string */
3840
private string $tableSuffix = '_audit';
3941

42+
/** @phpstan-var literal-string */
4043
private string $revisionTableName = 'revisions';
4144

45+
/** @phpstan-var literal-string */
4246
private string $revisionFieldName = 'rev';
4347

48+
/** @phpstan-var literal-string */
4449
private string $revisionTypeFieldName = 'revtype';
4550

4651
private string $revisionIdFieldType = Types::INTEGER;
@@ -69,13 +74,19 @@ public static function forEntities(array $classes)
6974
* @param ClassMetadataInfo<object> $metadata
7075
*
7176
* @return string
77+
*
78+
* @phpstan-return literal-string
79+
*
80+
* @psalm-suppress MoreSpecificReturnType,LessSpecificReturnStatement https://github.com/vimeo/psalm/issues/10910
7281
*/
7382
public function getTableName(ClassMetadataInfo $metadata)
7483
{
84+
/** @var literal-string $tableName */
7585
$tableName = $metadata->getTableName();
76-
77-
if (null !== $metadata->getSchemaName()) {
78-
$tableName = $metadata->getSchemaName().'.'.$tableName;
86+
/** @var literal-string|null $schemaName */
87+
$schemaName = $metadata->getSchemaName();
88+
if (null !== $schemaName && '' !== $schemaName) {
89+
$tableName = $schemaName.'.'.$tableName;
7990
}
8091

8192
return $this->getTablePrefix().$tableName.$this->getTableSuffix();
@@ -93,6 +104,8 @@ public function setDisabledForeignKeys(bool $disabled): void
93104

94105
/**
95106
* @return string
107+
*
108+
* @phpstan-return literal-string
96109
*/
97110
public function getTablePrefix()
98111
{
@@ -101,6 +114,8 @@ public function getTablePrefix()
101114

102115
/**
103116
* @param string $prefix
117+
*
118+
* @phpstan-param literal-string $prefix
104119
*/
105120
public function setTablePrefix($prefix): void
106121
{
@@ -109,6 +124,8 @@ public function setTablePrefix($prefix): void
109124

110125
/**
111126
* @return string
127+
*
128+
* @phpstan-return literal-string
112129
*/
113130
public function getTableSuffix()
114131
{
@@ -117,6 +134,8 @@ public function getTableSuffix()
117134

118135
/**
119136
* @param string $suffix
137+
*
138+
* @phpstan-param literal-string $suffix
120139
*/
121140
public function setTableSuffix($suffix): void
122141
{
@@ -125,6 +144,8 @@ public function setTableSuffix($suffix): void
125144

126145
/**
127146
* @return string
147+
*
148+
* @phpstan-return literal-string
128149
*/
129150
public function getRevisionFieldName()
130151
{
@@ -133,6 +154,8 @@ public function getRevisionFieldName()
133154

134155
/**
135156
* @param string $revisionFieldName
157+
*
158+
* @phpstan-param literal-string $revisionFieldName
136159
*/
137160
public function setRevisionFieldName($revisionFieldName): void
138161
{
@@ -141,6 +164,8 @@ public function setRevisionFieldName($revisionFieldName): void
141164

142165
/**
143166
* @return string
167+
*
168+
* @phpstan-return literal-string
144169
*/
145170
public function getRevisionTypeFieldName()
146171
{
@@ -149,6 +174,8 @@ public function getRevisionTypeFieldName()
149174

150175
/**
151176
* @param string $revisionTypeFieldName
177+
*
178+
* @phpstan-param literal-string $revisionTypeFieldName
152179
*/
153180
public function setRevisionTypeFieldName($revisionTypeFieldName): void
154181
{
@@ -157,6 +184,8 @@ public function setRevisionTypeFieldName($revisionTypeFieldName): void
157184

158185
/**
159186
* @return string
187+
*
188+
* @phpstan-return literal-string
160189
*/
161190
public function getRevisionTableName()
162191
{
@@ -165,6 +194,8 @@ public function getRevisionTableName()
165194

166195
/**
167196
* @param string $revisionTableName
197+
*
198+
* @phpstan-param literal-string $revisionTableName
168199
*/
169200
public function setRevisionTableName($revisionTableName): void
170201
{

src/AuditReader.php

+15-9
Original file line numberDiff line numberDiff line change
@@ -701,11 +701,14 @@ public function getEntityHistory($className, int|string|array $id)
701701
$id = [$classMetadata->identifier[0] => $id];
702702
}
703703

704+
/** @phpstan-var array<literal-string> $whereId */
704705
$whereId = [];
705706
foreach ($classMetadata->identifier as $idField) {
706707
if (isset($classMetadata->fieldMappings[$idField])) {
708+
/** @phpstan-var literal-string $columnName */
707709
$columnName = $classMetadata->fieldMappings[$idField]['columnName'];
708710
} elseif (isset($classMetadata->associationMappings[$idField]['joinColumns'])) {
711+
/** @phpstan-var literal-string $columnName */
709712
$columnName = $classMetadata->associationMappings[$idField]['joinColumns'][0]['name'];
710713
} else {
711714
continue;
@@ -720,10 +723,14 @@ public function getEntityHistory($className, int|string|array $id)
720723

721724
foreach ($classMetadata->fieldNames as $columnName => $field) {
722725
$type = Type::getType($classMetadata->fieldMappings[$field]['type']);
723-
$columnList[] = $type->convertToPHPValueSQL(
726+
/** @phpstan-var literal-string $sqlExpr */
727+
$sqlExpr = $type->convertToPHPValueSQL(
724728
$this->quoteStrategy->getColumnName($field, $classMetadata, $this->platform),
725729
$this->platform
726-
).' AS '.$this->platform->quoteSingleIdentifier($field);
730+
);
731+
/** @phpstan-var literal-string $quotedField */
732+
$quotedField = $this->platform->quoteSingleIdentifier($field);
733+
$columnList[] = $sqlExpr.' AS '.$quotedField;
727734
$columnMap[$field] = $this->getSQLResultCasing($this->platform, $columnName);
728735
}
729736

@@ -736,6 +743,7 @@ public function getEntityHistory($className, int|string|array $id)
736743
continue;
737744
}
738745

746+
/** @phpstan-var literal-string $sourceCol */
739747
foreach ($assoc['targetToSourceKeyColumns'] as $sourceCol) {
740748
$columnList[] = $sourceCol;
741749
$columnMap[$sourceCol] = $this->getSQLResultCasing($this->platform, $sourceCol);
@@ -744,13 +752,11 @@ public function getEntityHistory($className, int|string|array $id)
744752

745753
$values = array_values($id);
746754

747-
$query = sprintf(
748-
'SELECT %s FROM %s e WHERE %s ORDER BY e.%s DESC',
749-
implode(', ', $columnList),
750-
$tableName,
751-
$whereSQL,
752-
$this->config->getRevisionFieldName()
753-
);
755+
$query =
756+
'SELECT '.implode(', ', $columnList)
757+
.' FROM '.$tableName.' e'
758+
.' WHERE '.$whereSQL
759+
.' ORDER BY e.'.$this->config->getRevisionFieldName().' DESC';
754760

755761
$stmt = $this->em->getConnection()->executeQuery($query, $values);
756762

src/Collection/AuditedCollection.php

+11-9
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ public function __construct(
8080
}
8181

8282
/**
83-
* @return true
83+
* @return void
84+
*
85+
* @phpstan-ignore-next-line https://github.com/phpstan/phpstan-doctrine/pull/560
8486
*/
8587
#[\ReturnTypeWillChange]
8688
public function add(mixed $element)
@@ -293,9 +295,10 @@ public function exists(\Closure $p)
293295
/**
294296
* @return Collection<TKey, T>
295297
*
296-
* @phpstan-param \Closure(T, int|string):bool $p
297-
* @psalm-param \Closure(T=):bool $p
298-
* @psalm-return Collection<TKey, T>
298+
* @phpstan-param \Closure(T, TKey):bool $p
299+
* @phpstan-return Collection<TKey, T>
300+
*
301+
* @psalm-suppress MoreSpecificImplementedParamType https://github.com/doctrine/collections/pull/411
299302
*/
300303
#[\ReturnTypeWillChange]
301304
public function filter(\Closure $p)
@@ -323,9 +326,7 @@ public function forAll(\Closure $p)
323326
*
324327
* @phpstan-template U
325328
* @phpstan-param \Closure(T):U $func
326-
* @psalm-return Collection<TKey, U>
327-
*
328-
* @psalm-suppress ImplementedParamTypeMismatch,InvalidArgument
329+
* @phpstan-return Collection<TKey, U>
329330
*/
330331
#[\ReturnTypeWillChange]
331332
public function map(\Closure $func)
@@ -339,7 +340,9 @@ public function map(\Closure $func)
339340
* @return array<Collection<TKey, T>>
340341
*
341342
* @phpstan-param \Closure(TKey, T):bool $p
342-
* @psalm-return array{0: Collection<TKey, T>, 1: Collection<TKey, T>}
343+
* @phpstan-return array{0: Collection<TKey, T>, 1: Collection<TKey, T>}
344+
*
345+
* @psalm-suppress MoreSpecificImplementedParamType https://github.com/doctrine/collections/pull/411
343346
*/
344347
#[\ReturnTypeWillChange]
345348
public function partition(\Closure $p)
@@ -454,7 +457,6 @@ public function count()
454457
* @return T|null
455458
*
456459
* @phpstan-return T|null
457-
* @psalm-return mixed|null
458460
*/
459461
#[\ReturnTypeWillChange]
460462
public function findFirst(\Closure $p)

0 commit comments

Comments
 (0)