Function recalculatePasswords
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
public static function recalculatePasswords(string $method, string $password, string $vector, int $target)
{
$dbAdmin = \App\Db::getInstance('admin');
$decryptInstance = static::getInstance($target);
if (!$decryptInstance->getTarget() || ($decryptInstance->get('method') === $method && $decryptInstance->get('vector') === $vector && $decryptInstance->get('pass') === $password)) {
- Read upRead up
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
Method recalculatePasswords
has 65 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function recalculatePasswords(string $method, string $password, string $vector, int $target)
{
$dbAdmin = \App\Db::getInstance('admin');
$decryptInstance = static::getInstance($target);
if (!$decryptInstance->getTarget() || ($decryptInstance->get('method') === $method && $decryptInstance->get('vector') === $vector && $decryptInstance->get('pass') === $password)) {
The method recalculatePasswords() has an NPath complexity of 365. The configured NPath complexity threshold is 200. Open
public static function recalculatePasswords(string $method, string $password, string $vector, int $target)
{
$dbAdmin = \App\Db::getInstance('admin');
$decryptInstance = static::getInstance($target);
if (!$decryptInstance->getTarget() || ($decryptInstance->get('method') === $method && $decryptInstance->get('vector') === $vector && $decryptInstance->get('pass') === $password)) {
- Read upRead up
- Exclude checks
NPathComplexity
Since: 0.1
The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.
Example
class Foo {
function bar() {
// lots of complicated code
}
}
Source https://phpmd.org/rules/codesize.html#npathcomplexity
The method recalculatePasswords() has a Cyclomatic Complexity of 16. The configured cyclomatic complexity threshold is 10. Open
public static function recalculatePasswords(string $method, string $password, string $vector, int $target)
{
$dbAdmin = \App\Db::getInstance('admin');
$decryptInstance = static::getInstance($target);
if (!$decryptInstance->getTarget() || ($decryptInstance->get('method') === $method && $decryptInstance->get('vector') === $vector && $decryptInstance->get('pass') === $password)) {
- Read upRead up
- Exclude checks
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
Refactor this function to reduce its Cognitive Complexity from 22 to the 15 allowed. Open
public static function recalculatePasswords(string $method, string $password, string $vector, int $target)
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
The class Module has a coupling between objects value of 14. Consider to reduce the number of dependencies under 13. Open
class Module extends \App\Encryption
{
/** {@inheritdoc} */
public static function getInstance(int $target = \App\Encryption::TARGET_SETTINGS)
{
- Read upRead up
- Exclude checks
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
Missing class import via use statement (line '86', column '17'). Open
throw new \App\Exceptions\AppException('ERR_IMPOSSIBLE_ENCRYPT');
- 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
The method isActive has a boolean flag argument $testMode, which is a certain sign of a Single Responsibility Principle violation. Open
public function isActive(bool $testMode = false)
- 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 '95', column '10'). Open
(new \App\BatchMethod(['method' => __CLASS__ . '::recalculatePasswords', 'params' => [$method, $password, $vector, $target, microtime()]]))->save();
- 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 '133', column '26'). Open
$queryGenerator = (new \App\QueryGenerator($moduleName))->setFields($fields);
- 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 '137', column '45'). Open
$queryGenerator->addNativeCondition((new \yii\db\Expression('0 > 1')));
- 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 '25', column '15'). Open
$row = (new \App\Db\Query())->from(static::TABLE_NAME)->where(['target' => $target])->one(\App\Db::getInstance('admin'));
- 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 '23', column '14'). Open
throw new \App\Exceptions\IllegalValue('ERR_NOT_ALLOWED_VALUE||target', 406);
- 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 '81', column '18'). Open
throw new \App\Exceptions\AppException('ERR_IMPOSSIBLE_DECRYPT');
- 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 '97', column '10'). Open
(new \App\ConfigFile('module', \App\Module::getModuleName($target)))
- 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\Module' in method 'isActive'. Open
$method = \App\Config::module(\App\Module::getModuleName($this->getTarget()), 'encryptionMethod');
- 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
The method recalculatePasswords uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
(new \App\ConfigFile('module', \App\Module::getModuleName($target)))
->set('encryptionMethod', $method)
->set('encryptionPass', $password)
->create();
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid using static access to class '\App\Config' in method 'isActive'. Open
$method = \App\Config::module(\App\Module::getModuleName($this->getTarget()), 'encryptionMethod');
- 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\Db' in method 'recalculatePasswords'. Open
$dbAdmin = \App\Db::getInstance('admin');
- 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\Module' in method 'recalculatePasswords'. Open
$moduleName = \App\Module::getModuleName($target);
- 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\Db' in method 'getInstance'. Open
$row = (new \App\Db\Query())->from(static::TABLE_NAME)->where(['target' => $target])->one(\App\Db::getInstance('admin'));
- 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\Module' in method 'recalculatePasswords'. Open
(new \App\ConfigFile('module', \App\Module::getModuleName($target)))
- 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\Cache' in method 'recalculatePasswords'. Open
\App\Cache::clear();
- 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\Module' in method 'getInstance'. Open
$instance->set('pass', \App\Config::module(\App\Module::getModuleName($target), 'encryptionPass'));
- 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\Config' in method 'getInstance'. Open
$instance->set('pass', \App\Config::module(\App\Module::getModuleName($target), 'encryptionPass'));
- 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\Pauser' in method 'recalculatePasswords'. Open
$pauser = \App\Pauser::getInstance("Encryption-{$moduleName}");
- 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\Db' in method 'recalculatePasswords'. Open
$db = \App\Db::getInstance();
- 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\Module' in method 'getQueryGenerator'. Open
$moduleName = \App\Module::getModuleName($this->getTarget());
- 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 "method" 10 times. Open
$instance->set('method', $row['method']);
- 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 "vector" 3 times. Open
$instance->set('vector', $row['pass']);
- 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 "target" 6 times. Open
$row = (new \App\Db\Query())->from(static::TABLE_NAME)->where(['target' => $target])->one(\App\Db::getInstance('admin'));
- 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.
Reference to constant TARGET_SETTINGS
from undeclared class \App\Encryption
(Did you mean class \Tests\App\Encryption) Open
public static function getInstance(int $target = \App\Encryption::TARGET_SETTINGS)
- Exclude checks
Call to undeclared method \App\Encryptions\Module::getTarget
Open
$method = \App\Config::module(\App\Module::getModuleName($this->getTarget()), 'encryptionMethod');
- Exclude checks
Call to undeclared method \App\Encryptions\Module::get
Open
|| !\in_array($this->get('method'), static::getMethods())
- Exclude checks
Reference to undeclared constant \App\Encryptions\Module::TABLE_NAME
Open
$row = (new \App\Db\Query())->from(static::TABLE_NAME)->where(['target' => $target])->one(\App\Db::getInstance('admin'));
- Exclude checks
Call to undeclared method \App\Db\Query::from
Open
$row = (new \App\Db\Query())->from(static::TABLE_NAME)->where(['target' => $target])->one(\App\Db::getInstance('admin'));
- Exclude checks
Call to undeclared method \App\Encryptions\Module::set
Open
$instance->set('pass', \App\Config::module(\App\Module::getModuleName($target), 'encryptionPass'));
- Exclude checks
Call to undeclared method \App\Db::beginTransaction
Open
$transactionAdmin = $dbAdmin->beginTransaction();
- Exclude checks
Call to method createQuery
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
if ($decryptInstance->getQueryGenerator((int) $pauser->getValue())->createQuery()->exists()) {
- Exclude checks
Return type of getQueryGenerator()
is undeclared type \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
public function getQueryGenerator(int $lastId = null): \App\QueryGenerator
- Exclude checks
Call to undeclared method \App\Encryptions\Module::get
Open
if (!$decryptInstance->getTarget() || ($decryptInstance->get('method') === $method && $decryptInstance->get('vector') === $vector && $decryptInstance->get('pass') === $password)) {
- Exclude checks
Reference to undeclared constant \App\Encryptions\Module::STATUS_ACTIVE
Open
'status' => self::STATUS_ACTIVE,
- Exclude checks
Doc-block of $lastId
in getQueryGenerator
is phpdoc param type int
which is not a permitted replacement of the nullable param type ?int
declared in the signature ('?T' should be documented as 'T|null' or '?T') Open
* @param int $lastId
- Exclude checks
Call to undeclared method \App\Encryptions\Module::getTarget
Open
$moduleName = \App\Module::getModuleName($this->getTarget());
- Exclude checks
Call to undeclared method \App\Encryptions\Module::isEmpty
Open
|| $this->isEmpty('method')
- Exclude checks
Call to undeclared method \App\Db::beginTransaction
Open
$transactionBase = $db->beginTransaction();
- Exclude checks
Call to undeclared method \App\Encryptions\Module::set
Open
$instance->set('target', (int) $row['target']);
- Exclude checks
Reference to undeclared constant \App\Encryptions\Module::STATUS_ACTIVE
Open
$dbAdmin->createCommand()->update(self::TABLE_NAME, ['status' => self::STATUS_ACTIVE], ['target' => $target])->execute();
- Exclude checks
Reference to undeclared constant \App\Encryptions\Module::TABLE_NAME
Open
$dbAdmin->createCommand()->update(self::TABLE_NAME, ['status' => self::STATUS_ACTIVE], ['target' => $target])->execute();
- Exclude checks
Static call to undeclared method \App\Encryptions\Module::getMethods
Open
|| !\in_array($this->get('method'), static::getMethods())
- Exclude checks
Class extends undeclared class \App\Encryption
(Did you mean class \Tests\App\Encryption) Open
class Module extends \App\Encryption
- Exclude checks
Call to undeclared method \App\Encryptions\Module::set
Open
$instance->set('method', $row['method']);
- Exclude checks
Reference to undeclared constant \App\Encryptions\Module::TABLE_NAME
Open
$dbAdmin->createCommand()->update(self::TABLE_NAME, [
- Exclude checks
Call to undeclared method \App\Encryptions\Module::set
Open
$instance->set('vector', $row['pass']);
- Exclude checks
Call to undeclared method \App\Encryptions\Module::decrypt
Open
$value = $decryptInstance->decrypt($value);
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
$dbAdmin->createCommand()->update(self::TABLE_NAME, [
- Exclude checks
Call to method __construct
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$queryGenerator = (new \App\QueryGenerator($moduleName))->setFields($fields);
- Exclude checks
Call to undeclared method \App\Encryptions\Module::getTarget
Open
if (!$decryptInstance->getTarget() || ($decryptInstance->get('method') === $method && $decryptInstance->get('vector') === $vector && $decryptInstance->get('pass') === $password)) {
- Exclude checks
Call to undeclared method \App\Encryptions\Module::set
Open
$encryptInstance = (new static())
- Exclude checks
Call to method createQuery
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$dataReader = $queryGenerator->createQuery()->createCommand()->query();
- Exclude checks
Call to method getColumnName
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$db->createCommand()->update($fieldModel->getTableName(), [$fieldModel->getColumnName() => $value], [$queryGenerator->getColumnName('id') => $recordId])->execute();
- Exclude checks
Call to method setFields
from undeclared class \App\QueryGenerator
(Did you mean class \Tests\App\QueryGenerator) Open
$queryGenerator = (new \App\QueryGenerator($moduleName))->setFields($fields);
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
$dbAdmin->createCommand()->update(self::TABLE_NAME, ['status' => self::STATUS_ACTIVE], ['target' => $target])->execute();
- Exclude checks
Call to undeclared method \App\Db::createCommand
Open
$db->createCommand()->update($fieldModel->getTableName(), [$fieldModel->getColumnName() => $value], [$queryGenerator->getColumnName('id') => $recordId])->execute();
- Exclude checks
Call to method __construct
from undeclared class \yii\db\Expression
Open
$queryGenerator->addNativeCondition((new \yii\db\Expression('0 > 1')));
- Exclude checks
Reference to undeclared constant \App\Encryptions\Module::TARGET_SETTINGS
Open
if ($target === static::TARGET_SETTINGS) {
- Exclude checks
Call to undeclared method \App\Encryptions\Module::isEmpty
Open
if (!$decryptInstance->isEmpty('method') && !$decryptInstance->isActive()) {
- Exclude checks
Call to undeclared method \App\Encryptions\Module::get
Open
|| ($this->get('method') !== $method && !$testMode)
- Exclude checks
Avoid variables with short names like $db. Configured minimum length is 3. Open
$db = \App\Db::getInstance();
- Read upRead up
- Exclude checks
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
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($target === static::TARGET_SETTINGS) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$instance->set('target', (int) $row['target']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$instance->set('pass', \App\Config::module(\App\Module::getModuleName($target), 'encryptionPass'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $method
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** {@inheritdoc} */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$instance->set('vector', $row['pass']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function recalculatePasswords(string $method, string $password, string $vector, int $target)
- Exclude checks
Line exceeds 120 characters; contains 133 characters Open
$dbAdmin->createCommand()->update(self::TABLE_NAME, ['status' => self::STATUS_ACTIVE], ['target' => $target])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->set('method', $method)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$transactionAdmin = $dbAdmin->beginTransaction();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryGenerator = $decryptInstance->getQueryGenerator($lastId);
- 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 (empty($value) && '' !== $valueRaw && $method) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryGenerator->addNativeCondition((new \yii\db\Expression('0 > 1')));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryGenerator->setLimit($limit);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$row = (new \App\Db\Query())->from(static::TABLE_NAME)->where(['target' => $target])->one(\App\Db::getInstance('admin'));
- 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
try {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$lastId = (int) $pauser->getValue();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dataReader->close();
- 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 function getQueryGenerator(int $lastId = null): \App\QueryGenerator
- 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
$pauser = \App\Pauser::getInstance("Encryption-{$moduleName}");
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$decryptInstance->isEmpty('method') && !$decryptInstance->isActive()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new \App\Exceptions\AppException('ERR_IMPOSSIBLE_DECRYPT');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
(new \App\BatchMethod(['method' => __CLASS__ . '::recalculatePasswords', 'params' => [$method, $password, $vector, $target, microtime()]]))->save();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw $e;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Gets query.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fields[] = 'id';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryGenerator->setOrder('id', \App\Db::ASC);
- 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
throw new \App\Exceptions\AppException('ERR_IMPOSSIBLE_ENCRYPT');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($decryptInstance->getQueryGenerator((int) $pauser->getValue())->createQuery()->exists()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
(new \App\ConfigFile('module', \App\Module::getModuleName($target)))
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->set('encryptionPass', $password)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $lastId
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryGenerator->addNativeCondition(['>', $queryGenerator->getColumnName('id'), $lastId]);
- 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 $instance;
- 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
* Function to change password for encryption.
- 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 int $target
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'pass' => $vector,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getInstance(int $target = \App\Encryption::TARGET_SETTINGS)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new \App\Exceptions\IllegalValue('ERR_NOT_ALLOWED_VALUE||target', 406);
- Exclude checks
Line exceeds 120 characters; contains 129 characters Open
$row = (new \App\Db\Query())->from(static::TABLE_NAME)->where(['target' => $target])->one(\App\Db::getInstance('admin'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$encryptInstance = (new static())
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$db = \App\Db::getInstance();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$recordId = $row['id'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} else {
- 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
* @return bool
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$decryptInstance = static::getInstance($target);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->set('target', $target);
- 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
$pauser->setValue((string) $recordId);
- Exclude checks
Line exceeds 120 characters; contains 167 characters Open
(new \App\BatchMethod(['method' => __CLASS__ . '::recalculatePasswords', 'params' => [$method, $password, $vector, $target, microtime()]]))->save();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->create();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
], ['target' => $target])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pauser->destroy();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$transactionBase->rollBack();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return \App\QueryGenerator
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param bool $testMode
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return !(
- 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
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $password
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->set('pass', $password)
- 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
'status' => self::STATUS_ACTIVE,
- 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
$moduleName = \App\Module::getModuleName($this->getTarget());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryGenerator = (new \App\QueryGenerator($moduleName))->setFields($fields);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryGenerator->permissions = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $queryGenerator;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
|| !\in_array($this->get('method'), static::getMethods())
- 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
$instance->set('method', $row['method']);
- 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 (!$decryptInstance->getTarget() || ($decryptInstance->get('method') === $method && $decryptInstance->get('vector') === $vector && $decryptInstance->get('pass') === $password)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dbAdmin->createCommand()->update(self::TABLE_NAME, [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$transactionAdmin->rollBack();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Checks if encrypt or decrypt is possible.
- 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
$instance = new static();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dbAdmin = \App\Db::getInstance('admin');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dataReader = $queryGenerator->createQuery()->createCommand()->query();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$db->createCommand()->update($fieldModel->getTableName(), [$fieldModel->getColumnName() => $value], [$queryGenerator->getColumnName('id') => $recordId])->execute();
- Exclude checks
Line exceeds 120 characters; contains 184 characters Open
$db->createCommand()->update($fieldModel->getTableName(), [$fieldModel->getColumnName() => $value], [$queryGenerator->getColumnName('id') => $recordId])->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
$transactionBase->commit();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->set('vector', $vector)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$moduleName = \App\Module::getModuleName($target);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!empty($value)) {
- 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
$transactionAdmin->commit();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$limit = 50000;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function isActive(bool $testMode = false)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$dataReader->count()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
while ($row = $dataReader->read()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value = $encryptInstance->encrypt($value, true);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\App\Cache::clear();
- 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
$transactionBase = $db->beginTransaction();
- 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
->set('encryptionMethod', $method)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
} catch (\Throwable $e) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pwdFields = \Vtiger_Module_Model::getInstance($moduleName)->getFieldsByUiType(99);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$queryGenerator->setStateCondition('All');
- 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 = \App\Config::module(\App\Module::getModuleName($this->getTarget()), 'encryptionMethod');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dbAdmin->createCommand()->update(self::TABLE_NAME, ['status' => self::STATUS_ACTIVE], ['target' => $target])->execute();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pauser->destroy();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value = $valueRaw = $row[$fieldModel->getName()] ?? '';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fields = array_keys($pwdFields);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
|| $this->isEmpty('method')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Line exceeds 120 characters; contains 188 characters Open
if (!$decryptInstance->getTarget() || ($decryptInstance->get('method') === $method && $decryptInstance->get('vector') === $vector && $decryptInstance->get('pass') === $password)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return;
- 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
if (!$pwdFields) {
- 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
|| ($this->get('method') !== $method && !$testMode)
- 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 $vector
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pwdFields = \Vtiger_Module_Model::getInstance($moduleName)->getFieldsByUiType(99);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($pwdFields as $fieldModel) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$value = $decryptInstance->decrypt($value);
- 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
!\function_exists('openssl_encrypt')
- Exclude checks