PresentationPage_Controller::index()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
class PresentationPage extends Page
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
6
    private static $splash_image_location = '/assets/splasimages';
0 ignored issues
show
Unused Code introduced by
The property $splash_image_location 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...
7
8
    private static $db = array(
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...
9
        'Website' => "Varchar(100)",
10
        'StartSlogan' => "Varchar(100)"
11
    );
12
    private static $has_one = array(
0 ignored issues
show
Unused Code introduced by
The property $has_one 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...
13
        'BackgroundImage' => "Image"
14
    );
15
16
    private static $icon = "mysite/images/treeicons/Presentation";
0 ignored issues
show
Unused Code introduced by
The property $icon 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...
17
18
    public function getCMSFields()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
19
    {
20
        $fields = parent::getCMSFields();
21
        $fields->addFieldToTab("Root.Splash", TextField::create('Website'));
22
        $fields->addFieldToTab("Root.Splash", TextField::create('StartSlogan'));
23
        $fields->addFieldToTab("Root.Splash", UploadField::create('BackgroundImage','Background Image'));
24
        $fields->addFieldToTab("Root.Splash", HtmlEditorField::create('Content'));
25
        return $fields;
26
    }
27
28
}
29
30
class PresentationPage_Controller extends Page_Controller
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
31
{
32
33
34
    function init()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
35
    {
36
        ContentController::init();
37
    }
38
39
40
    public function index()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
41
    {
42
        return $this->renderWith('PresentationPage_Splash');
43
    }
44
45
46
    /**
47
     * Private variables to locally cache the selected image index and
48
     * shuffled array with the images URLs
49
     */
50
    private $_selectedImage = null;
51
52
    private $_shuffledImages = array();
53
54
55
    /**
56
     * Returns the URL of the first image to be shown on the Splash
57
     * @return String
58
     */
59
    public function getRandomSplashImage()
60
    {
61
62
        if ($this->_selectedImage === null) {
63
            if($this->BackgroundImageID) {
64
                if($image = $this->BackgroundImage()) {
65
                    $this->_selectedImage = $image->Link();
66
                }
67
            }
68
            if ($this->_selectedImage === null) {
69
                $this->_shuffledImages = Config::inst()->get('PresentationPage', 'splash_images');
70
                shuffle($this->_shuffledImages);
71
                $randomIndex = array_rand($this->_shuffledImages);
72
                $this->_selectedImage = Config::inst()->get('PresentationPage', 'splash_image_location').
73
                    '/'.
74
                    $this->_shuffledImages[$randomIndex];
75
            }
76
        }
77
        return $this->_selectedImage;
78
    }
79
80
    /**
81
     * Returns the index of the first image to be shown on the Presentation Page Splash.
82
     * @return Integer
0 ignored issues
show
Documentation introduced by
Should the return type not be string?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
83
     */
84
    public function getRandomSplashImageIndex()
85
    {
86
        return $this->_selectedImage;
87
    }
88
89
    /**
90
     * Generates a Javascript Array command from the list of Shuffled images.
91
     * @return String
92
     */
93
    public function getJavaImageArray()
94
    {
95
        $imageArray  = $this->_shuffledImages; //Config::inst()->get('Presentation Page', 'splash_images');
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
96
        return "new Array('/images/".implode("', '/images/", $imageArray)."'),";
97
    }
98
99
    /**
100
     * Returns an html message with tags other tahn <a><span> removed.
101
     * @return String
102
     */
103
    public function getSplashMessageClean()
104
    {
105
        $strippedHMTL = str_replace('>', '>', $this->Content);
106
        $strippedHMTL = strip_tags($strippedHMTL, '<a><span>');
107
        $strippedHMTL = str_replace('&nbsp;', ' ', $strippedHMTL);
108
        $obj = DBField::create_field('Varchar', $strippedHMTL);
109
        $value = $obj->raw();
110
        $value = str_replace("'", '&rsquo;', $value);
111
        $value = str_replace("\r", ' ', $value);
112
        $value = str_replace("\n", ' ', $value);
113
        $value = str_replace("\t", ' ', $value);
114
        $value = preg_replace("/\s{1,}/", " ", $value);;
0 ignored issues
show
Coding Style introduced by
It is generally recommended to place each PHP statement on a line by itself.

Let’s take a look at an example:

// Bad
$a = 5; $b = 6; $c = 7;

// Good
$a = 5;
$b = 6;
$c = 7;
Loading history...
115
        if(strlen($value) < 10) {
116
            return 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam.';
117
        }
118
119
        return $value;
120
    }
121
122 View Code Duplication
    function PreviousPage()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
123
    {
124
        return PresentationPage::get()
125
            ->sort(array('Sort' => 'DESC'))
126
            ->where('Sort < '.$this->Sort.' AND ShowInSearch = 1')
127
            ->First();
128
    }
129
130 View Code Duplication
    function NextPage()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
131
    {
132
        return PresentationPage::get()
133
            ->where('Sort >= '.$this->Sort.'  AND ShowInSearch = 1')
134
            ->sort(array('Sort' => 'ASC'))
135
            ->exclude(array('ID' => $this->ID))
136
            ->First();
137
    }
138
139
}
140