Skip to content

Commit 23316d6

Browse files
committed
Stop passing parameters by reference in mapping drivers
1 parent 0848a48 commit 23316d6

File tree

41 files changed

+192
-42
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+192
-42
lines changed

phpstan.neon.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ parameters:
1919
- '#^Property Gedmo\\Tests\\.+\\Fixture\\[^:]+::\$\w+ is never written, only read\.$#'
2020
- '#^Property Gedmo\\Tests\\.+\\Fixture\\[^:]+::\$\w+ is never read, only written\.$#'
2121
- '#^Property Gedmo\\Tests\\.+\\Fixture\\[^:]+::\$\w+ is unused\.$#'
22+
- '#^Method Gedmo\\(?:[^\\]+\\)*Mapping\\Driver[^:]+::readExtendedMetadata\(\) with return type void returns [\w\|<>\s,]+ but should not return anything\.$#'
23+
- '#^Method Gedmo\\Uploadable\\Mapping\\Validator::validateConfiguration\(\) with return type void returns array<string, mixed> but should not return anything\.$#'
24+
- '#^Result of static method Gedmo\\Uploadable\\Mapping\\Validator::validateConfiguration\(\) \(void\) is used\.$#'
25+
- '#^Result of method Gedmo\\Mapping\\Driver::readExtendedMetadata\(\) \(void\) is used\.$#'
2226

2327
rules:
2428
- PHPStan\Rules\Constants\MissingClassConstantTypehintRule

src/Blameable/Mapping/Driver/Annotation.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,7 @@ public function readExtendedMetadata($meta, array &$config)
8888
$config[$blameable->on][] = $field;
8989
}
9090
}
91+
92+
return $config;
9193
}
9294
}

src/Blameable/Mapping/Driver/Xml.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ public function readExtendedMetadata($meta, array &$config)
110110
}
111111
}
112112
}
113+
114+
return $config;
113115
}
114116

