Completed
Pull Request — master (#28)
by Robbie
01:30
created

ComposerUpdateExtension   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 2
cbo 2
dl 0
loc 53
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A requireDefaultRecords() 0 4 1
A getAvailableVersion() 0 7 2
A getJobName() 0 4 1
1
<?php
2
3
namespace BringYourOwnIdeas\UpdateChecker\Extensions;
4
5
use DataExtension;
6
use Injector;
7
use QueuedJobService;
8
9
/**
10
 * Describes any available updates to an installed Composer package
11
 *
12
 * Originally from https://github.com/XploreNet/silverstripe-composerupdates
13
 */
14
class ComposerUpdateExtension extends DataExtension
15
{
16
    /**
17
     * @var string
18
     */
19
    protected $jobName = 'CheckComposerUpdatesJob';
20
21
    private static $db = [
0 ignored issues
show
Unused Code introduced by
The property $db is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
22
        'VersionHash' => 'Varchar',
23
        'VersionConstraint' => 'Varchar(50)',
24
        'AvailableVersion' => 'Varchar(50)',
25
        'AvailableHash' => 'Varchar(50)',
26
        'LatestVersion' => 'Varchar(50)',
27
        'LatestHash' => 'Varchar(50)',
28
    ];
29
30
    private static $summary_fields = [
0 ignored issues
show
Unused Code introduced by
The property $summary_fields is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
31
        'AvailableVersion' => 'Available',
32
        'LatestVersion' => 'Latest',
33
    ];
34
35
    /**
36
     * Automatically schedule a self update job on dev/build
37
     */
38
    public function requireDefaultRecords()
39
    {
40
        Injector::inst()->get(QueuedJobService::class)->queueJob($this->getJobName());
41
    }
42
43
    /**
44
     * If the available version is the same as the current version then return nothing, otherwise show the latest
45
     * available version
46
     *
47
     * @return string
48
     */
49
    public function getAvailableVersion()
50
    {
51
        if ($this->owner->getField('Version') === $this->owner->getField('AvailableVersion')) {
52
            return '';
53
        }
54
        return $this->owner->getField('AvailableVersion');
55
    }
56
57
    /**
58
     * Return the name of the related job
59
     *
60
     * @return string
61
     */
62
    public function getJobName()
63
    {
64
        return $this->jobName;
65
    }
66
}
67