rugk/threema-msgapi-sdk-php

View on GitHub

Showing 299 of 299 total issues

Avoid using short method names like Common::e(). The configured minimum method name length is 3.
Open

    public static function e($msg) {
        $STDERR = fopen('php://stderr', 'w+');
        fwrite($STDERR, $msg."\n");

    }
Severity: Minor
Found in source/Threema/Console/Common.php by phpmd

ShortMethodName

Since: 0.2

Detects when very short method names are used.

Example

class ShortMethod {
    public function a( $index ) { // Violation
    }
}

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

Avoid using short method names like Common::l(). The configured minimum method name length is 3.
Open

    public static function l($string = '', $indent = 0) {
        $pad = str_repeat('  ', $indent);
        echo $pad . wordwrap($string, 100, "\n" . $pad) . "\n";
    }
Severity: Minor
Found in source/Threema/Console/Common.php by phpmd

ShortMethodName

Since: 0.2

Detects when very short method names are used.

Example

class ShortMethod {
    public function a( $index ) { // Violation
    }
}

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

Avoid using short method names like Common::ln(). The configured minimum method name length is 3.
Open

    public static function ln($string = '') {
        echo $string . "\n";
    }
Severity: Minor
Found in source/Threema/Console/Common.php by phpmd

ShortMethodName

Since: 0.2

Detects when very short method names are used.

Example

class ShortMethod {
    public function a( $index ) { // Violation
    }
}

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

Function __construct has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    public function __construct($threemaId, $secret, $host = null, array $tlsOptions = null) {
        $this->threemaId = $threemaId;
        $this->secret = $secret;
        if ($host === null) {
            $host = 'https://msgapi.threema.ch';
Severity: Minor
Found in source/Threema/MsgApi/ConnectionSettings.php - About 1 hr 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

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/MsgApi/Commands/LookupEmail.php and 1 other location - About 1 hr to fix
source/Threema/MsgApi/Commands/LookupPhone.php on lines 1..56

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 105.

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/MsgApi/Commands/LookupPhone.php and 1 other location - About 1 hr to fix
source/Threema/MsgApi/Commands/LookupEmail.php on lines 1..56

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 105.

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 sendFileMessage has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public final function sendFileMessage($threemaId, $filePath, $thumbnailPath = null) {
        //analyse the file
        $fileAnalyzeResult = FileAnalysisTool::analyse($filePath);

        if(null === $fileAnalyzeResult) {
Severity: Minor
Found in source/Threema/MsgApi/Helpers/E2EHelper.php - About 1 hr to fix

Avoid using undefined variables such as '$p' which will lead to PHP notices.
Open

        $p['box'] = $cryptTool->bin2hex($this->getBox());

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

Source https://phpmd.org/rules/cleancode.html#undefinedvariable

Avoid using undefined variables such as '$p' which will lead to PHP notices.
Open

        return $p;

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

Source https://phpmd.org/rules/cleancode.html#undefinedvariable

Avoid using undefined variables such as '$p' which will lead to PHP notices.
Open

        $p['nonce'] = $cryptTool->bin2hex($this->getNonce());

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

Source https://phpmd.org/rules/cleancode.html#undefinedvariable

Avoid using undefined variables such as '$p' which will lead to PHP notices.
Open

        $p['to'] = $this->threemaId;

UndefinedVariable

Since: 2.8.0

Detects when a variable is used that has not been defined before.

Example

class Foo
{
    private function bar()
    {
        // $message is undefined
        echo $message;
    }
}

Source https://phpmd.org/rules/cleancode.html#undefinedvariable

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/HashEmail.php and 1 other location - About 1 hr to fix
source/Threema/Console/Command/HashPhone.php on lines 1..28

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 103.

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/HashPhone.php and 1 other location - About 1 hr to fix
source/Threema/Console/Command/HashEmail.php on lines 1..28

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 103.

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 initFile has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function initFile($fileHandle = null)
    {
        //check if file does already contain content
        if (filesize($this->file) != 0) {
            return true;
Severity: Minor
Found in source/Threema/MsgApi/PublicKeyStores/PhpFile.php - About 1 hr to fix

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

<?php

use Threema\MsgApi\Connection;
use Threema\MsgApi\ConnectionSettings;

Severity: Major
Found in samples/testKeyLookup.php and 1 other location - About 1 hr to fix
samples/testFetchPublicKey.php on lines 1..31

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 102.

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

use Threema\MsgApi\Connection;
use Threema\MsgApi\ConnectionSettings;

Severity: Major
Found in samples/testFetchPublicKey.php and 1 other location - About 1 hr to fix
samples/testKeyLookup.php on lines 1..29

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 102.

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 sendImageMessage has 26 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public final function sendImageMessage($threemaId, $imagePath) {
        //analyse the file
        $fileAnalyzeResult = FileAnalysisTool::analyse($imagePath);

        if(null === $fileAnalyzeResult) {
Severity: Minor
Found in source/Threema/MsgApi/Helpers/E2EHelper.php - About 1 hr to fix

Method checkMac has 8 arguments (exceeds 4 allowed). Consider refactoring.
Open

    public final function checkMac($threemaId, $gatewayId, $messageId, $date, $nonce, $box, $mac, $secret) {
Severity: Major
Found in source/Threema/MsgApi/Helpers/E2EHelper.php - About 1 hr to fix

Function decryptMessage has a Cognitive Complexity of 9 (exceeds 5 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: Minor
Found in source/Threema/MsgApi/Tools/CryptTool.php - About 55 mins 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 stringCompare has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    public function stringCompare($str1, $str2)
    {
        if (function_exists('hash_equals')) {
            return hash_equals($str1, $str2);
        } else {
Severity: Minor
Found in source/Threema/MsgApi/Tools/CryptTool.php - About 55 mins 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

Severity
Category
Status
Source
Language