rugk/threema-msgapi-sdk-php

View on GitHub

Showing 299 of 299 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

<?php
/**
 * @author Threema GmbH
 * @copyright Copyright (c) 2015-2016 Threema GmbH
 */
Severity: Major
Found in source/Threema/Console/Command/LookupIdByEmail.php and 1 other location - About 7 hrs to fix
source/Threema/Console/Command/LookupIdByPhoneNo.php on lines 1..55

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 242.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

<?php
/**
 * @author Threema GmbH
 * @copyright Copyright (c) 2015-2016 Threema GmbH
 */
Severity: Major
Found in source/Threema/Console/Command/LookupIdByPhoneNo.php and 1 other location - About 7 hrs to fix
source/Threema/Console/Command/LookupIdByEmail.php on lines 1..55

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 242.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Function receiveMessage has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
Open

    public final function receiveMessage($threemaId,
                                         $messageId,
                                         $box,
                                         $nonce,
                                         $outputFolder = null,
Severity: Minor
Found in source/Threema/MsgApi/Helpers/E2EHelper.php - About 5 hrs to fix

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

CryptTool has 35 functions (exceeds 20 allowed). Consider refactoring.
Open

abstract class CryptTool {
    const TYPE_SODIUM = 'sodium';
    const TYPE_SALT = 'salt';

    const FILE_NONCE = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01";
Severity: Minor
Found in source/Threema/MsgApi/Tools/CryptTool.php - About 4 hrs to fix

The class CryptTool has 21 public methods. Consider refactoring CryptTool to keep number of public methods under 10.
Open

abstract class CryptTool {
    const TYPE_SODIUM = 'sodium';
    const TYPE_SALT = 'salt';

    const FILE_NONCE = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01";

TooManyPublicMethods

Since: 0.1

A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

By default it ignores methods starting with 'get' or 'set'.

Example

Source https://phpmd.org/rules/codesize.html#toomanypublicmethods

The class CryptTool has 29 non-getter- and setter-methods. Consider refactoring CryptTool to keep number of methods under 25.
Open

abstract class CryptTool {
    const TYPE_SODIUM = 'sodium';
    const TYPE_SALT = 'salt';

    const FILE_NONCE = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01";

TooManyMethods

Since: 0.1

A class with too many methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

By default it ignores methods starting with 'get' or 'set'.

The default was changed from 10 to 25 in PHPMD 2.3.

Example

Source https://phpmd.org/rules/codesize.html#toomanymethods

The class CryptTool has an overall complexity of 69 which is very high. The configured complexity threshold is 50.
Open

abstract class CryptTool {
    const TYPE_SODIUM = 'sodium';
    const TYPE_SALT = 'salt';

    const FILE_NONCE = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01";

Method receiveMessage has 68 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public final function receiveMessage($threemaId,
                                         $messageId,
                                         $box,
                                         $nonce,
                                         $outputFolder = null,
Severity: Major
Found in source/Threema/MsgApi/Helpers/E2EHelper.php - About 2 hrs to fix

File CryptTool.php has 272 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * @author Threema GmbH
 * @copyright Copyright (c) 2015-2016 Threema GmbH
 */
Severity: Minor
Found in source/Threema/MsgApi/Tools/CryptTool.php - About 2 hrs to fix

Similar blocks of code found in 2 locations. Consider refactoring.
Open

            if(null !== $result && true === $result->isSuccess()) {
                $file = $this->cryptTool->decryptFile(
                    $result->getData(),
                    $this->cryptTool->hex2bin($message->getEncryptionKey()));

Severity: Major
Found in source/Threema/MsgApi/Helpers/E2EHelper.php and 1 other location - About 2 hrs to fix
source/Threema/MsgApi/Helpers/E2EHelper.php on lines 279..292

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 131.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

                if(null !== $result && true === $result->isSuccess()) {
                    $file = $this->cryptTool->decryptFileThumbnail(
                        $result->getData(),
                        $this->cryptTool->hex2bin($message->getEncryptionKey()));

Severity: Major
Found in source/Threema/MsgApi/Helpers/E2EHelper.php and 1 other location - About 2 hrs to fix
source/Threema/MsgApi/Helpers/E2EHelper.php on lines 261..275

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 131.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Method decryptMessage has 57 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    final public function decryptMessage($box, $recipientPrivateKey, $senderPublicKey, $nonce) {

        $data = $this->openBox($box, $recipientPrivateKey, $senderPublicKey, $nonce);

        if (null === $data || strlen($data) == 0) {
Severity: Major
Found in source/Threema/MsgApi/Tools/CryptTool.php - About 2 hrs to fix

Function createDefaultOptions has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

    private function createDefaultOptions(\Closure $progress = null) {
        $options = array(
            CURLOPT_RETURNTRANSFER => true
        );

Severity: Minor
Found in source/Threema/MsgApi/Connection.php - About 2 hrs to fix

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 run has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

    public function run() {
        $found = null;
        $argumentLength = 0;

        //find the correct command by arguments and arguments count
Severity: Minor
Found in source/Threema/Console/Run.php - About 2 hrs to fix

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 excessively long variable names like $thumbnailUploadResult. Keep variable name length under 20.
Open

        $thumbnailUploadResult = null;

LongVariable

Since: 0.2

Detects when a field, formal or local variable is declared with a long name.

Example

class Something {
    protected $reallyLongIntName = -3; // VIOLATION - Field
    public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
        $otherReallyLongName = -5; // VIOLATION - Local
        for ($interestingIntIndex = 0; // VIOLATION - For
             $interestingIntIndex < 10;
             $interestingIntIndex++ ) {
        }
    }
}

Source https://phpmd.org/rules/naming.html#longvariable

Avoid excessively long variable names like $thumbnailUploadFileResult. Keep variable name length under 20.
Open

                                             UploadFileResult $thumbnailUploadFileResult = null,

LongVariable

Since: 0.2

Detects when a field, formal or local variable is declared with a long name.

Example

class Something {
    protected $reallyLongIntName = -3; // VIOLATION - Field
    public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
        $otherReallyLongName = -5; // VIOLATION - Local
        for ($interestingIntIndex = 0; // VIOLATION - For
             $interestingIntIndex < 10;
             $interestingIntIndex++ ) {
        }
    }
}

Source https://phpmd.org/rules/naming.html#longvariable

Avoid excessively long variable names like $thumbnailEncryptionResult. Keep variable name length under 20.
Open

            $thumbnailEncryptionResult = $this->cryptTool->encryptFileThumbnail(file_get_contents($thumbnailPath), $encryptionResult->getKey());

LongVariable

Since: 0.2

Detects when a field, formal or local variable is declared with a long name.

Example

class Something {
    protected $reallyLongIntName = -3; // VIOLATION - Field
    public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
        $otherReallyLongName = -5; // VIOLATION - Local
        for ($interestingIntIndex = 0; // VIOLATION - For
             $interestingIntIndex < 10;
             $interestingIntIndex++ ) {
        }
    }
}

Source https://phpmd.org/rules/naming.html#longvariable

Method createDefaultOptions has 41 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function createDefaultOptions(\Closure $progress = null) {
        $options = array(
            CURLOPT_RETURNTRANSFER => true
        );

Severity: Minor
Found in source/Threema/MsgApi/Connection.php - About 1 hr to fix

Method doRun has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    protected function doRun() {
        $cryptTool = CryptTool::getInstance();

        $sendersThreemaId = $this->getArgumentThreemaId(self::argThreemaId);
        $id = $this->getArgumentThreemaId(self::argFrom);
Severity: Minor
Found in source/Threema/Console/Command/ReceiveMessage.php - About 1 hr to fix

Method run has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function run() {
        $found = null;
        $argumentLength = 0;

        //find the correct command by arguments and arguments count
Severity: Minor
Found in source/Threema/Console/Run.php - About 1 hr to fix
Severity
Category
Status
Source
Language