LicenceGenerator   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 56
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A showList() 0 8 1
A getLicenceName() 0 5 2
A setType() 0 5 2
A create() 0 5 1
1
<?php namespace Packedge\Workbench\Generators;
2
3
use Illuminate\Filesystem\Filesystem;
4
use Mustache_Engine;
5
6
class LicenceGenerator extends BaseGenerator implements GeneratorInterface
7
{
8
    /*
9
     * Composer Ids
10
     * https://github.com/composer/composer/blob/master/res/spdx-identifier.json
11
     */
12
13
14
    /**
15
     * @var array
16
     */
17
    protected static $licences = [
18
        'MIT' => [ 'file' => 'MIT.txt',  'human' => 'MIT'],
19
        'Apache-2.0' => [ 'file' => 'Apache-2-0.txt', 'human' => 'Apache 2.0'],
20
        'GPL-3' => [ 'file' => 'GPL-3.txt', 'human' => 'GNU GPL v3.0'],
21
    ];
22
23
24
    /**
25
     * @var string
26
     */
27
    protected $type = 'MIT';
28
29 21
    public function __construct(Filesystem $filesystem = null, Mustache_Engine $mustache = null)
30
    {
31 21
        parent::__construct($filesystem, $mustache);
32 21
        $this->outputPath = 'LICENSE';
33 21
    }
34
35
    public static function showList()
36
    {
37 3
        $data = array_map(function($item){
38 3
            return $item['human'];
39 3
        }, static::$licences);
40
41 3
        return array_flip($data);
42
    }
43
44 6
    public static function getLicenceName($key)
45
    {
46 6
        if(!array_key_exists($key, static::$licences)) throw new \InvalidArgumentException("Licence $key not found.");
47 3
        return static::$licences[$key]['human'];
48
    }
49
50 6
    public function setType($name)
51
    {
52 6
        if(!array_key_exists($name, static::$licences)) throw new \InvalidArgumentException("Licence $name not found.");
53 3
        $this->type = $name;
54 3
    }
55
56 3
    public function create($packagePath)
57
    {
58 3
        $this->templatePath = 'licences/' . static::$licences[$this->type]['file'];
59 3
        parent::create($packagePath);
60
    }
61
}