Issues (49)

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.

ChangeNotificationPresentationModel.php (2 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
namespace SMW\Notifications\ChangeNotification;
4
5
use EchoEvent;
6
use EchoEventPresentationModel;
7
use Title;
8
use SMW\DIProperty;
9
10
/**
11
 * @license GNU GPL v2+
12
 * @since 1.0
13
 *
14
 * @author mwjames
15
 */
16
class ChangeNotificationPresentationModel extends EchoEventPresentationModel {
17
18
	/**
19
	 * @see EchoEventPresentationModel::getIconType
20
	 */
21 4
	public function getIconType() {
22
23 4
		if ( $this->event->getType() !== ChangeNotificationFilter::SPECIFICATION_CHANGE ) {
24 1
			return $this->event->getType();
25
		}
26
27 3
		$namespace = $this->event->getTitle()->getNamespace();
28
29
		// @see EchoNotificationsManager::addNotificationsDefinitions for the icons
30 3
		if ( $namespace === NS_CATEGORY || $namespace === SMW_NS_CONCEPT ) {
31 2
			return $this->event->getType() . '-category';
32
		}
33
34 1
		return $this->event->getType() . '-property';
35
	}
36
37
	/**
38
	 * @see EchoEventPresentationModel::canRender
39
	 */
40 1
	public function canRender() {
41 1
		return (bool)$this->event->getTitle();
42
	}
43
44
	/**
45
	 * @param EchoEvent
46
	 * @return string
47
	 */
48 2
	public function callbackForBundleCount( EchoEvent $event ) {
49 2
		return $event->getTitle()->getPrefixedText();
50
	}
51
52
	/**
53
	 * @see EchoEventPresentationModel::getHeaderMessageKey
54
	 */
55 2
	public function getHeaderMessageKey() {
56
57 2
		if ( $this->getBundleCount( true, [ $this, 'callbackForBundleCount' ] ) > 1 ) {
58
			return "notification-bundle-header-{$this->type}";
59
		}
60
61 2
		return "notification-header-{$this->type}";
62
	}
63
64
	/**
65
	 * @see EchoEventPresentationModel::getHeaderMessage
66
	 */
67 1
	public function getHeaderMessage() {
68
69 1
		$extra = $this->event->getExtra();
70 1
		$msg = parent::getHeaderMessage();
71
72 1
		$msg->params(
73 1
			$this->getTruncatedTitleText( $this->event->getTitle(), true )
74
		);
75
76
		// Plural indicator
77 1
		$msg->params(
78 1
			( isset( $extra['properties'] ) ? count( $extra['properties'] ) : 0 )
79
		);
80
81 1
		$count = $this->getNotificationCountForOutput(
82 1
			false, // we need only other pages count
83 1
			[ $this, 'callbackForBundleCount' ]
84
		);
85
86 1
		if ( $count > 0 ) {
87
			$msg->numParams( $count );
88
		}
89
90 1
		return $msg;
91
	}
92
93
	/**
94
	 * @see EchoEventPresentationModel::getBodyMessage
95
	 */
96 5
	public function getBodyMessage() {
97
98 5
		$extra = $this->event->getExtra();
99 5
		$labels = array();
100
101 5
		if ( !isset( $extra['properties'] ) || $extra['properties'] === array() ) {
102 3
			return false;
103
		}
104
105 2
		foreach ( $extra['properties'] as $dataItem ) {
106
107 2
			$prefix = '';
108
109 2
			if ( $dataItem->getDBKey() === '' ) {
110 1
				continue;
111
			}
112
113 2
			if ( $dataItem->getNamespace() === NS_CATEGORY ) {
114
				$prefix = $this->language->getNsText( NS_CATEGORY ) . ':';
115
			}
116
117
			try {
118 2
				$labels[] = $prefix . DIProperty::newFromUserLabel( $dataItem->getDBKey() )->getLabel();
119
			} catch ( \SMW\Exception\PredefinedPropertyLabelMismatchException $e ) {
120
				continue;
121
			}
122
		}
123
124 2
		$msg = wfMessage( "notification-body-{$this->type}" );
125 2
		$msg->params( $this->language->listToText( $labels ) );
126 2
		$msg->params( count( $labels ) );
127
128 2
		return $msg;
129
	}
130
131
	/**
132
	 * @see EchoEventPresentationModel::getPrimaryLink
133
	 */
134 3
	public function getPrimaryLink() {
135 3
		$title = $this->event->getTitle();
136
		return array(
137 3
			'url' => $title->getFullURL(),
138 3
			'label' => $title->getFullText()
139
		);
140
	}
141
142
	/**
143
	 * @see EchoEventPresentationModel::getSecondaryLinks
144
	 */
145 3
	public function getSecondaryLinks() {
146
147 3
		$extra = $this->event->getExtra();
0 ignored issues
show
$extra 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...
148 3
		$title = $this->event->getTitle();
149
150 3
		$queryParameters['oldid'] = 'prev';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$queryParameters was never initialized. Although not strictly required by PHP, it is generally a good practice to add $queryParameters = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
151
152 3
		if ( $this->event->getExtraParam( 'revid' ) > 0 ) {
153 3
			$queryParameters['diff'] = $this->event->getExtraParam( 'revid' );
154
		}
155
156
		$viewChangesLink = array(
157 3
			'url'   => $title->getLocalURL( $queryParameters ),
158 3
			'label' => $this->msg( 'notification-link-text-view-changes', $this->getViewingUserForGender() )->text(),
159 3
			'description' => '',
160 3
			'icon' => 'changes',
161
			'prioritized' => true,
162
		);
163
164 3
		return array( $this->getAgentLink(), $viewChangesLink );
165
	}
166
167
}
168