Issues (120)

Security Analysis    not enabled

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/WebPortfolioPage.php (13 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
/**
4
 * @author Nicolaas [at] sunnysideup.co.nz
5
 * @package webportfolio
6
 * @sub-packages webportfolio
7
 *
8
 *
9
 *
10
 */
11
12
class WebPortfolioPage 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...
13
{
14
    private static $icon = "webportfolio/images/treeicons/WebPortfolioPage";
0 ignored issues
show
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...
15
16
    private static $db = array(
0 ignored issues
show
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...
17
        'HighlightsOnly' => 'Boolean'
18
    );
19
20
    private static $has_one = array();
0 ignored issues
show
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...
21
22
    private static $many_many = array(
0 ignored issues
show
The property $many_many 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...
23
        "WebPortfolioItems" => "WebPortfolioItem"
24
    );
25
26
    public function getCMSFields()
0 ignored issues
show
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...
27
    {
28
        $fields = parent::getCMSFields();
29
        $itemOptionSet = WebPortfolioItem::get();
30
        $itemOptionSetMap = ($itemOptionSet->count()) ? $itemOptionSet->map('ID', 'Title')->toArray() : array();
31
        $fields->addFieldsToTab(
32
            "Root.Portfolio",
33
            array(
34
                CheckboxField::create(
35
                    'HighlightsOnly',
36
                    'Highlights Only'
37
                ),
38
                LiteralField::create("UpdatePortfolio", "<h3>Update Portfolio</h3>"),
39
                LiteralField::create("EditPortfolio", "<p><a href=\"/admin/webportfolio\" target=\"_blank\">edit portfolio</a></p>"),
40
                LiteralField::create("RefreshPortfolio", "<p><a href=\"".$this->Link("json/?flush=json")."\" target=\"_blank\">clear portfolio cache</a> (portfolio data is cached to increase loading speed)</p>"),
41
                CheckboxSetField::create(
42
                    $name = "WebPortfolioItems",
43
                    $title = "Items shown",
44
                    $source = $itemOptionSetMap
45
                )
46
            )
47
        );
48
        return $fields;
49
    }
50
}
51
52
class WebPortfolioPage_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...
53
{
54
    private static $allowed_actions = array(
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...
55
        "show"
56
    );
57
58 View Code Duplication
    public function init()
0 ignored issues
show
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...
59
    {
60
        parent::init();
61
        Requirements::javascript(THIRDPARTY_DIR."/jquery/jquery.js");
62
        if (class_exists("PrettyPhoto")) {
63
            PrettyPhoto::include_code();
64
        } else {
65
            user_error("It is recommended that you include the PrettyPhoto Module", E_USER_NOTICE);
66
        }
67
        Requirements::javascript("webportfolio/javascript/webportfolio.js");
68
        Requirements::themedCSS("WebPortfolioPage", "webportfolio");
69
    }
70
71
    protected $IDArray = array();
72
    protected $hasFilter = false;
73
    protected $currentCode = "";
74
    protected $currentDescription = "";
75
76
    public function index()
77
    {
78
        if (!$this->HighlightsOnly) {
79
            $this->Title .= " - Favourites";
80
        }
81
        return array();
82
    }
83
84
    public function show()
85
    {
86
        $this->hasFilter = true;
87
        $code = Convert::raw2sql($this->request->param("ID"));
88
        if (is_numeric($code) && intval($code) > 0) {
89
            $this->currentCode = $code;
0 ignored issues
show
Documentation Bug introduced by
It seems like $code can also be of type integer or double. However, the property $currentCode is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
90
            $item = WebPortfolioItem::get()->byID(intval($code));
91
            if ($item) {
92
                $this->IDArray = array($item->ID => $item->ID);
93
                $this->Title .= " - ".$item->getHeadLine();
94
                $this->currentDescription = $item->Notes;
95
            }
96
        } elseif ($code) {
97
            $this->currentCode = $code;
98
            $obj = WebPortfolioWhatWeDidDescriptor::get()->filter(array("Code" => $code))->first();
99
            $this->Title .= " - ".$obj->Name;
100
            if ($obj) {
101
                $this->currentDescription = $obj->Description;
102
                $components = $obj->getManyManyComponents('WebPortfolioItem');
103
                if ($components && $components->count()) {
104
                    $this->IDArray = $components->column("ID");
105
                }
106
            }
107
        }
108
        return array();
109
    }
110
111
    public function SelectedWebPortfolioItems()
0 ignored issues
show
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...
112
    {
113
        if ($this->HighlightsOnly) {
114
            return $this->WebPortfolioItems()
115
                ->sort(array("Favourites" => "DESC", "RAND()" => "ASC"));
116
        }
117
        if ($this->hasFilter) {
0 ignored issues
show
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
118
        } else {
119
            $components = $this->getManyManyComponents('WebPortfolioItems');
120
            if ($components && $components->count()) {
121
                $this->IDArray = $components->column("ID");
122
            }
123
        }
124
        $reset = false;
125
        if (!$this->IDArray) {
126
            $reset = true;
127
        } elseif (!is_array($this->IDArray)) {
128
            $reset = true;
129
        } elseif (!count($this->IDArray)) {
130
            $reset = true;
131
        }
132
        if ($reset) {
133
            $this->IDArray = array(0 => 0);
134
        }
135
        $extraWhere = "";
136
        if (!$this->hasFilter) {
137
            $extraWhere = " AND \"Favourites\" = 1";
138
        }
139
        return WebPortfolioItem::get()
140
            ->where("\"WebPortfolioItem\".\"ID\" IN (".implode(",", $this->IDArray).") AND \"WebPortfolioPage_WebPortfolioItems\".\"WebPortfolioPageID\" = ".$this->ID.$extraWhere)
141
            ->sort(array("Favourites" => "DESC", "RAND()" => "ASC"))
142
            ->innerJoin("WebPortfolioPage_WebPortfolioItems", "\"WebPortfolioPage_WebPortfolioItems\".\"WebPortfolioItemID\" = \"WebPortfolioItem\".\"ID\"");
143
    }
144
145
    public function HasFilter()
146
    {
147
        return $this->hasFilter;
148
    }
149
150
    public function CurrentDescription()
151
    {
152
        return $this->currentDescription;
153
    }
154
155
    public function FilterList()
156
    {
157
        if ($this->HighlightsOnly) {
158
            return null;
159
        }
160
        $items = WebPortfolioWhatWeDidDescriptor::get()
161
            ->innerJoin("WebPortfolioItem_WhatWeDid", " \"WebPortfolioItem_WhatWeDid\".\"WebPortfolioWhatWeDidDescriptorID\" = \"WebPortfolioWhatWeDidDescriptor\".\"ID\"");
162
        foreach ($items as $item) {
163
            if ($item->Code == $this->currentCode) {
164
                $item->LinkingMode = "current";
165
            } else {
166
                $item->LinkingMode = "link";
167
            }
168
        }
169
        return $items;
170
    }
171
}
172