PageNotFound_Controller   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A set_old_to_new_array() 0 4 1
B init() 0 18 5
1
<?php
2
/**
3
 * ErrorPage holds the content for the page of an error response.
4
 * Renders the page on each publish action into a static HTML file
5
 * within the assets directory, after the naming convention
6
 * /assets/error-<statuscode>.html.
7
 * This enables us to show errors even if PHP experiences a recoverable error.
8
 * ErrorPages
9
 *
10
 * @see Debug::friendlyError()
11
 *
12
 * @package cms
13
 */
14
class PageNotFound extends ErrorPage
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...
15
{
16
    public static $icon = "mysite/images/treeIcons/PageNotFound";
17
18
    public static $hide_ancestor = "ErrorPage";
19
20
    public function doPublish()
21
    {
22
        parent::doPublish();
23
    }
24
}
25
/**
26
 * Controller for ErrorPages.
27
 * @package cms
28
 */
29
class PageNotFound_Controller extends ErrorPage_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...
30
{
31
    private static $old_to_new_array = array();
32
33
    public static function set_old_to_new_array(array $a)
34
    {
35
        self::$old_to_new_array = $a;
36
    }
37
38
    public function init()
39
    {
40
        parent::init();
41
        $bt = defined('DB::USE_ANSI_SQL') ? "\"" : "`";
0 ignored issues
show
Unused Code introduced by
$bt is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
42
        $page = null;
0 ignored issues
show
Unused Code introduced by
$page is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
43
        //NOTE: this function (Director::urlParam) is depreciated, but should actuall be kept
44
        $URLSegment = Director::urlParam("URLSegment");
0 ignored issues
show
Deprecated Code introduced by
The method Director::urlParam() has been deprecated with message: 3.0 Use SS_HTTPRequest->latestParam()

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
45
        $Action = Director::urlParam("Action");
0 ignored issues
show
Deprecated Code introduced by
The method Director::urlParam() has been deprecated with message: 3.0 Use SS_HTTPRequest->latestParam()

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
46
        foreach (self::$old_to_new_array as $oldURL => $newURL) {
47
            if ($URLSegment == $oldURL) {
48
                $page = DataObject::get_one("SiteTree", "URLSegment = '$newURL'");
49
                Director::redirect($page->Link(), 301);
50
            } elseif ($URLSegment."/".$Action == $oldURL) {
51
                $page = DataObject::get_one("SiteTree", "URLSegment = '$newURL'");
52
                Director::redirect($page->Link(), 301);
53
            }
54
        }
55
    }
56
}
57