app/Version.php
Suspicious array access to false
Open
Open
return static::compare($version, static::$versions[$type], $condition);
- Exclude checks
Suspicious array access to false
Open
Open
return static::$versions[$type];
- Exclude checks
Define a constant instead of duplicating this literal "appVersion" 3 times. Open
Open
public static function get($type = 'appVersion'): string
- 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.
Avoid variables with short names like $v2. Configured minimum length is 3. Open
Open
public static function compare($v1, $v2, $operator = '==')
- 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
Avoid variables with short names like $v1. Configured minimum length is 3. Open
Open
public static function compare($v1, $v2, $operator = '==')
- 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
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @param string $type
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @return string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
static::$versions = require 'config/version.php';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @return mixed
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
private static function init(): void
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @return bool|int
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$ev2 = \explode('.', $v2);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$lv2 = \count($ev2);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @return string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* Function to load versions.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @param string $type
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* Check app versions with given version.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @param string $version - String Version against which comparision to be done
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
private static $versions = false;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return static::$versions[$type];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
if (false === static::$versions) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
static::init();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @param string $v2
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$fullVer = \explode('.', self::get($type));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @param string $v1
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @param string $operator
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @param string $type
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* @param string $condition - String Condition like ( '=', '!=', '<', '<=', '>', '>=')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
if ('x' === substr($v2, -1)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return version_compare($v1, $v2, $operator);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public static function get($type = 'appVersion'): string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* Get current short version of system.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public static function getShort($type = 'appVersion'): string
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
static::init();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return \implode('.', $fullVer);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* Compares two version number strings.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
\array_pop($ev2);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public static function check($version, $type = 'appVersion', $condition = '>=')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
return static::compare($version, static::$versions[$type], $condition);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
public static function compare($v1, $v2, $operator = '==')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$v2 = \implode('.', $ev2);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
* Get current version of system.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
array_pop($fullVer);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
Open
$v1 = \implode('.', \array_slice(\explode('.', $v1), 0, $lv2));
- Exclude checks