YetiForceCompany/YetiForceCRM

View on GitHub
app/YetiForce/Encryption.php

Summary

Maintainability
A
0 mins
Test Coverage

Missing class import via use statement (line '44', column '33').
Open

        return \App\Json::decode((new \App\Encryption($this->getConfig()))->decrypt($data, true)) ?: [];
Severity: Minor
Found in app/YetiForce/Encryption.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

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

        return (new \App\Encryption($this->getConfig()))->encrypt(\App\Json::encode($data), true);
Severity: Minor
Found in app/YetiForce/Encryption.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

Avoid using static access to class '\App\Json' in method 'encrypt'.
Open

        return (new \App\Encryption($this->getConfig()))->encrypt(\App\Json::encode($data), true);
Severity: Minor
Found in app/YetiForce/Encryption.php by phpmd

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 '\App\Json' in method 'decrypt'.
Open

        return \App\Json::decode((new \App\Encryption($this->getConfig()))->decrypt($data, true)) ?: [];
Severity: Minor
Found in app/YetiForce/Encryption.php by phpmd

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 '\App\Encryption' in method 'getDefaultData'.
Open

            'pass' => \App\Encryption::generatePassword(10),
Severity: Minor
Found in app/YetiForce/Encryption.php by phpmd

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

Define a constant instead of duplicating this literal "vector" 3 times.
Open

            'vector' => base64_encode(openssl_random_pseudo_bytes(openssl_cipher_iv_length(self::DEFAULT_METHOD))),
Severity: Critical
Found in app/YetiForce/Encryption.php by sonar-php

Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

Noncompliant Code Example

With the default threshold of 3:

function run() {
  prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
  execute('action1');
  release('action1');
}

Compliant Solution

ACTION_1 = 'action1';

function run() {
  prepare(ACTION_1);
  execute(ACTION_1);
  release(ACTION_1);
}

Exceptions

To prevent generating some false-positives, literals having less than 5 characters are excluded.

Call to method __construct from undeclared class \App\Encryption (Did you mean class \Tests\App\Encryption)
Open

        return (new \App\Encryption($this->getConfig()))->encrypt(\App\Json::encode($data), true);
Severity: Critical
Found in app/YetiForce/Encryption.php by phan

Call to method __construct from undeclared class \App\YetiForce\Config (Did you mean class \App\Config or class \Tests\App\Config)
Open

        $data = (new Config())->getData();
Severity: Critical
Found in app/YetiForce/Encryption.php by phan

Call to method encrypt from undeclared class \App\Encryption (Did you mean class \Tests\App\Encryption)
Open

        return (new \App\Encryption($this->getConfig()))->encrypt(\App\Json::encode($data), true);
Severity: Critical
Found in app/YetiForce/Encryption.php by phan

Call to method getData from undeclared class \App\YetiForce\Config (Did you mean class \App\Config or class \Tests\App\Config)
Open

        $data = (new Config())->getData();
Severity: Critical
Found in app/YetiForce/Encryption.php by phan

Call to method decrypt from undeclared class \App\Encryption (Did you mean class \Tests\App\Encryption)
Open

        return \App\Json::decode((new \App\Encryption($this->getConfig()))->decrypt($data, true)) ?: [];
Severity: Critical
Found in app/YetiForce/Encryption.php by phan

Call to method generatePassword from undeclared class \App\Encryption (Did you mean class \Tests\App\Encryption)
Open

            'pass' => \App\Encryption::generatePassword(10),
Severity: Critical
Found in app/YetiForce/Encryption.php by phan

Call to method __construct from undeclared class \App\Encryption (Did you mean class \Tests\App\Encryption)
Open

        return \App\Json::decode((new \App\Encryption($this->getConfig()))->decrypt($data, true)) ?: [];
Severity: Critical
Found in app/YetiForce/Encryption.php by phan

Avoid variables with short names like $iv. Configured minimum length is 3.
Open

        $iv = $data['vector'] ?? '';
Severity: Minor
Found in app/YetiForce/Encryption.php by phpmd

ShortVariable

Since: 0.2

Detects when a field, local, or parameter has a very short name.

Example

class Something {
    private $q = 15; // VIOLATION - Field
    public static function main( array $as ) { // VIOLATION - Formal
        $r = 20 + $this->q; // VIOLATION - Local
        for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
            $r += $this->q;
        }
    }
}

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

Spaces must be used to indent lines; tabs are not allowed
Open

    public function getDefaultData(): array
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

        return [
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    /**
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    public const DEFAULT_METHOD = 'AES-128-CBC';
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    public function encrypt(array $data): string
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    /**
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     *
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    }
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    {
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    {
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     * Get default configuration data for encryption.
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

        unset($data['key']);
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            $data['vector'] = base64_decode($iv);
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     */
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return string
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    {
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     *
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    {
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return array
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    /** @var string Default encryption method */
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     * @param array $data
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return array
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     * Data encryption function.
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     *
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

        return (new \App\Encryption($this->getConfig()))->encrypt(\App\Json::encode($data), true);
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            'method' => self::DEFAULT_METHOD,
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

        $iv = $data['vector'] ?? '';
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    /**
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     *
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    private function getConfig(): array
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     *
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     * @param string $data
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    /**
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     * Data decryption function.
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    public function decrypt(string $data): array
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     */
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

        return \App\Json::decode((new \App\Encryption($this->getConfig()))->decrypt($data, true)) ?: [];
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

        ];
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

        return $data;
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            'pass' => \App\Encryption::generatePassword(10),
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     * Configuration data for encryption.
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     */
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            'vector' => base64_encode(openssl_random_pseudo_bytes(openssl_cipher_iv_length(self::DEFAULT_METHOD))),
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

        $data = (new Config())->getData();
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

        }
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

        if ($iv) {
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     *
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     */
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    }
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     * @return array
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    }
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    }
Severity: Minor
Found in app/YetiForce/Encryption.php by phpcodesniffer

There are no issues that match your filters.

Category
Status