115117
/**

src/Blameable/Mapping/Driver/Yaml.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ public function readExtendedMetadata($meta, array &$config)
111111
}
112112
}
113113
}
114+
115+
return $config;
114116
}
115117

116118
protected function _loadMappingFile($file)

src/IpTraceable/Mapping/Driver/Annotation.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,7 @@ public function readExtendedMetadata($meta, array &$config)
7979
$config[$ipTraceable->on][] = $field;
8080
}
8181
}
82+
83+
return $config;
8284
}
8385
}

src/IpTraceable/Mapping/Driver/Xml.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ public function readExtendedMetadata($meta, array &$config)
113113
$config[$this->_getAttribute($data, 'on')][] = $field;
114114
}
115115
}
116+
117+
return $config;
116118
}
117119
}
118120

src/IpTraceable/Mapping/Driver/Yaml.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ public function readExtendedMetadata($meta, array &$config)
108108
$config[$mappingProperty['on']][] = $field;
109109
}
110110
}
111+
112+
return $config;
111113
}
112114
}
113115

src/Loggable/Mapping/Driver/Annotation.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ public function readExtendedMetadata($meta, array &$config)
9595
throw new InvalidMappingException("Class must be annotated with Loggable annotation in order to track versioned fields in class - {$meta->getName()}");
9696
}
9797
}
98+
99+
return $config;
98100
}
99101

100102
/**

src/Loggable/Mapping/Driver/Xml.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,22 +56,22 @@ public function readExtendedMetadata($meta, array &$config)
5656
}
5757

5858
if (isset($xmlDoctrine->field)) {
59-
$this->inspectElementForVersioned($xmlDoctrine->field, $config, $meta);
59+
$config = $this->inspectElementForVersioned($xmlDoctrine->field, $config, $meta);
6060
}
6161
foreach ($xmlDoctrine->{'attribute-overrides'}->{'attribute-override'} ?? [] as $overrideMapping) {
62-
$this->inspectElementForVersioned($overrideMapping, $config, $meta);
62+
$config = $this->inspectElementForVersioned($overrideMapping, $config, $meta);
6363
}
6464
if (isset($xmlDoctrine->{'many-to-one'})) {
65-
$this->inspectElementForVersioned($xmlDoctrine->{'many-to-one'}, $config, $meta);
65+
$config = $this->inspectElementForVersioned($xmlDoctrine->{'many-to-one'}, $config, $meta);
6666
}
6767
if (isset($xmlDoctrine->{'one-to-one'})) {
68-
$this->inspectElementForVersioned($xmlDoctrine->{'one-to-one'}, $config, $meta);
68+
$config = $this->inspectElementForVersioned($xmlDoctrine->{'one-to-one'}, $config, $meta);
6969
}
7070
if (isset($xmlDoctrine->{'reference-one'})) {
71-
$this->inspectElementForVersioned($xmlDoctrine->{'reference-one'}, $config, $meta);
71+
$config = $this->inspectElementForVersioned($xmlDoctrine->{'reference-one'}, $config, $meta);
7272
}
7373
if (isset($xmlDoctrine->{'embedded'})) {
74-
$this->inspectElementForVersioned($xmlDoctrine->{'embedded'}, $config, $meta);
74+
$config = $this->inspectElementForVersioned($xmlDoctrine->{'embedded'}, $config, $meta);
7575
}
7676

7777
if (!$meta->isMappedSuperclass && $config) {
@@ -82,14 +82,18 @@ public function readExtendedMetadata($meta, array &$config)
8282
throw new InvalidMappingException("Class must be annotated with Loggable annotation in order to track versioned fields in class - {$meta->getName()}");
8383
}
8484
}
85+
86+
return $config;
8587
}
8688

8789
/**
8890
* Searches mappings on element for versioned fields
8991
*
9092
* @param array<string, mixed> $config
93+
*
94+
* @return array<string, mixed>
9195
*/
92-
private function inspectElementForVersioned(\SimpleXMLElement $element, array &$config, ClassMetadata $meta): void
96+
private function inspectElementForVersioned(\SimpleXMLElement $element, array $config, ClassMetadata $meta): array
9397
{
9498
foreach ($element as $mapping) {
9599
$mappingDoctrine = $mapping;
@@ -108,5 +112,7 @@ private function inspectElementForVersioned(\SimpleXMLElement $element, array &$
108112
$config['versioned'][] = $field;
109113
}
110114
}
115+
116+
return $config;
111117
}
112118
}

src/Loggable/Mapping/Driver/Yaml.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public function readExtendedMetadata($meta, array &$config)
118118
}
119119
// fields cannot be overrided and throws mapping exception
120120
$mapping = $this->_getMapping($fieldMapping['class']);
121-
$this->inspectEmbeddedForVersioned($field, $mapping, $config);
121+
$config = $this->inspectEmbeddedForVersioned($field, $mapping, $config);
122122
}
123123
}
124124
}
@@ -132,6 +132,8 @@ public function readExtendedMetadata($meta, array &$config)
132132
throw new InvalidMappingException("Class must be annotated with Loggable annotation in order to track versioned fields in class - {$meta->getName()}");
133133
}
134134
}
135+
136+
return $config;
135137
}
136138

137139
protected function _loadMappingFile($file)
@@ -142,13 +144,17 @@ protected function _loadMappingFile($file)
142144
/**
143145
* @param array<string, array<string, array<string, mixed>>> $mapping
144146
* @param array<string, mixed> $config
147+
*
148+
* @return array<string, mixed>
145149
*/
146-
private function inspectEmbeddedForVersioned(string $field, array $mapping, array &$config): void
150+
private function inspectEmbeddedForVersioned(string $field, array $mapping, array $config): array
147151
{
148152
if (isset($mapping['fields'])) {
149153
foreach ($mapping['fields'] as $property => $fieldMapping) {
150154
$config['versioned'][] = $field.'.'.$property;
151155
}
152156
}
157+
158+
return $config;
153159
}
154160
}

0 commit comments

Comments
 (0)