Issues (64)

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/model/UpdateNoteExtension.php (8 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
5
class UpdateNoteExtension extends DataExtension
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
    private static $has_many = array(
0 ignored issues
show
The property $has_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...
8
        'UpdateNotes' => 'UpdateNote'
9
    );
10
11
    private static $seconds_grace = 600;
0 ignored issues
show
The property $seconds_grace 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...
12
13
    private static $latest_limit = 600;
0 ignored issues
show
The property $latest_limit 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...
14
15
    private static $_run_once_only = array();
16
17
    /**
18
     * Event handler called after writing to the database.
19
     */
20
    public function onAfterWrite()
21
    {
22
        parent::onAfterWrite();
23
        $id = $this->owner->ID;
24
        $class = $this->owner->ClassName;
25
        $userID = Member::currentUserID();
26
        $filter = array(
27
            'UpdateNoteRecordID' => $id,
28
            'UpdateNoteRecordClass' => $class,
29
            'UpdatedByID' => $userID
30
        );
31
        $key = implode('_', $filter);
32
        if (! isset(self::$_run_once_only[$key])) {
33
            self::$_run_once_only[$key] = true;
34
            $now = SS_Datetime::now()->Rfc2822();
35
            $gracePointInTime = strtotime($now) - Config::inst()->get('UpdateNoteExtension', 'seconds_grace');
36
            $log = DataObject::get_one(
37
                'UpdateNote',
38
                $filter,
39
                $cacheDataObjectGetOne = false,
40
                array('Created' => 'DESC')
0 ignored issues
show
array('Created' => 'DESC') is of type array<string,string,{"Created":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
41
            );
42
            if ($log) {
43
                $editPointInTime = strtotime($log->Created);
44
                debug::log(Date('l jS \of F Y h:i:s A', $editPointInTime).'...'.Date('l jS \of F Y h:i:s A', $gracePointInTime));
45
                if ($editPointInTime < $gracePointInTime) {
46
                    $log = null;
47
                }
48
            }
49
            if ($log && $log->exists()) {
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...
50
                //already exists ...
51
            } else {
52
                $log = UpdateNote::create($filter);
53
            }
54
            $log->write();
55
        }
56
    }
57
58
    /**
59
     * Update Fields
60
     * @return FieldList
61
     */
62
    public function updateCMSFields(FieldList $fields)
63
    {
64
        $owner = $this->owner;
0 ignored issues
show
$owner 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...
65
        $name = Injector::inst()->get('UpdateNote')->i18n_plural_name();
66
        $fields->addFieldToTab(
67
            'Root.'.$name,
68
            GridField::create(
69
                'UpdateNotes',
70
                $name,
71
                $this->owner->UpdateNotes(),
72
                GridFieldConfig_RecordEditor::create()
73
            )
74
        );
75
76
        return $fields;
77
    }
78
79
    /**
80
     * Event handler called before deleting from the database.
81
     */
82
    public function onBeforeDelete()
83
    {
84
        foreach ($this->owner->UpdateNotes() as $note) {
85
            $note->delete();
86
        }
87
    }
88
89
90
    public function LatestUpdateNotes()
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...
91
    {
92
        return $this->owner->UpdateNotes()
93
            ->limit(Config::inst()->get('xx', 'latest_limit'));
94
    }
95
}
96