Completed
Push — master ( 2158d1...bc8d4c )
by Hong
04:13
created

Installer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 9 1
A getInstallPath() 0 14 4
1
<?php
2
/**
3
 * Phossa Project
4
 *
5
 * PHP version 5.4
6
 *
7
 * @category  Library
8
 * @package   Phossa2\Composer
9
 * @copyright Copyright (c) 2016 phossa.com
10
 * @license   http://mit-license.org/ MIT License
11
 * @link      http://www.phossa.com/
12
 */
13
/*# declare(strict_types=1); */
14
15
namespace Phossa2\Composer;
16
17
use Composer\Package\PackageInterface;
18
use Composer\Installer\LibraryInstaller;
19
20
/**
21
 * Installer
22
 *
23
 * @package Phossa2\Composer
24
 * @author  Hong Zhang <[email protected]>
25
 * @version 2.0.0
26
 * @since   2.0.0 added
27
 */
28
class Installer extends LibraryInstaller
29
{
30
    // phossa2 application
31
    const TYPE_APP = 'phossa2-app';
32
33
    // phossa2 extension
34
    const TYPE_EXT = 'phossa2-extension';
35
36
    // app dir defined in extra
37
    const EXTRA_APPPATH = 'app-path';
38
39
    /**
40
     * {@inheritDoc}
41
     */
42
    public function supports($packageType)
43
    {
44
        // types supported
45
        $types = [
46
            'phossa2-app',
47
            'phossa2-extension'
48
        ];
49
        return in_array($packageType, $types);
50
    }
51
52
    /**
53
     * {@inheritDoc}
54
     */
55
    public function getInstallPath(PackageInterface $package)
56
    {
57
        $extra = $package->getExtra();
58
        switch ($package->getType()) {
59
            // install to a custom app dir if defined
60
            case self::TYPE_APP:
61
                return isset($extra[self::EXTRA_APPPATH]) ?
62
                    $extra[self::EXTRA_APPPATH] : 'app';
63
64
            // install to extension dir
65
            case self::TYPE_EXT:
66
                return 'extension/' . $package->getPrettyName();
67
        }
68
    }
69
}
70