Code Duplication    Length = 33-40 lines in 2 locations

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

@@ 423-455 (lines=33) @@
420
            $interface_exists = false;
421
422
            if (!$codebase->classExists($lhs_type_part->value)) {
423
                if ($codebase->interfaceExists($lhs_type_part->value)) {
424
                    $interface_exists = true;
425
                    $interface_storage = $codebase->classlike_storage_provider->get($lhs_type_part->value);
426
427
                    $override_property_visibility = $interface_storage->override_property_visibility;
428
429
                    foreach ($intersection_types as $intersection_type) {
430
                        if ($intersection_type instanceof TNamedObject
431
                            && $codebase->classExists($intersection_type->value)
432
                        ) {
433
                            $fq_class_name = $intersection_type->value;
434
                            $class_exists = true;
435
                            break;
436
                        }
437
                    }
438
439
                    if (!$class_exists) {
440
                        if (IssueBuffer::accepts(
441
                            new NoInterfaceProperties(
442
                                'Interfaces cannot have properties',
443
                                new CodeLocation($statements_analyzer->getSource(), $stmt),
444
                                $lhs_type_part->value
445
                            ),
446
                            $statements_analyzer->getSuppressedIssues()
447
                        )) {
448
                            return true;
449
                        }
450
451
                        if (!$codebase->methodExists($fq_class_name . '::__set')) {
452
                            return true;
453
                        }
454
                    }
455
                }
456
457
                if (!$class_exists && !$interface_exists) {
458
                    if ($lhs_type_part->from_docblock) {

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

@@ 308-347 (lines=40) @@
305
                $interface_exists = false;
306
307
                if (!$codebase->classExists($lhs_type_part->value)) {
308
                    if ($codebase->interfaceExists($lhs_type_part->value)) {
309
                        $interface_exists = true;
310
                        $interface_storage = $codebase->classlike_storage_provider->get(
311
                            strtolower($lhs_type_part->value)
312
                        );
313
314
                        $override_property_visibility = $interface_storage->override_property_visibility;
315
316
                        foreach ($intersection_types as $intersection_type) {
317
                            if ($intersection_type instanceof TNamedObject
318
                                && $codebase->classExists($intersection_type->value)
319
                            ) {
320
                                $fq_class_name = $intersection_type->value;
321
                                $class_exists = true;
322
                                break;
323
                            }
324
                        }
325
326
                        if (!$class_exists) {
327
                            if (IssueBuffer::accepts(
328
                                new NoInterfaceProperties(
329
                                    'Interfaces cannot have properties',
330
                                    new CodeLocation($statements_analyzer->getSource(), $stmt),
331
                                    $lhs_type_part->value
332
                                ),
333
                                $statements_analyzer->getSuppressedIssues()
334
                            )) {
335
                                return null;
336
                            }
337
338
                            if (!$codebase->methods->methodExists(
339
                                new \Psalm\Internal\MethodIdentifier(
340
                                    $fq_class_name,
341
                                    '__set'
342
                                )
343
                            )) {
344
                                return null;
345
                            }
346
                        }
347
                    }
348
349
                    if (!$class_exists && !$interface_exists) {
350
                        if (IssueBuffer::accepts(