validatePreConditions accesses the super-global variable $_SERVER. Open
public function validatePreConditions(&$errorString)
{
/** @var XenForo_Options $options */
$options = XenForo_Application::getOptions();
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
The class ThreemaGateway_Handler_Action_Callback has an overall complexity of 59 which is very high. The configured complexity threshold is 50. Open
class ThreemaGateway_Handler_Action_Callback extends ThreemaGateway_Handler_Action_Abstract
{
/**
* @var string used by strtotime to allow messages sent in the future
*/
- Exclude checks
File Callback.php
has 286 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* Allows XenForo to receive Threema messages by providing a callback.
*
* @package ThreemaGateway
Method processMessage
has 51 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function processMessage($downloadPath, $debugMode = false)
{
/** @var string $output */
$output = '';
Method saveMessage
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function saveMessage(
Threema\MsgApi\Helpers\ReceiveMessageResult $receiveResult,
Threema\MsgApi\Messages\ThreemaMessage $threemaMsg
) {
$dataWriter = XenForo_DataWriter::create('ThreemaGateway_DataWriter_Messages');
Method getLogData
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function getLogData(
Threema\MsgApi\Helpers\ReceiveMessageResult $receiveResult,
Threema\MsgApi\Messages\ThreemaMessage $threemaMsg
) {
$eol = PHP_EOL;
Method validatePreConditions
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function validatePreConditions(&$errorString)
{
/** @var XenForo_Options $options */
$options = XenForo_Application::getOptions();
Method validateRequest
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function validateRequest(&$errorString)
{
// access token validation (authentication of Gateway server)
/** @var XenForo_Options $options */
$options = XenForo_Application::getOptions();
Consider simplifying this complex logical expression. Open
if (!$this->input->inRequest('from') ||
!$this->input->inRequest('to') ||
!$this->input->inRequest('messageId') ||
!$this->input->inRequest('date') ||
!$this->input->inRequest('nonce') ||
Function validatePreConditions
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function validatePreConditions(&$errorString)
{
/** @var XenForo_Options $options */
$options = XenForo_Application::getOptions();
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function addLog
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function addLog(&$log, $stringToAdd, $stringToAddDetail = null)
{
// convert to array if necessary or just add string
if (is_string($log)) {
if ($stringToAddDetail) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function saveMessage
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
protected function saveMessage(
Threema\MsgApi\Helpers\ReceiveMessageResult $receiveResult,
Threema\MsgApi\Messages\ThreemaMessage $threemaMsg
) {
$dataWriter = XenForo_DataWriter::create('ThreemaGateway_DataWriter_Messages');
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function processMessage
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function processMessage($downloadPath, $debugMode = false)
{
/** @var string $output */
$output = '';
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this method. Open
return true;
The method validatePreConditions() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10. Open
public function validatePreConditions(&$errorString)
{
/** @var XenForo_Options $options */
$options = XenForo_Application::getOptions();
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
The class ThreemaGateway_Handler_Action_Callback has a coupling between objects value of 18. Consider to reduce the number of dependencies under 13. Open
class ThreemaGateway_Handler_Action_Callback extends ThreemaGateway_Handler_Action_Abstract
{
/**
* @var string used by strtotime to allow messages sent in the future
*/
- Read upRead up
- Exclude checks
CouplingBetweenObjects
Since: 1.1.0
A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability
Example
class Foo {
/**
* @var \foo\bar\X
*/
private $x = null;
/**
* @var \foo\bar\Y
*/
private $y = null;
/**
* @var \foo\bar\Z
*/
private $z = null;
public function setFoo(\Foo $foo) {}
public function setBar(\Bar $bar) {}
public function setBaz(\Baz $baz) {}
/**
* @return \SplObjectStorage
* @throws \OutOfRangeException
* @throws \InvalidArgumentException
* @throws \ErrorException
*/
public function process(\Iterator $it) {}
// ...
}
Source https://phpmd.org/rules/design.html#couplingbetweenobjects
Missing class import via use statement (line '225', column '23'). Open
throw new XenForo_Exception('Download dir ' . $downloadPath . ' cannot be accessed.');
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '277', column '23'). Open
throw new XenForo_Exception('Message could not be saved: [' . get_class($e) . '] ' . $e->getMessage());
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '244', column '23'). Open
throw new XenForo_Exception('Message cannot be processed: [ResultErrors] ' . implode('|', $receiveResult->getErrors()));
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
The method processMessage has a boolean flag argument $debugMode, which is a certain sign of a Single Responsibility Principle violation. Open
public function processMessage($downloadPath, $debugMode = false)
- Read upRead up
- Exclude checks
BooleanArgumentFlag
Since: 1.4.0
A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.
Example
class Foo {
public function bar($flag = true) {
}
}
Source https://phpmd.org/rules/cleancode.html#booleanargumentflag
Missing class import via use statement (line '240', column '23'). Open
throw new XenForo_Exception('Message cannot be processed: [' . get_class($e) . '] ' . $e->getMessage());
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '342', column '25'). Open
$receiver = new ThreemaGateway_Handler_Action_Receiver(true, true);
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '346', column '23'). Open
throw new XenForo_Exception('Message "' . $messageId . '" has already been received and is already saved. This may indicate a replay attack.');
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '41', column '28'). Open
$this->input = new XenForo_Input($request);
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Avoid using static access to class 'ThreemaGateway_Handler_Validation' in method 'processMessage'. Open
if (!ThreemaGateway_Handler_Validation::checkDir($downloadPath)) {
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class 'XenForo_Application' in method 'validateFormalities'. Open
$options = XenForo_Application::getOptions();
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class 'XenForo_Error' in method 'processMessage'. Open
XenForo_Error::logException($e);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class 'XenForo_CodeEvent' in method 'processMessage'. Open
XenForo_CodeEvent::fire('threemagw_message_callback_postsave', [
$this,
$receiveResult,
$threemaMsg,
&$output,
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class 'XenForo_DataWriter' in method 'saveMessage'. Open
$dataWriter = XenForo_DataWriter::create('ThreemaGateway_DataWriter_Messages');
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
The method addLog uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$log .= PHP_EOL . $stringToAdd;
return;
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid using static access to class 'XenForo_Application' in method 'validatePreConditions'. Open
$options = XenForo_Application::getOptions();
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class 'XenForo_Application' in method 'validateRequest'. Open
$options = XenForo_Application::getOptions();
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class 'XenForo_Error' in method 'processMessage'. Open
XenForo_Error::logException($e);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
The method processMessage uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$this->saveMessageId($receiveResult->getMessageId());
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid using static access to class 'XenForo_CodeEvent' in method 'processMessage'. Open
XenForo_CodeEvent::fire('threemagw_message_callback_presave', [
$this,
$receiveResult,
$threemaMsg,
&$output,
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class 'XenForo_DataWriter' in method 'saveMessageId'. Open
$dataWriter = XenForo_DataWriter::create('ThreemaGateway_DataWriter_Messages');
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}