Missing class import via use statement (line '44', column '33'). Open
return \App\Json::decode((new \App\Encryption($this->getConfig()))->decrypt($data, true)) ?: [];
- 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 '32', column '15'). Open
return (new \App\Encryption($this->getConfig()))->encrypt(\App\Json::encode($data), true);
- 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\Json' in method 'encrypt'. Open
return (new \App\Encryption($this->getConfig()))->encrypt(\App\Json::encode($data), true);
- 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 'decrypt'. Open
return \App\Json::decode((new \App\Encryption($this->getConfig()))->decrypt($data, true)) ?: [];
- 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 'getDefaultData'. Open
'pass' => \App\Encryption::generatePassword(10),
- 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 "vector" 3 times. Open
'vector' => base64_encode(openssl_random_pseudo_bytes(openssl_cipher_iv_length(self::DEFAULT_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.
Call to method __construct
from undeclared class \App\Encryption
(Did you mean class \Tests\App\Encryption) Open
return (new \App\Encryption($this->getConfig()))->encrypt(\App\Json::encode($data), true);
- Exclude checks
Call to method __construct
from undeclared class \App\YetiForce\Config
(Did you mean class \App\Config or class \Tests\App\Config) Open
$data = (new Config())->getData();
- Exclude checks
Call to method encrypt
from undeclared class \App\Encryption
(Did you mean class \Tests\App\Encryption) Open
return (new \App\Encryption($this->getConfig()))->encrypt(\App\Json::encode($data), true);
- Exclude checks
Call to method getData
from undeclared class \App\YetiForce\Config
(Did you mean class \App\Config or class \Tests\App\Config) Open
$data = (new Config())->getData();
- Exclude checks
Call to method decrypt
from undeclared class \App\Encryption
(Did you mean class \Tests\App\Encryption) Open
return \App\Json::decode((new \App\Encryption($this->getConfig()))->decrypt($data, true)) ?: [];
- Exclude checks
Call to method generatePassword
from undeclared class \App\Encryption
(Did you mean class \Tests\App\Encryption) Open
'pass' => \App\Encryption::generatePassword(10),
- Exclude checks
Call to method __construct
from undeclared class \App\Encryption
(Did you mean class \Tests\App\Encryption) Open
return \App\Json::decode((new \App\Encryption($this->getConfig()))->decrypt($data, true)) ?: [];
- Exclude checks
Avoid variables with short names like $iv. Configured minimum length is 3. Open
$iv = $data['vector'] ?? '';
- 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
public function getDefaultData(): array
- 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
public const DEFAULT_METHOD = 'AES-128-CBC';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function encrypt(array $data): 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
*
- 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
* Get default configuration data for encryption.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
unset($data['key']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$data['vector'] = base64_decode($iv);
- 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
*
- 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 array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** @var string Default encryption method */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param array $data
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Data encryption 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
return (new \App\Encryption($this->getConfig()))->encrypt(\App\Json::encode($data), true);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'method' => self::DEFAULT_METHOD,
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$iv = $data['vector'] ?? '';
- 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
private function getConfig(): array
- 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 $data
- 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
* Data decryption function.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function decrypt(string $data): array
- 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 \App\Json::decode((new \App\Encryption($this->getConfig()))->decrypt($data, true)) ?: [];
- 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 $data;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
'pass' => \App\Encryption::generatePassword(10),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Configuration data 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
'vector' => base64_encode(openssl_random_pseudo_bytes(openssl_cipher_iv_length(self::DEFAULT_METHOD))),
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$data = (new Config())->getData();
- 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 ($iv) {
- 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
* @return array
- 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