Missing class import via use statement (line '35', column '19'). Open
$iterator = new \DirectoryIterator(__DIR__ . '/SMSProvider');
- 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 '106', column '16'). Open
$data = (new \App\Db\Query())->from(self::TABLE_NAME)->where(['id' => $id])->one();
- 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 '93', column '16'). Open
$data = (new \App\Db\Query())->from(self::TABLE_NAME)->where(['isactive' => self::STATUS_ACTIVE])->one();
- 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 'getProviderByData'. Open
$parameters = \App\Json::isJson($data['parameters']) ? \App\Json::decode($data['parameters']) : [];
- 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 'getProviderByData'. Open
$parameters = \App\Json::isJson($data['parameters']) ? \App\Json::decode($data['parameters']) : [];
- 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 assigning values to variables in if clauses and the like (line '37', column '105'). Open
public static function getProviders(): array
{
$providers = [];
$iterator = new \DirectoryIterator(__DIR__ . '/SMSProvider');
foreach ($iterator as $item) {
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
Define a constant instead of duplicating this literal "parameters" 3 times. Open
$parameters = \App\Json::isJson($data['parameters']) ? \App\Json::decode($data['parameters']) : [];
- 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\Query::from
Open
$data = (new \App\Db\Query())->from(self::TABLE_NAME)->where(['id' => $id])->one();
- Exclude checks
Call to undeclared method \App\Db\Query::from
Open
$data = (new \App\Db\Query())->from(self::TABLE_NAME)->where(['isactive' => self::STATUS_ACTIVE])->one();
- Exclude checks
Avoid variables with short names like $id. Configured minimum length is 3. Open
public static function getById(int $id): ?SMSProvider\Provider
- 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
/** @var int Status active */
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$iterator = new \DirectoryIterator(__DIR__ . '/SMSProvider');
- 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 SMSProvider\Provider|null
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getProviderByData(array $data): ?SMSProvider\Provider
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Check if there is an active provider.
- 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 getProviderByName(string $name): ?SMSProvider\Provider
- 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
public static function getProviders(): 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
* Get provider by data.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $data ? self::getProviderByData($data) : null;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$providers = [];
- 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
foreach ($parameters as $name => $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
return null !== static::getDefaultProvider();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public const STATUS_ACTIVE = 1;
- 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 provider by name.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return SMSProvider\Provider|null
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$className = "\\App\\Integrations\\SMSProvider\\{$name}";
- 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 class_exists($className) ? new $className() : null;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
unset($data['parameters']);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function isActiveProvider(): bool
- 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 ? self::getProviderByData($data) : null;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/** @var int Status inactive */
- 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
$parameters = \App\Json::isJson($data['parameters']) ? \App\Json::decode($data['parameters']) : [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$data[$name] = $value;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return SMSProvider\Provider|null
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return SMSProvider\Provider|null
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Line exceeds 120 characters; contains 179 characters Open
if ($item->isFile() && 'Provider.php' !== $item->getFilename() && 'php' === $item->getExtension() && $provider = self::getProviderByName($item->getBasename('.php'))) {
- 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
$providers[$provider->getName()] = $provider;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $name
- 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 provider.
- 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 TABLE_NAME = 'a_#__smsnotifier_servers';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $providers;
- 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
public const STATUS_INACTIVE = 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($iterator as $item) {
- 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
$data = (new \App\Db\Query())->from(self::TABLE_NAME)->where(['isactive' => self::STATUS_ACTIVE])->one();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $id
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getById(int $id): ?SMSProvider\Provider
- 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
/** @var string Basic table name */
- 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 providers.
- 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 getDefaultProvider(): ?SMSProvider\Provider
- 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
$provider = self::getProviderByName($data['providertype']);
- 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 = (new \App\Db\Query())->from(self::TABLE_NAME)->where(['id' => $id])->one();
- 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 ($item->isFile() && 'Provider.php' !== $item->getFilename() && 'php' === $item->getExtension() && $provider = self::getProviderByName($item->getBasename('.php'))) {
- 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 $provider ? $provider->setData($data) : 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
* Get provider by ID.
- Exclude checks