Method dataValidator
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function dataValidator(): array
{
return [
['url', true, 'ssl://imap.gmail.com:993'],
['url', true, 'ssl://imap.gmail.com'],
Avoid using static access to class '\App\Validator' in method 'testValidator'. Open
$this->assertSame($expected, \App\Validator::{$fn}($value));
- 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\Validator' in method 'testFloatIsEqual'. Open
$this->assertSame($result, \App\Validator::floatIsEqual($value1, $value2, $precision), 'Expected ' . $result);
- 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 "urlDomain" 22 times. Open
['urlDomain', true, 'ssl://imap.gmail.com:993'],
- 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 \Tests\App\Validator::assertSame
Open
$this->assertSame($expected, \App\Validator::{$fn}($value));
- Exclude checks
Call to undeclared method \Tests\App\Validator::assertSame
Open
$this->assertSame($result, \App\Validator::floatIsEqual($value1, $value2, $precision), 'Expected ' . $result);
- Exclude checks
Call to method floatIsEqual
from undeclared class \App\Validator
(Did you mean class \Tests\App\Validator) Open
$this->assertSame($result, \App\Validator::floatIsEqual($value1, $value2, $precision), 'Expected ' . $result);
- Exclude checks
Suspicious type bool
of a variable or expression used to build a string. (Expected type to be able to cast to a string) Open
$this->assertSame($result, \App\Validator::floatIsEqual($value1, $value2, $precision), 'Expected ' . $result);
- Exclude checks
Avoid variables with short names like $fn. Configured minimum length is 3. Open
public function testValidator(string $fn, bool $expected, $value)
- 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
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->assertSame($expected, \App\Validator::{$fn}($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
* Data provider for testValidator function.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
['urlDomain', true, 'google.pl'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
['urlDomain', false, 'https://yetiforce*com/pl/'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Provide test data for testFloatIsEqual 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
public function testFloatIsEqual(float $value1, float $value2, int $precision, bool $result)
- 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 testValidator(string $fn, bool $expected, $value)
- 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
return [
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
['urlDomain', false, 'https://1243yfcom%.pl'],
- 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
['urlDomain', true, 'http://элтранс.рф'],
- 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 float $value1
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
['urlDomain', false, 'https://yeti force.com/pl/'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
['urlDomain', false, 'http*://yetiforce.com'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @dataProvider floatIsEqualProvider
- 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
['url', true, 'tls://imap.gmail.com'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
['urlDomain', false, 'http://a-.bc.com'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
['urlDomain', false, 'test@com.pl'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
['urlDomain', true, 'http://yetiforce.com:2160/'],
- 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
public function floatIsEqualProvider()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
[0.314111, 0.3199, 3, 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 void
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
['urlDomain', true, 'ssl://imap.gmail.com'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
['urlDomain', 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
* @param float $value2
- 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
* @dataProvider dataValidator
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param bool $expected
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $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
public function dataValidator(): array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
['url', true, 'ssl://imap.gmail.com'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
['url', true, 'imap.gmail.com:993'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
['urlDomain', true, 'http://www.müller.de'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
[0.314001, 0.314, 6, false],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
['urlDomain', true, 'http://google.pl'],
- 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
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
['urlDomain', true, 'tls://imap.gmail.com'],
- 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
['urlDomain', true, 'imap.gmail.com'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
['urlDomain', false, '#'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
['urlDomain', true, 'mailto://info@yetiforce.com'],
- 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
[0.314000, 0.314, 6, true],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->assertSame($result, \App\Validator::floatIsEqual($value1, $value2, $precision), 'Expected ' . $result);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param string $fn
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
['urlDomain', true, 'tel://600500100'],
- 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
[0.314001, 0.314, 5, true],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param bool $result
- 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
['url', true, 'imap.gmail.com'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
['urlDomain', true, 'ftp://yetiforce.com'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
['url', true, 'ssl://imap.gmail.com:993'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
['urlDomain', true, 'ssl://imap.gmail.com:993'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
['urlDomain', false, ' http://yetiforce.com/'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
[3.5768, 3.58, 3, false],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
['urlDomain', false, 'javascript:alert(1)'],
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Testing process function.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param int $precision
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks