Completed
Pull Request — master (#8)
by ARCANEDEV
06:34
created

LinksTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 39
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B mergePackageLinks() 0 26 3
1
<?php namespace Arcanedev\Composer\Entities\PackageTraits;
2
3
use Composer\Package\BasePackage;
4
use Composer\Package\RootPackageInterface;
5
6
/**
7
 * Trait     LinksTrait
8
 *
9
 * @package  Arcanedev\Composer\Entities\PackageTraits
10
 * @author   ARCANEDEV <[email protected]>
11
 */
12
trait LinksTrait
13
{
14
    /* ------------------------------------------------------------------------------------------------
15
     |  Main Functions
16
     | ------------------------------------------------------------------------------------------------
17
     */
18
    /**
19
     * Merge package links of the given type into a RootPackageInterface
20
     *
21
     * @param  string                                  $type  'conflict', 'replace' or 'provide'
22
     * @param  \Composer\Package\RootPackageInterface  $root
23
     */
24
    protected function mergePackageLinks($type, RootPackageInterface $root)
25
    {
26
        $linkType = BasePackage::$supportedLinkTypes[$type];
27
        $getter   = 'get' . ucfirst($linkType['method']);
28
        $setter   = 'set' . ucfirst($linkType['method']);
29
30
        $links = $this->package->{$getter}();
0 ignored issues
show
Bug introduced by
The property package does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
31
32
        if (empty($links)) return;
33
34
        $unwrapped = self::unwrapIfNeeded($root, $setter);
35
36
        // @codeCoverageIgnoreStart
37
        if ($root !== $unwrapped) {
38
            $this->logger->warning(
0 ignored issues
show
Bug introduced by
The property logger does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
39
                'This Composer version does not support ' .
40
                "'{$type}' merging for aliased packages."
41
            );
42
        }
43
        // @codeCoverageIgnoreEnd
44
45
        $unwrapped->{$setter}(array_merge(
46
            $root->{$getter}(),
47
            $this->replaceSelfVersionDependencies($type, $links, $root)
0 ignored issues
show
Bug introduced by
It seems like replaceSelfVersionDependencies() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
48
        ));
49
    }
50
}
51