Completed
Pull Request — master (#109)
by Jason
06:12
created

defaultSliderSettings()   C

Complexity

Conditions 8
Paths 2

Size

Total Lines 32
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 72

Importance

Changes 0
Metric Value
dl 0
loc 32
ccs 0
cts 23
cp 0
rs 5.3846
c 0
b 0
f 0
cc 8
eloc 23
nc 2
nop 0
crap 72
1
<?php
2
3
namespace Dynamic\FlexSlider;
4
5
use SilverStripe\CMS\Model\SiteTree;
6
use SilverStripe\Core\ClassInfo;
7
use SilverStripe\Dev\BuildTask;
8
9
class SlideThumbnailNavMigrationTask extends BuildTask
10
{
11
    /**
12
     * @var string
13
     */
14
    protected $title = 'FlexSlider Default Values';
15
    /**
16
     * @var string
17
     */
18
    protected $description = 'Set default values for slider after the thumbnail nav update';
19
    /**
20
     * @var bool
21
     */
22
    protected $enabled = true;
23
    /**
24
     * @param $request
25
     */
26
    public function run($request)
27
    {
28
        $this->defaultSliderSettings();
29
    }
30
    /**
31
     *
32
     */
33
    public function defaultSliderSettings()
34
    {
35
        $ct = 0;
36
37
        $objects = ClassInfo::subclassesFor('DataObject');
38
        if ($objects) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $objects of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
39
            unset($objects['DataObject']);
40
            foreach ($objects as $object) {
41
                if (singleton($object)->hasExtension('FlexSlider')) {
42
                    foreach ($object::get() as $result) {
43
                        $result->Loop = 1;
44
                        $result->Animate = 1;
45
                        $result->SliderControlNav = 1;
46
                        $result->SliderDirectionNav = 1;
47
                        $result->CarouselControlNav = 0;
48
                        $result->CarouselDirectionNav = 1;
49
                        $result->CarouselThumbnailCt = 6;
50
                        if ($result InstanceOf SiteTree || singleton($object)->hasExtension('VersionedDataobject')) {
51
                            $result->writeToStage('Stage');
52
                            if ($result->isPublished()) {
53
                                $result->publish('Stage', 'Live');
54
                            }
55
                        } else {
56
                            $result->write();
57
                        }
58
                        $ct++;
59
                    }
60
                }
61
            }
62
        }
63
        echo '<p>'.$ct.' Sliders updated.</p>';
64
    }
65
}