StrongCoupling   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 22
loc 22
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 6 1
A getMessage() 9 9 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Solidifier\Defects;
4
5
use Solidifier\Defect;
6
use Solidifier\Visitors\ObjectType;
7
use PhpParser\Node\Expr\New_;
8
9 View Code Duplication
class StrongCoupling extends Defect
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
{
11
    private
12
        $objectType;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $objectType.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
13
        
14
    public function __construct(ObjectType $objectType, New_ $node)
15
    {
16
        parent::__construct($node);
17
        
18
        $this->objectType = $objectType;
19
    }    
20
    
21
    public function getMessage()
22
    {
23
        return sprintf(
24
            'Allocation in %s <type>%s</type> (instanciate %s)',
25
            $this->objectType->type,
26
            $this->objectType->fullname,
27
            $this->node->class
0 ignored issues
show
Bug introduced by
Accessing class on the interface PhpParser\Node suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
28
        );
29
    }
30
}
31