rhosocial/rho.social

View on GitHub
api.rho.social/modules/v1/helpers/AccessToken.php

Summary

Maintainability
A
1 hr
Test Coverage

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

    public static function generateAccessToken()
    {
        if (function_exists('mcrypt_create_iv')) {
            $randomData = mcrypt_create_iv(20, MCRYPT_DEV_URANDOM);
            if ($randomData !== false && strlen($randomData) === 20) {
Severity: Minor
Found in api.rho.social/modules/v1/helpers/AccessToken.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

The method generateAccessToken() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10.
Open

    public static function generateAccessToken()
    {
        if (function_exists('mcrypt_create_iv')) {
            $randomData = mcrypt_create_iv(20, MCRYPT_DEV_URANDOM);
            if ($randomData !== false && strlen($randomData) === 20) {

CyclomaticComplexity

Since: 0.1

Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

Example

// Cyclomatic Complexity = 11
class Foo {
1   public function example() {
2       if ($a == $b) {
3           if ($a1 == $b1) {
                fiddle();
4           } elseif ($a2 == $b2) {
                fiddle();
            } else {
                fiddle();
            }
5       } elseif ($c == $d) {
6           while ($c == $d) {
                fiddle();
            }
7        } elseif ($e == $f) {
8           for ($n = 0; $n < $h; $n++) {
                fiddle();
            }
        } else {
            switch ($z) {
9               case 1:
                    fiddle();
                    break;
10              case 2:
                    fiddle();
                    break;
11              case 3:
                    fiddle();
                    break;
                default:
                    fiddle();
                    break;
            }
        }
    }
}

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

Missing class import via use statement (line '98', column '23').
Open

            throw new \yii\web\ServerErrorHttpException('Access Token Failed to Issue.', 10013);

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

Remove error control operator '@' on line 121.
Open

    public static function generateAccessToken()
    {
        if (function_exists('mcrypt_create_iv')) {
            $randomData = mcrypt_create_iv(20, MCRYPT_DEV_URANDOM);
            if ($randomData !== false && strlen($randomData) === 20) {

ErrorControlOperator

Error suppression should be avoided if possible as it doesn't just suppress the error, that you are trying to stop, but will also suppress errors that you didn't predict would ever occur. Consider changing error_reporting() level and/or setting up your own error handler.

Example

function foo($filePath) {
    $file = @fopen($filPath); // hides exceptions
    $key = @$array[$notExistingKey]; // assigns null to $key
}

Source http://phpmd.org/rules/cleancode.html#errorcontroloperator

Avoid using static access to class '\common\models\OauthAccessToken' in method 'setAccessToken'.
Open

        $model = OauthAccessToken::findOne(['client_id' => $client_id, 'user_uuid' => $user_uuid]);

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 'rho_api\modules\v1\helpers\AuthorizationCode' in method 'setAccessToken'.
Open

        $user_uuid = AuthorizationCode::findUserUuid($authorization_code);

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 '\common\models\OauthAccessToken' in method 'checkAccessToken'.
Open

        $model = OauthAccessToken::findOne($access_token);

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 '\common\models\OauthAuthorizationCode' in method 'createAccessToken'.
Open

        $code = OauthAuthorizationCode::findOne(['authorization_code' => $authorization_code]);

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 'rho_api\modules\v1\helpers\AuthorizationCode' in method 'createAccessToken'.
Open

            AuthorizationCode::expireAuthorizationCode($code);

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

The parameter $expires_in is not named in camelCase.
Open

    public static function setAccessToken($client_id, $authorization_code, $access_token, $expires_in)
    {
        $user_uuid = AuthorizationCode::findUserUuid($authorization_code);

        $model = OauthAccessToken::findOne(['client_id' => $client_id, 'user_uuid' => $user_uuid]);

CamelCaseParameterName

Since: 0.2

It is considered best practice to use the camelCase notation to name parameters.

Example

class ClassName {
    public function doSomething($user_name) {
    }
}

Source

The parameter $authorization_code is not named in camelCase.
Open

    public static function createAccessToken($client_id, $authorization_code)
    {
        $token = [
            "access_token" => self::generateAccessToken(),
            "expires_in" => Yii::$app->params['access_lifetime'],

CamelCaseParameterName

Since: 0.2

It is considered best practice to use the camelCase notation to name parameters.

Example

class ClassName {
    public function doSomething($user_name) {
    }
}

Source

The parameter $access_token is not named in camelCase.
Open

    public static function setAccessToken($client_id, $authorization_code, $access_token, $expires_in)
    {
        $user_uuid = AuthorizationCode::findUserUuid($authorization_code);

        $model = OauthAccessToken::findOne(['client_id' => $client_id, 'user_uuid' => $user_uuid]);

CamelCaseParameterName

Since: 0.2

It is considered best practice to use the camelCase notation to name parameters.

Example

class ClassName {
    public function doSomething($user_name) {
    }
}

Source

The parameter $access_token is not named in camelCase.
Open

    public static function checkAccessToken($access_token)
    {
        $model = OauthAccessToken::findOne($access_token);
        if (!$model) {
            throw new ForbiddenHttpException("Invalid Access Token.", 10011);

CamelCaseParameterName

Since: 0.2

It is considered best practice to use the camelCase notation to name parameters.

Example

class ClassName {
    public function doSomething($user_name) {
    }
}

Source

The parameter $authorization_code is not named in camelCase.
Open

    public static function setAccessToken($client_id, $authorization_code, $access_token, $expires_in)
    {
        $user_uuid = AuthorizationCode::findUserUuid($authorization_code);

        $model = OauthAccessToken::findOne(['client_id' => $client_id, 'user_uuid' => $user_uuid]);

CamelCaseParameterName

Since: 0.2

It is considered best practice to use the camelCase notation to name parameters.

Example

class ClassName {
    public function doSomething($user_name) {
    }
}

Source

The parameter $client_id is not named in camelCase.
Open

    public static function createAccessToken($client_id, $authorization_code)
    {
        $token = [
            "access_token" => self::generateAccessToken(),
            "expires_in" => Yii::$app->params['access_lifetime'],

CamelCaseParameterName

Since: 0.2

It is considered best practice to use the camelCase notation to name parameters.

Example

class ClassName {
    public function doSomething($user_name) {
    }
}

Source

The parameter $client_id is not named in camelCase.
Open

    public static function setAccessToken($client_id, $authorization_code, $access_token, $expires_in)
    {
        $user_uuid = AuthorizationCode::findUserUuid($authorization_code);

        $model = OauthAccessToken::findOne(['client_id' => $client_id, 'user_uuid' => $user_uuid]);

CamelCaseParameterName

Since: 0.2

It is considered best practice to use the camelCase notation to name parameters.

Example

class ClassName {
    public function doSomething($user_name) {
    }
}

Source

Line exceeds 120 characters; contains 121 characters
Open

        $setResult = self::setAccessToken($client_id, $authorization_code, $token['access_token'], $token['expires_in']);

Whitespace found at end of line
Open

     * 

The variable $expires_in is not named in camelCase.
Open

    public static function setAccessToken($client_id, $authorization_code, $access_token, $expires_in)
    {
        $user_uuid = AuthorizationCode::findUserUuid($authorization_code);

        $model = OauthAccessToken::findOne(['client_id' => $client_id, 'user_uuid' => $user_uuid]);

CamelCaseVariableName

Since: 0.2

It is considered best practice to use the camelCase notation to name variables.

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The variable $authorization_code is not named in camelCase.
Open

    public static function createAccessToken($client_id, $authorization_code)
    {
        $token = [
            "access_token" => self::generateAccessToken(),
            "expires_in" => Yii::$app->params['access_lifetime'],

CamelCaseVariableName

Since: 0.2

It is considered best practice to use the camelCase notation to name variables.

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The variable $authorization_code is not named in camelCase.
Open

    public static function createAccessToken($client_id, $authorization_code)
    {
        $token = [
            "access_token" => self::generateAccessToken(),
            "expires_in" => Yii::$app->params['access_lifetime'],

CamelCaseVariableName

Since: 0.2

It is considered best practice to use the camelCase notation to name variables.

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The variable $client_id is not named in camelCase.
Open

    public static function setAccessToken($client_id, $authorization_code, $access_token, $expires_in)
    {
        $user_uuid = AuthorizationCode::findUserUuid($authorization_code);

        $model = OauthAccessToken::findOne(['client_id' => $client_id, 'user_uuid' => $user_uuid]);

CamelCaseVariableName

Since: 0.2

It is considered best practice to use the camelCase notation to name variables.

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The variable $authorization_code is not named in camelCase.
Open

    public static function setAccessToken($client_id, $authorization_code, $access_token, $expires_in)
    {
        $user_uuid = AuthorizationCode::findUserUuid($authorization_code);

        $model = OauthAccessToken::findOne(['client_id' => $client_id, 'user_uuid' => $user_uuid]);

CamelCaseVariableName

Since: 0.2

It is considered best practice to use the camelCase notation to name variables.

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The variable $user_uuid is not named in camelCase.
Open

    public static function setAccessToken($client_id, $authorization_code, $access_token, $expires_in)
    {
        $user_uuid = AuthorizationCode::findUserUuid($authorization_code);

        $model = OauthAccessToken::findOne(['client_id' => $client_id, 'user_uuid' => $user_uuid]);

CamelCaseVariableName

Since: 0.2

It is considered best practice to use the camelCase notation to name variables.

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The variable $user_uuid is not named in camelCase.
Open

    public static function setAccessToken($client_id, $authorization_code, $access_token, $expires_in)
    {
        $user_uuid = AuthorizationCode::findUserUuid($authorization_code);

        $model = OauthAccessToken::findOne(['client_id' => $client_id, 'user_uuid' => $user_uuid]);

CamelCaseVariableName

Since: 0.2

It is considered best practice to use the camelCase notation to name variables.

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The variable $client_id is not named in camelCase.
Open

    public static function createAccessToken($client_id, $authorization_code)
    {
        $token = [
            "access_token" => self::generateAccessToken(),
            "expires_in" => Yii::$app->params['access_lifetime'],

CamelCaseVariableName

Since: 0.2

It is considered best practice to use the camelCase notation to name variables.

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The variable $client_id is not named in camelCase.
Open

    public static function setAccessToken($client_id, $authorization_code, $access_token, $expires_in)
    {
        $user_uuid = AuthorizationCode::findUserUuid($authorization_code);

        $model = OauthAccessToken::findOne(['client_id' => $client_id, 'user_uuid' => $user_uuid]);

CamelCaseVariableName

Since: 0.2

It is considered best practice to use the camelCase notation to name variables.

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The variable $access_token is not named in camelCase.
Open

    public static function setAccessToken($client_id, $authorization_code, $access_token, $expires_in)
    {
        $user_uuid = AuthorizationCode::findUserUuid($authorization_code);

        $model = OauthAccessToken::findOne(['client_id' => $client_id, 'user_uuid' => $user_uuid]);

CamelCaseVariableName

Since: 0.2

It is considered best practice to use the camelCase notation to name variables.

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The variable $access_token is not named in camelCase.
Open

    public static function checkAccessToken($access_token)
    {
        $model = OauthAccessToken::findOne($access_token);
        if (!$model) {
            throw new ForbiddenHttpException("Invalid Access Token.", 10011);

CamelCaseVariableName

Since: 0.2

It is considered best practice to use the camelCase notation to name variables.

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

The variable $user_uuid is not named in camelCase.
Open

    public static function setAccessToken($client_id, $authorization_code, $access_token, $expires_in)
    {
        $user_uuid = AuthorizationCode::findUserUuid($authorization_code);

        $model = OauthAccessToken::findOne(['client_id' => $client_id, 'user_uuid' => $user_uuid]);

CamelCaseVariableName

Since: 0.2

It is considered best practice to use the camelCase notation to name variables.

Example

class ClassName {
    public function doSomething() {
        $data_module = new DataModule();
    }
}

Source

There are no issues that match your filters.

Category
Status