Code Duplication    Length = 41-41 lines in 2 locations

src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/StaticPropertyFetchAnalyzer.php 1 location

@@ 275-315 (lines=41) @@
272
273
        $declaring_property_id = strtolower($declaring_property_class) . '::$' . $prop_name;
274
275
        if ($codebase->alter_code) {
276
            $moved_class = $codebase->classlikes->handleClassLikeReferenceInMigration(
277
                $codebase,
278
                $statements_analyzer,
279
                $stmt->class,
280
                $fq_class_name,
281
                $context->calling_method_id
282
            );
283
284
            if (!$moved_class) {
285
                foreach ($codebase->property_transforms as $original_pattern => $transformation) {
286
                    if ($declaring_property_id === $original_pattern) {
287
                        list($old_declaring_fq_class_name) = explode('::$', $declaring_property_id);
288
                        list($new_fq_class_name, $new_property_name) = explode('::$', $transformation);
289
290
                        $file_manipulations = [];
291
292
                        if (strtolower($new_fq_class_name) !== strtolower($old_declaring_fq_class_name)) {
293
                            $file_manipulations[] = new \Psalm\FileManipulation(
294
                                (int) $stmt->class->getAttribute('startFilePos'),
295
                                (int) $stmt->class->getAttribute('endFilePos') + 1,
296
                                Type::getStringFromFQCLN(
297
                                    $new_fq_class_name,
298
                                    $statements_analyzer->getNamespace(),
299
                                    $statements_analyzer->getAliasedClassesFlipped(),
300
                                    null
301
                                )
302
                            );
303
                        }
304
305
                        $file_manipulations[] = new \Psalm\FileManipulation(
306
                            (int) $stmt->name->getAttribute('startFilePos'),
307
                            (int) $stmt->name->getAttribute('endFilePos') + 1,
308
                            '$' . $new_property_name
309
                        );
310
311
                        FileManipulationBuffer::add($statements_analyzer->getFilePath(), $file_manipulations);
312
                    }
313
                }
314
            }
315
        }
316
317
        $class_storage = $codebase->classlike_storage_provider->get($declaring_property_class);
318
        $property = $class_storage->properties[$prop_name];

src/Psalm/Internal/Analyzer/Statements/Expression/Assignment/StaticPropertyAssignmentAnalyzer.php 1 location

@@ 133-173 (lines=41) @@
130
131
        $declaring_property_id = strtolower((string) $declaring_property_class) . '::$' . $prop_name;
132
133
        if ($codebase->alter_code && $stmt->class instanceof PhpParser\Node\Name) {
134
            $moved_class = $codebase->classlikes->handleClassLikeReferenceInMigration(
135
                $codebase,
136
                $statements_analyzer,
137
                $stmt->class,
138
                $fq_class_name,
139
                $context->calling_method_id
140
            );
141
142
            if (!$moved_class) {
143
                foreach ($codebase->property_transforms as $original_pattern => $transformation) {
144
                    if ($declaring_property_id === $original_pattern) {
145
                        list($old_declaring_fq_class_name) = explode('::$', $declaring_property_id);
146
                        list($new_fq_class_name, $new_property_name) = explode('::$', $transformation);
147
148
                        $file_manipulations = [];
149
150
                        if (strtolower($new_fq_class_name) !== strtolower($old_declaring_fq_class_name)) {
151
                            $file_manipulations[] = new \Psalm\FileManipulation(
152
                                (int) $stmt->class->getAttribute('startFilePos'),
153
                                (int) $stmt->class->getAttribute('endFilePos') + 1,
154
                                Type::getStringFromFQCLN(
155
                                    $new_fq_class_name,
156
                                    $statements_analyzer->getNamespace(),
157
                                    $statements_analyzer->getAliasedClassesFlipped(),
158
                                    null
159
                                )
160
                            );
161
                        }
162
163
                        $file_manipulations[] = new \Psalm\FileManipulation(
164
                            (int) $stmt->name->getAttribute('startFilePos'),
165
                            (int) $stmt->name->getAttribute('endFilePos') + 1,
166
                            '$' . $new_property_name
167
                        );
168
169
                        FileManipulationBuffer::add($statements_analyzer->getFilePath(), $file_manipulations);
170
                    }
171
                }
172
            }
173
        }
174
175
        $class_storage = $codebase->classlike_storage_provider->get($declaring_property_class);
176