The method get has a boolean flag argument $remove, which is a certain sign of a Single Responsibility Principle violation. Open
public static function get(string $uid, bool $remove = true): ?array
- Read upRead up
- Exclude checks
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
Missing class import via use statement (line '88', column '15'). Open
$row = (new \App\Db\Query())->from('s_#__tokens')->where(['uid' => $uid])->one(\App\Db::getInstance('admin')) ?: null;
- Read upRead up
- Exclude checks
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 '50', column '14'). Open
throw new \App\Exceptions\AppException("The method `$method` does not exist");
- Read upRead up
- Exclude checks
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\Db' in method 'get'. Open
$row = (new \App\Db\Query())->from('s_#__tokens')->where(['uid' => $uid])->one(\App\Db::getInstance('admin')) ?: null;
- Read upRead up
- Exclude checks
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 'generate'. Open
'params' => \App\Json::encode($params),
- Read upRead up
- Exclude checks
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 'generateUid'. Open
$uid = \App\Encryption::generatePassword(64);
- Read upRead up
- Exclude checks
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 'get'. Open
$row['params'] = \App\Json::decode($row['params']);
- Read upRead up
- Exclude checks
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\User' in method 'generate'. Open
'created_by_user' => \App\User::getCurrentUserRealId(),
- Read upRead up
- Exclude checks
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 "params" 4 times. Open
return \call_user_func($tokenData['method'], $tokenData['params']);
- Read upRead up
- Exclude checks
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 a constant instead of duplicating this literal "expiration_date" 3 times. Open
'expiration_date' => $expirationDate,
- Read upRead up
- Exclude checks
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 a constant instead of duplicating this literal "s_#__tokens" 3 times. Open
\App\Db::getInstance('admin')->createCommand()->insert('s_#__tokens', [
- Read upRead up
- Exclude checks
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 a constant instead of duplicating this literal "admin" 3 times. Open
\App\Db::getInstance('admin')->createCommand()->insert('s_#__tokens', [
- Read upRead up
- Exclude checks
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 undeclared method \App\Db::createCommand
Open
\App\Db::getInstance('admin')->createCommand()->insert('s_#__tokens', [
- Exclude checks
Call to method generatePassword
from undeclared class \App\Encryption
(Did you mean class \Tests\App\Encryption) Open
$uid = \App\Encryption::generatePassword(64);
- Exclude checks
Call to undeclared method \App\Db\Query::from
Open
$row = (new \App\Db\Query())->from('s_#__tokens')->where(['uid' => $uid])->one(\App\Db::getInstance('admin')) ?: null;
- Exclude checks
Call to method getCurrentUserRealId
from undeclared class \App\User
(Did you mean class \Tests\App\User) Open
'created_by_user' => \App\User::getCurrentUserRealId(),
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
\App\Db::getInstance('admin')->createCommand()->delete('s_#__tokens', ['uid' => $uid])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Generate uid function.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'params' => \App\Json::encode($params),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Get token detail.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$row = (new \App\Db\Query())->from('s_#__tokens')->where(['uid' => $uid])->one(\App\Db::getInstance('admin')) ?: null;
- Exclude checks
Line exceeds 120 characters; contains 126 characters Open
$row = (new \App\Db\Query())->from('s_#__tokens')->where(['uid' => $uid])->one(\App\Db::getInstance('admin')) ?: null;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function generate(string $method, array $params, string $expirationDate = null): string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Db::getInstance('admin')->createCommand()->insert('s_#__tokens', [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Execute token method.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'expiration_date' => $expirationDate,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $uid
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function execute(string $uid, array $tokenData = null): bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'created_by_user' => \App\User::getCurrentUserRealId(),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $uid
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $method Method name
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param array $params
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private static function generateUid(): string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($remove) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return void
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Db::getInstance('admin')->createCommand()->delete('s_#__tokens', ['uid' => $uid])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$tokenData = self::get($uid);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new \App\Exceptions\AppException("The method `$method` does not exist");
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'created_date' => date('Y-m-d H:i:s'),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($row['expiration_date']) && strtotime($row['expiration_date']) < time()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function delete(string $uid): void
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (null !== $tokenData) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return \call_user_func($tokenData['method'], $tokenData['params']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!\is_callable($method) && !class_exists($method)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$uid = self::generateUid();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param bool $remove
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array|null
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param array|null $tokenData
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Generate token.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'method' => $method,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function get(string $uid, bool $remove = true): ?array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$row = null;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($row) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $row;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$row['params'] = \App\Json::decode($row['params']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (null !== self::get($uid)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return self::generateUid();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
self::delete($uid);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (null === $tokenData) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string|null $expirationDate Date and time until which the token is valid
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'uid' => $uid,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $uid;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $uid
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$uid = \App\Encryption::generatePassword(64);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
self::delete($uid);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $uid;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Delete token.
- Exclude checks