Issues (25)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

code/SlidePage.php (12 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
* Defines the StaffPage page type.
4
*/
5
class SlidePage 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...
6
{
7
    public static $db = array(
8
        'Caption' => 'Text',
9
    );
10
11
    public static $has_one = array(
12
        'Photo' => 'Image',
13
        'InternalPage' => 'SiteTree',
14
    );
15
16
    public static $allowed_children = 'none';
17
18
    private static $defaults = array(
0 ignored issues
show
The property $defaults 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...
19
       'ShowInMenus' => false,
20
       'ShowInSearch' => false,
21
    );
22
23
    public function getThumbnail2()
24
    {
25
        return $this->InternalPage()->getPortletImage()->CMSThumbnail()->Tag;
26
    }
27
28
    public function getCMSFields()
29
    {
30
        Requirements::javascript('slider/javascript/slideredit.js');
31
32
        $fields = parent::getCMSFields();
33
        $existing_photo = null;
34
        $photo_field = null;
0 ignored issues
show
$photo_field 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...
35
        $internal_page = $this->InternalPage();
36
37
        if ($internal_page instanceof RenderableAsPortlet) {
0 ignored issues
show
The class RenderableAsPortlet does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
38
            error_log('Class implements renderable as a portlet');
39
            $existing_photo = $this->InternalPage()->getPortletImage();
40
        } else {
41
            // check parents recursively
42
            $parents = class_parents($internal_page);
43
            error_log(print_r($parents, 1));
44
        }
45
46
        $fields->addFieldToTab('Root.Main',
47
            new TreeDropdownField('InternalPageID', _t('SlidePage.CHOOSE_INTERNAL_LINK', 'Select a page on the website to link to'), 'SiteTree'));
48
49
        $composite_photoField = null;
0 ignored issues
show
$composite_photoField 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...
50
51
        if (!$existing_photo) {
52
            $photo_field = new UploadField('Photo', _t('SlidePage.PHOTO', 'Photo'));
53
            $photo_info = new LiteralField('PhotoInfo', _t('Slide.PHOTO_INFO', 'If the page you choose to link to has an image already it will appear here'), 'Photo');
0 ignored issues
show
The call to LiteralField::__construct() has too many arguments starting with 'Photo'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
54
            $composite_photoField = CompositeField::create($photo_field, $photo_info);
55
        } else {
56
            // FIXME, find a cleaner way of doing this
57
            $composite_photoField = new LiteralField('Thumbnail2', '<div id="Thumbnail2" class="field readonly">
58
    <label class="left" for="Form_EditForm_Thumbnail2">Photo</label>
59
    <div class="middleColumn">
60
    <span id="Form_EditForm_Thumbnail2" class="readonly">
61
        <img src="'.$existing_photo->SetWidth(400)->URL.'" alt="'.$existing_photo->Title.'" />
62
    </span>
63
    </div>
64
</div>');
65
        }
66
67
        $composite_photoField->setTitle('Photo');
68
        $fields->addFieldToTab('Root.Main', $composite_photoField);
69
        $fields->addFieldToTab('Root.Main', new TextField('Caption', _t('SlidePage.CAPTION', 'Caption')));
70
        $fields->renameField('Title', 'Slide Title');
71
72
        $fields->removeFieldFromTab('Root.Main', 'Content');
73
74
        return $fields;
75
    }
76
77
    /*
78
    Accessible from templates as $PortletImage
79
    */
80
    public function getPortletImage()
81
    {
82
        $image = null;
0 ignored issues
show
$image 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...
83
        if ($this->InternalPage() instanceof RenderableAsPortlet) {
0 ignored issues
show
The class RenderableAsPortlet does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
84
            $image = $this->InternalPage()->getPortletImage();
85
        } else {
86
            $image = $this->Photo();
87
        }
88
89
        return $image;
90
    }
91
92
    public function getThumbnail()
93
    {
94
        if ($Image = $this->Photo()) {
95
            return $Image->CMSThumbnail();
96
        } else {
97
            return '(No Image)';
98
        }
99
    }
100
101
    public function getWebsiteAddress()
102
    {
103
        $result = '#"';
104
105
        if ($this->InternalPageID) {
106
            $targetPage = DataObject::get_by_id('Page', $this->InternalPageID);
107
            if ($targetPage) {
108
                $result = $targetPage->Link();
109
            } else {
110
                $result = '#';
111
            }
112
        }
113
114
        return $result;
115
    }
116
}
117
118
class SlidePage_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...
This class is not in CamelCase format.

Classes in PHP are usually named in CamelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. The whole name starts with a capital letter as well.

Thus the name database provider becomes DatabaseProvider.

Loading history...
119
{
120
    private static $allowed_actions = array('newpageselected' => true);
0 ignored issues
show
The property $allowed_actions 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...
121
122
    /*
123
    When a new item is selected return JSON containing the title and image
124
    */
125
    public function newpageselected(SS_HTTPRequest $request)
126
    {
127
        $sitetree_id = $request->param('ID');
128
        $page = SiteTree::get_by_id($sitetree_id);
129
        $result = array();
130
        if ($page) {
131
            $result['Title'] = $page->Title;
132
        }
133
        return json_encode($result);
134
    }
135
}
136