Completed
Pull Request — master (#78)
by
unknown
01:54
created

Package   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSummary() 0 3 1
A getTitle() 0 3 1
A requireDefaultRecords() 0 5 1
1
<?php
2
3
namespace BringYourOwnIdeas\Maintenance\Model;
4
5
use SilverStripe\Core\Injector\Injector;
6
use BringYourOwnIdeas\Maintenance\Tasks\UpdatePackageInfoTask;
7
use SilverStripe\ORM\DataObject;
8
9
/**
10
 * Describes an installed composer package version.
11
 */
12
class Package extends DataObject
13
{
14
    private static $table_name = 'Package';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
15
16
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
17
        'Name' => 'Varchar(255)',
18
        'Description' => 'Varchar(255)',
19
        'Version' => 'Varchar(255)',
20
        'Type' => 'Varchar(255)',
21
        'Supported' => 'Boolean',
22
    ];
23
24
    private static $summary_fields = [
0 ignored issues
show
introduced by
The private property $summary_fields is not used, and could be removed.
Loading history...
25
        'Title' => 'Title',
26
        'Description' => 'Description',
27
        'Version' => 'Version',
28
    ];
29
30
    /**
31
     * Strips vendor and 'silverstripe-' prefix from Name property
32
     * @return string More easily digestable module name for human consumers
33
     */
34
    public function getTitle()
35
    {
36
        return preg_replace('#^[^/]+/(silverstripe-)?#', '', $this->Name);
0 ignored issues
show
Bug Best Practice introduced by
The property Name does not exist on BringYourOwnIdeas\Maintenance\Model\Package. Since you implemented __get, consider adding a @property annotation.
Loading history...
37
    }
38
39
    /**
40
     * Returns HTML formatted summary of this object, uses a template to do this.
41
     * @return string
42
     */
43
    public function getSummary()
44
    {
45
        return $this->renderWith('Package_summary');
46
    }
47
48
    /**
49
     * requireDefaultRecords() gets abused to update the information on dev/build.
50
     */
51
    public function requireDefaultRecords()
52
    {
53
        parent::requireDefaultRecords();
54
        $task = Injector::inst()->create(UpdatePackageInfoTask::class);
55
        $task->run(null);
56
    }
57
}
58