Total Complexity | 20 |
Total Lines | 224 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
39 | trait ModuleDataFixTrait |
||
40 | { |
||
41 | /** |
||
42 | * Options form. |
||
43 | * |
||
44 | * @param Tree $tree |
||
45 | * |
||
46 | * @return string |
||
47 | */ |
||
48 | public function fixOptions(Tree $tree): string |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * A list of all records that need examining. This may include records |
||
55 | * that do not need updating, if we can't detect this quickly using SQL. |
||
56 | * |
||
57 | * @param Tree $tree |
||
58 | * @param array<string,string> $params |
||
59 | * |
||
60 | * @return Collection<stdClass> |
||
61 | */ |
||
62 | public function recordsToFix(Tree $tree, array $params): Collection |
||
63 | { |
||
64 | $families = $this->familiesToFix($tree, $params); |
||
1 ignored issue
–
show
|
|||
65 | $individuals = $this->individualsToFix($tree, $params); |
||
1 ignored issue
–
show
|
|||
66 | $media = $this->mediaToFix($tree, $params); |
||
1 ignored issue
–
show
|
|||
67 | $notes = $this->notesToFix($tree, $params); |
||
1 ignored issue
–
show
|
|||
68 | $repositories = $this->repositoriesToFix($tree, $params); |
||
1 ignored issue
–
show
|
|||
69 | $sources = $this->sourcesToFix($tree, $params); |
||
1 ignored issue
–
show
|
|||
70 | $submitters = $this->submittersToFix($tree, $params); |
||
1 ignored issue
–
show
|
|||
71 | |||
72 | $records = new Collection(); |
||
73 | |||
74 | if ($families !== null) { |
||
1 ignored issue
–
show
|
|||
75 | $records = $records->concat($this->mergePendingRecords($families, $tree, Family::RECORD_TYPE)); |
||
76 | } |
||
77 | |||
78 | if ($individuals !== null) { |
||
1 ignored issue
–
show
|
|||
79 | $records = $records->concat($this->mergePendingRecords($individuals, $tree, Individual::RECORD_TYPE)); |
||
80 | } |
||
81 | |||
82 | if ($media !== null) { |
||
1 ignored issue
–
show
|
|||
83 | $records = $records->concat($this->mergePendingRecords($media, $tree, Media::RECORD_TYPE)); |
||
84 | } |
||
85 | |||
86 | if ($notes !== null) { |
||
1 ignored issue
–
show
|
|||
87 | $records = $records->concat($this->mergePendingRecords($notes, $tree, Note::RECORD_TYPE)); |
||
88 | } |
||
89 | |||
90 | if ($repositories !== null) { |
||
1 ignored issue
–
show
|
|||
91 | $records = $records->concat($this->mergePendingRecords($repositories, $tree, Repository::RECORD_TYPE)); |
||
92 | } |
||
93 | |||
94 | if ($sources !== null) { |
||
1 ignored issue
–
show
|
|||
95 | $records = $records->concat($this->mergePendingRecords($sources, $tree, Source::RECORD_TYPE)); |
||
96 | } |
||
97 | |||
98 | if ($submitters !== null) { |
||
1 ignored issue
–
show
|
|||
99 | $records = $records->concat($this->mergePendingRecords($submitters, $tree, Submitter::RECORD_TYPE)); |
||
100 | } |
||
101 | |||
102 | return $records |
||
103 | ->unique() |
||
104 | ->sort(static function (stdClass $x, stdClass $y) { |
||
105 | return $x->xref <=> $y->xref; |
||
106 | }); |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * Does a record need updating? |
||
111 | * |
||
112 | * @param GedcomRecord $record |
||
113 | * @param array<string,string> $params |
||
114 | * |
||
115 | * @return bool |
||
116 | */ |
||
117 | public function doesRecordNeedUpdate(GedcomRecord $record, array $params): bool |
||
118 | { |
||
119 | return false; |
||
120 | } |
||
121 | |||
122 | /** |
||
123 | * Show the changes we would make |
||
124 | * |
||
125 | * @param GedcomRecord $record |
||
126 | * @param array<string,string> $params |
||
127 | * |
||
128 | * @return string |
||
129 | */ |
||
130 | public function previewUpdate(GedcomRecord $record, array $params): string |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * Fix a record |
||
137 | * |
||
138 | * @param GedcomRecord $record |
||
139 | * @param array<string,string> $params |
||
140 | * |
||
141 | * @return void |
||
142 | */ |
||
143 | public function updateRecord(GedcomRecord $record, array $params): void |
||
145 | } |
||
146 | |||
147 | /** |
||
148 | * XREFs of family records that might need fixing. |
||
149 | * |
||
150 | * @param Tree $tree |
||
151 | * @param array<string,string> $params |
||
152 | * |
||
153 | * @return Collection<string>|null |
||
154 | */ |
||
155 | protected function familiesToFix(Tree $tree, array $params): ?Collection |
||
158 | } |
||
159 | |||
160 | /** |
||
161 | * XREFs of individual records that might need fixing. |
||
162 | * |
||
163 | * @param Tree $tree |
||
164 | * @param array<string,string> $params |
||
165 | * |
||
166 | * @return Collection<string>|null |
||
167 | */ |
||
168 | protected function individualsToFix(Tree $tree, array $params): ?Collection |
||
169 | { |
||
170 | return null; |
||
171 | } |
||
172 | |||
173 | /** |
||
174 | * XREFs of media records that might need fixing. |
||
175 | * |
||
176 | * @param Tree $tree |
||
177 | * @param array<string,string> $params |
||
178 | * |
||
179 | * @return Collection<string>|null |
||
180 | */ |
||
181 | protected function mediaToFix(Tree $tree, array $params): ?Collection |
||
182 | { |
||
183 | return null; |
||
184 | } |
||
185 | |||
186 | /** |
||
187 | * XREFs of note records that might need fixing. |
||
188 | * |
||
189 | * @param Tree $tree |
||
190 | * @param array<string,string> $params |
||
191 | * |
||
192 | * @return Collection<string>|null |
||
193 | */ |
||
194 | protected function notesToFix(Tree $tree, array $params): ?Collection |
||
197 | } |
||
198 | |||
199 | /** |
||
200 | * XREFs of repository records that might need fixing. |
||
201 | * |
||
202 | * @param Tree $tree |
||
203 | * @param array<string,string> $params |
||
204 | * |
||
205 | * @return Collection<string>|null |
||
206 | */ |
||
207 | protected function repositoriesToFix(Tree $tree, array $params): ?Collection |
||
210 | } |
||
211 | |||
212 | /** |
||
213 | * XREFs of source records that might need fixing. |
||
214 | * |
||
215 | * @param Tree $tree |
||
216 | * @param array<string,string> $params |
||
217 | * |
||
218 | * @return Collection<string>|null |
||
219 | */ |
||
220 | protected function sourcesToFix(Tree $tree, array $params): ?Collection |
||
221 | { |
||
222 | return null; |
||
223 | } |
||
224 | |||
225 | /** |
||
226 | * XREFs of submitter records that might need fixing. |
||
227 | * |
||
228 | * @param Tree $tree |
||
229 | * @param array<string,string> $params |
||
230 | * |
||
231 | * @return Collection<string>|null |
||
232 | */ |
||
233 | protected function submittersToFix(Tree $tree, array $params): ?Collection |
||
236 | } |
||
237 | |||
238 | /** |
||
239 | * Merge pending changes of a given type. We need to check all pending records. |
||
240 | * |
||
241 | * @param Collection<string> $records |
||
242 | * @param Tree $tree |
||
243 | * @param string $type |
||
244 | * |
||
245 | * @return Collection<stdClass> |
||
246 | */ |
||
247 | private function mergePendingRecords(Collection $records, Tree $tree, string $type): Collection |
||
263 | }); |
||
264 | } |
||
265 | } |
||
266 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.