Method _getFields
has 121 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function _getFields()
{
return [
ThreemaGateway_Model_Messages::DB_TABLE_MESSAGES => [
'message_id' => [
Function _preSave
has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring. Open
protected function _preSave()
{
// filter data
// also uses existing data as a data base as otherwise the main table
// may also get deleted because of missing message id
- 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
File Messages.php
has 306 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* DataWriter for Threema messages.
*
* @package ThreemaGateway
Method _getExistingData
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function _getExistingData($data)
{
/** @var string $messageId */
if (!$messageId = $this->_getExistingPrimaryKey($data, 'message_id')) {
return false;
Method _preSave
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
protected function _preSave()
{
// filter data
// also uses existing data as a data base as otherwise the main table
// may also get deleted because of missing message id
Function _getExistingData
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
protected function _getExistingData($data)
{
/** @var string $messageId */
if (!$messageId = $this->_getExistingPrimaryKey($data, 'message_id')) {
return false;
- 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 _postSave
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
protected function _postSave()
{
// get data
$allFiles = $this->getExtraData(self::DATA_FILES);
$ackedMsgIds = $this->getExtraData(self::DATA_ACKED_MSG_IDS);
- 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
The method _preSave() has an NPath complexity of 1350. The configured NPath complexity threshold is 200. Open
protected function _preSave()
{
// filter data
// also uses existing data as a data base as otherwise the main table
// may also get deleted because of missing message id
- Read upRead up
- Exclude checks
NPathComplexity
Since: 0.1
The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.
Example
class Foo {
function bar() {
// lots of complicated code
}
}
Source https://phpmd.org/rules/codesize.html#npathcomplexity
The method _getFields() has 124 lines of code. Current threshold is set to 100. Avoid really long methods. Open
protected function _getFields()
{
return [
ThreemaGateway_Model_Messages::DB_TABLE_MESSAGES => [
'message_id' => [
- Exclude checks
The method _preSave() has a Cyclomatic Complexity of 16. The configured cyclomatic complexity threshold is 10. Open
protected function _preSave()
{
// filter data
// also uses existing data as a data base as otherwise the main table
// may also get deleted because of missing message id
- 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
Missing class import via use statement (line '253', column '49'). Open
throw new XenForo_Exception(new XenForo_Phrase('threemagw_unknown_message_type'));
- 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 '253', column '27'). Open
throw new XenForo_Exception(new XenForo_Phrase('threemagw_unknown_message_type'));
- 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_Helper_General' in method 'getRoundedReceiveDate'. Open
$receiveDate = ThreemaGateway_Helper_General::roundToDay($receiveDate);
- 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 'ThreemaGateway_Helper_Message' in method '_preDelete'. Open
if (ThreemaGateway_Helper_Message::isAtRiskOfReplayAttack($this->_existingData[ThreemaGateway_Model_Messages::DB_TABLE_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
Avoid assigning values to variables in if clauses and the like (line '196', column '14'). Open
protected function _getExistingData($data)
{
/** @var string $messageId */
if (!$messageId = $this->_getExistingPrimaryKey($data, 'message_id')) {
return false;
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
Avoid unused parameters such as '$tableName'. Open
protected function _getUpdateCondition($tableName)
- Read upRead up
- Exclude checks
UnusedFormalParameter
Since: 0.2
Avoid passing parameters to methods or constructors and then not using those parameters.
Example
class Foo
{
private function bar($howdy)
{
// $howdy is not used
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter
The method _postDelete is not named in camelCase. Open
protected function _postDelete()
{
// skip custom deletion if main table has already been deleted and is
// therefore stil in the fields array
if (isset($this->_fields[ThreemaGateway_Model_Messages::DB_TABLE_MESSAGES])) {
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _preSave is not named in camelCase. Open
protected function _preSave()
{
// filter data
// also uses existing data as a data base as otherwise the main table
// may also get deleted because of missing message id
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _postSave is not named in camelCase. Open
protected function _postSave()
{
// get data
$allFiles = $this->getExtraData(self::DATA_FILES);
$ackedMsgIds = $this->getExtraData(self::DATA_ACKED_MSG_IDS);
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _getFields is not named in camelCase. Open
protected function _getFields()
{
return [
ThreemaGateway_Model_Messages::DB_TABLE_MESSAGES => [
'message_id' => [
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _getUpdateCondition is not named in camelCase. Open
protected function _getUpdateCondition($tableName)
{
return 'message_id = ' . $this->_db->quote($this->getExisting('message_id'));
}
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _getMessagesModel is not named in camelCase. Open
protected function _getMessagesModel()
{
return $this->getModelFromCache('ThreemaGateway_Model_Messages');
}
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _preDelete is not named in camelCase. Open
protected function _preDelete()
{
// we may need to store the message ID to prevent replay attacks
if (ThreemaGateway_Helper_Message::isAtRiskOfReplayAttack($this->_existingData[ThreemaGateway_Model_Messages::DB_TABLE_MESSAGES])) {
// remove main table from deletion as it is handled in _postDelete().
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}
Source
The method _getExistingData is not named in camelCase. Open
protected function _getExistingData($data)
{
/** @var string $messageId */
if (!$messageId = $this->_getExistingPrimaryKey($data, 'message_id')) {
return false;
- Read upRead up
- Exclude checks
CamelCaseMethodName
Since: 0.2
It is considered best practice to use the camelCase notation to name methods.
Example
class ClassName {
public function get_name() {
}
}