YetiForceCompany/YetiForceCRM

View on GitHub
api/webservice/Core/TwoFactorAuth.php

Summary

Maintainability
A
0 mins
Test Coverage
D
63%

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

            throw new \Exception('Incorrect 2FA TOTP code');
Severity: Minor
Found in api/webservice/Core/TwoFactorAuth.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\Language' in method 'activate'.
Open

            return \App\Language::translate('ERR_INCORRECT_2FA_TOTP_CODE', 'Other.Exceptions');
Severity: Minor
Found in api/webservice/Core/TwoFactorAuth.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 "authy_secret_key" 4 times.
Open

        if (empty($params['authy_secret_key'])) {
Severity: Critical
Found in api/webservice/Core/TwoFactorAuth.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.

Define and throw a dedicated exception instead of using a generic one.
Open

            throw new \Exception('Incorrect 2FA TOTP code');

If you throw a general exception type, such as ErrorException, RuntimeException, or Exception in a library or framework, it forces consumers to catch all exceptions, including unknown exceptions that they do not know how to handle.

Instead, either throw a subtype that already exists in the Standard PHP Library, or create your own type that derives from Exception.

Noncompliant Code Example

throw new Exception();  // Noncompliant

Compliant Solution

throw new InvalidArgumentException();
// or
throw new UnexpectedValueException();

See

Call to method __construct from undeclared class \PragmaRX\Google2FA\Google2FA
Open

        if (!(new Google2FA())->verifyKey($auth['authy_secret_key'], (string) $this->action->controller->request->get('code'))) {
Severity: Critical
Found in api/webservice/Core/TwoFactorAuth.php by phan

Call to method __construct from undeclared class \PragmaRX\Google2FA\Google2FA
Open

            'secretKey' => (new Google2FA())->generateSecretKey(),
Severity: Critical
Found in api/webservice/Core/TwoFactorAuth.php by phan

Doc-block of generate contains declared return type string which is incompatible with the return type array declared in the signature
Open

     * @return string
Severity: Minor
Found in api/webservice/Core/TwoFactorAuth.php by phan

Call to method __construct from undeclared class \PragmaRX\Google2FA\Google2FA
Open

        if (!(new Google2FA())->verifyKey($secret, (string) $code)) {
Severity: Critical
Found in api/webservice/Core/TwoFactorAuth.php by phan

Call to method generateSecretKey from undeclared class \PragmaRX\Google2FA\Google2FA
Open

            'secretKey' => (new Google2FA())->generateSecretKey(),
Severity: Critical
Found in api/webservice/Core/TwoFactorAuth.php by phan

Doc-block of delete contains declared return type string which is incompatible with the return type void declared in the signature
Open

     * @return string
Severity: Minor
Found in api/webservice/Core/TwoFactorAuth.php by phan

Call to method verifyKey from undeclared class \PragmaRX\Google2FA\Google2FA
Open

        if (!(new Google2FA())->verifyKey($secret, (string) $code)) {
Severity: Critical
Found in api/webservice/Core/TwoFactorAuth.php by phan

Call to method verifyKey from undeclared class \PragmaRX\Google2FA\Google2FA
Open

        if (!(new Google2FA())->verifyKey($auth['authy_secret_key'], (string) $this->action->controller->request->get('code'))) {
Severity: Critical
Found in api/webservice/Core/TwoFactorAuth.php by phan

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

    public function __construct(BaseAction $action)

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

     *

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

    public function isActive(): bool

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

    {

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

    /**

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

     * Check if authorization is active.

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

     */

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

    /**

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

    {

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

     * @return bool

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

     *

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

     */

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

        $this->action = $action;

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

    }

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

    /** @var \Api\Core\BaseAction Action instance */

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

     * Constructor.

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

     * @param \Api\Core\BaseAction $action

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

    /**

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

        }

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

            'secretKey' => (new Google2FA())->generateSecretKey(),

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

        ]);

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

     * @throws \Api\Core\Exception

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

     *

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

    public function activate(): string

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

    /**

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

     */

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

     * @throws \Api\Core\Exception

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

        }

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

        if ($this->action->controller->request->isEmpty('code')) {

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

        return '';

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

            return false;

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

        }

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

     * Check auth secret key.

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

        $params = $this->action->getUserData('auth');

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

     * Generate secret key.

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

    public function generate(): array

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

            'authMethods' => 'TOTP',

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

        ];

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

     * @return array

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

     */

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

        return 'Ok';

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

    }

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

     */

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

        }

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

     */

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

    {

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

    public function details(): array

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

     * @return string

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

                'authy_secret_key' => '',

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

            ],

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

        $code = $this->action->controller->request->getByType('code', \App\Purifier::ALNUM);

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

        $this->action->updateUser([

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

            ],

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

    {

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

        if (!(new Google2FA())->verifyKey($auth['authy_secret_key'], (string) $this->action->controller->request->get('code'))) {

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

     */

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

            'authMethods' => 'TOTP',

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

    }

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

     *

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

     */

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

        $auth = $this->action->getUserData('auth');

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

    public function hasRequiresAdditionalData(): string

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

        if (empty($auth) || empty($auth['authy_methods']) || '-' === $auth['authy_methods']) {

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

        return '';

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

    }

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

    /**

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

     * @return void

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

    /**

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

    public function check(): string

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

     *

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

    {

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

     *

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

    {

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

     * @return string

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

    {

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

    public function delete(): void

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

            'auth' => [

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

    /**

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

        if (!(new Google2FA())->verifyKey($secret, (string) $code)) {

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

    {

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

     */

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

        if (empty($params['authy_secret_key'])) {

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

     *

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

        ];

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

        $secret = $this->action->controller->request->getByType('secret', \App\Purifier::ALNUM);

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

                'authy_secret_key' => $secret,

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

     * Verification of the required data entry.

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

        return true;

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

     * @return string

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

        return [

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

     * Get details.

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

        return [

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

     * Verify secret key.

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

    }

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

     * @return string

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

    {

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

        $this->action->updateUser([

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

     * Verify secret key.

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

            throw new \Exception('Incorrect 2FA TOTP code');

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

            return '2FA TOTP secret not generated';

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

        ]);

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

    }

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

     * @return string

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

    public function verify(): void

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

     *

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

            return 'ERR_NO_2FA_TOTP_CODE';

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

    }

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

     *

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

            return \App\Language::translate('ERR_INCORRECT_2FA_TOTP_CODE', 'Other.Exceptions');

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

     *

Line exceeds 120 characters; contains 129 characters
Open

        if (!(new Google2FA())->verifyKey($auth['authy_secret_key'], (string) $this->action->controller->request->get('code'))) {

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

    private $action;

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

    }

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

    /**

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

     * Delete authy secret key.

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

     *

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

        $auth = $this->action->getUserData('auth');

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

    }

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

    /**

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

        }

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

            'auth' => [

There are no issues that match your filters.

Category
Status