StaticPublishingTriggerPage   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 33
rs 10
c 1
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A generatePublishable() 0 7 1
A objectsToUpdate() 0 7 3
A objectsToDelete() 0 7 3
1
<?php
2
3
namespace SilverStripe\StaticPublishQueue\Test\SiteTreePublishingEngineTest\Model;
4
5
use SilverStripe\CMS\Model\SiteTree;
6
use SilverStripe\Dev\TestOnly;
7
use SilverStripe\ORM\ArrayList;
8
use SilverStripe\StaticPublishQueue\Contract\StaticPublishingTrigger;
9
10
class StaticPublishingTriggerPage extends SiteTree implements TestOnly, StaticPublishingTrigger
11
{
12
    private static $table_name = 'SPQ_StaticPublishingTriggerPage';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
13
14
    public function generatePublishable($url, $prio)
15
    {
16
        $obj = StaticallyPublishablePage::create();
17
        $obj->url = $url;
18
        $obj->prio = $prio;
19
20
        return $obj;
21
    }
22
23
    public function objectsToUpdate($context)
24
    {
25
        switch ($context['action']) {
26
            case 'publish':
27
                return new ArrayList([$this->generatePublishable('/updateOnPublish', 10)]);
28
            case 'unpublish':
29
                return new ArrayList([$this->generatePublishable('/updateOnUnpublish', 10)]);
30
        }
31
    }
32
33
    /**
34
     * Remove the object on unpublishing (the parent will get updated via objectsToUpdate).
35
     */
36
    public function objectsToDelete($context)
37
    {
38
        switch ($context['action']) {
39
            case 'publish':
40
                return new ArrayList([$this->generatePublishable('/deleteOnPublish', 10)]);
41
            case 'unpublish':
42
                return new ArrayList([$this->generatePublishable('/deleteOnUnpublish', 10)]);
43
        }
44
    }
45
}
46