rugk/threema-msgapi-sdk-php

View on GitHub

Showing 299 of 299 total issues

The class E2EHelper has a coupling between objects value of 16. Consider to reduce the number of dependencies under 13.
Open

class E2EHelper {
    /**
     * @var Connection
     */
    private $connection;

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

Method encryptImageMessage has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

            UploadFileResult $uploadFileResult,
            EncryptResult $encryptResult,
            $senderPrivateKey,
            $recipientPublicKey,
            $nonce) {
Severity: Minor
Found in source/Threema/MsgApi/Tools/CryptTool.php - About 35 mins to fix

Function writeHelp has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    public function writeHelp(\Closure $writer) {
        if(null !== $writer) {

            foreach($this->commands as $data) {
                if(is_scalar($data)) {
Severity: Minor
Found in source/Threema/Console/Run.php - About 35 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 getInstance has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    public static function getInstance() {
        if(null === self::$instance) {
            foreach(array(
                function() {
                    return self::createInstance(self::TYPE_SODIUM);
Severity: Minor
Found in source/Threema/MsgApi/Tools/CryptTool.php - About 35 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 analyse has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    public static function analyse($file) {
        //check if file exists
        if(false === file_exists($file)) {
            return null;
        }
Severity: Minor
Found in source/Threema/MsgApi/Tools/FileAnalysisTool.php - About 35 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

Avoid too many return statements within this method.
Open

                return 'Message is too long';
Severity: Major
Found in source/Threema/MsgApi/Commands/Results/SendSimpleResult.php - About 30 mins to fix

Missing class import via use statement (line '40', column '14').
Open

            throw new \InvalidArgumentException('please define a message');

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 too many return statements within this method.
Open

                return 'Unknown error';
Severity: Major
Found in source/Threema/MsgApi/Commands/Results/SendE2EResult.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

                return 'Unknown error';
Severity: Major
Found in source/Threema/MsgApi/Commands/Results/LookupIdResult.php - About 30 mins to fix

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

<?php
/**
 * @author Threema GmbH
 * @copyright Copyright (c) 2015-2016 Threema GmbH
 */
Severity: Minor
Found in source/Threema/MsgApi/Commands/Results/LookupIdResult.php and 1 other location - About 30 mins to fix
source/Threema/MsgApi/Commands/Results/UploadFileResult.php on lines 1..50

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

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

Missing class import via use statement (line '42', column '14').
Open

            throw new \InvalidArgumentException('please define a message');

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 too many return statements within this method.
Open

                return new FileMessage(
                    $values->getValue('b'),
                    $values->getValue('t'),
                    $values->getValue('k'),
                    $values->getValue('m'),
Severity: Major
Found in source/Threema/MsgApi/Tools/CryptTool.php - About 30 mins to fix

The method help has a boolean flag argument $shellColors, which is a certain sign of a Single Responsibility Principle violation.
Open

    final public function help($shellColors = true) {

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

Avoid too many return statements within this method.
Open

                return 'Unknown error';
Severity: Major
Found in source/Threema/MsgApi/Commands/Results/SendSimpleResult.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

                return 'A temporary internal server error has occurred';
Severity: Major
Found in source/Threema/MsgApi/Commands/Results/SendE2EResult.php - About 30 mins to fix

Avoid too many return statements within this method.
Open

                return 'Unknown error';
Severity: Major
Found in source/Threema/MsgApi/Commands/Results/UploadFileResult.php - About 30 mins to fix

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

<?php
/**
 * @author Threema GmbH
 * @copyright Copyright (c) 2015-2016 Threema GmbH
 */
Severity: Minor
Found in source/Threema/MsgApi/Commands/Results/UploadFileResult.php and 1 other location - About 30 mins to fix
source/Threema/MsgApi/Commands/Results/LookupIdResult.php on lines 1..50

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

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

Avoid too many return statements within this method.
Open

                return 'A temporary internal server error has occurred';
Severity: Major
Found in source/Threema/MsgApi/Commands/Results/SendSimpleResult.php - About 30 mins to fix

Missing class import via use statement (line '87', column '15').
Open

                throw new \InvalidArgumentException();
Severity: Minor
Found in source/Threema/MsgApi/Receiver.php by phpmd

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

Function fetchPublicKey has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function fetchPublicKey($threemaId) {
        $publicKey = null;

        if (null !== $this->publicKeyStore) {
            $publicKey = $this->publicKeyStore->getPublicKey($threemaId);
Severity: Minor
Found in source/Threema/MsgApi/Connection.php - About 25 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