Completed
Pull Request — master (#8)
by ARCANEDEV
02:29
created

AutoloadTrait   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A mergeAutoload() 0 9 2
unwrapIfNeeded() 0 3 ?
1
<?php namespace Arcanedev\Composer\Entities\PackageTraits;
2
3
use Arcanedev\Composer\Utilities\Util;
4
use Composer\Package\RootPackageInterface;
5
6
/**
7
 * Trait     AutoloadTrait
8
 *
9
 * @package  Arcanedev\Composer\Entities\PackageTraits
10
 * @author   ARCANEDEV <[email protected]>
11
 */
12
trait AutoloadTrait
13
{
14
    /* ------------------------------------------------------------------------------------------------
15
     |  Properties
16
     | ------------------------------------------------------------------------------------------------
17
     */
18
    /** @var \Composer\Package\CompletePackage $package */
19
    protected $package;
20
21
    /** @var string $path */
22
    protected $path;
23
24
    /* ------------------------------------------------------------------------------------------------
25
     |  Main Functions
26
     | ------------------------------------------------------------------------------------------------
27
     */
28
    /**
29
     * Merge autoload into a RootPackage.
30
     *
31
     * @param  \Composer\Package\RootPackageInterface  $root
32
     */
33
    private function mergeAutoload(RootPackageInterface $root)
34
    {
35
        if ( ! empty($autoload = $this->package->getAutoload())) {
36
            static::unwrapIfNeeded($root, 'setAutoload')
37
                ->setAutoload(array_merge_recursive(
38
                    $root->getAutoload(), Util::fixRelativePaths($this->path, $autoload)
39
                ));
40
        }
41
    }
42
43
    /**
44
     * Get a full featured Package from a RootPackageInterface.
45
     *
46
     * @param  \Composer\Package\RootPackageInterface|\Composer\Package\RootPackage  $root
47
     * @param  string                                                                $method
48
     *
49
     * @return \Composer\Package\RootPackageInterface|\Composer\Package\RootPackage
50
     */
51
    abstract protected function unwrapIfNeeded(
52
        RootPackageInterface $root, $method = 'setExtra'
53
    );
54
}
55