The class Network has 14 public methods. Consider refactoring Network to keep number of public methods under 10. Open
class Network implements \Iterator, \Countable
{
use PropertyTrait;
/**
- Read upRead up
- Exclude checks
TooManyPublicMethods
Since: 0.1
A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.
By default it ignores methods starting with 'get' or 'set'.
Example
Source https://phpmd.org/rules/codesize.html#toomanypublicmethods
The class Network has an overall complexity of 57 which is very high. The configured complexity threshold is 50. Open
class Network implements \Iterator, \Countable
{
use PropertyTrait;
/**
- Exclude checks
Avoid using static access to class 'IPTools\IP' in method 'parse'. Open
$netmask = IP::parse($netmask);
- 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 'IPTools\IP' in method 'parse'. Open
$ip = IP::parse($ip);
- 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 parse uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$ip = IP::parse($data);
$netmask = self::prefix2netmask($ip->getMaxPrefixLength(), $ip->getVersion());
}
- 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
The method exclude uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$matched = $upper;
$unmatched = $lower;
}
- 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 'IPTools\IP' in method 'prefix2netmask'. Open
return IP::parseBin($binIP);
- 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 'IPTools\IP' in method 'parse'. Open
$ip = IP::parse($data);
- 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 'IPTools\IP' in method 'getHosts'. Open
$firstHost = IP::parseBin(substr($firstHost->toBin(), 0, $firstHost->getMaxPrefixLength() - 1) . '1');
- 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 'IPTools\IP' in method 'getHosts'. Open
$lastHost = IP::parseBin(substr($lastHost->toBin(), 0, $lastHost->getMaxPrefixLength() - 1) . '0');
- 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 'IPTools\IP' in method 'parse'. Open
$ip = IP::parse($matches[1]);
- 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 variables with short names like $ip. Configured minimum length is 3. Open
public function setNetmask(IP $ip)
- 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 $ip. Configured minimum length is 3. Open
private $ip;
- 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 $ip. Configured minimum length is 3. Open
$ip = IP::parse($matches[1]);
- 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 $ip. Configured minimum length is 3. Open
public function __construct(IP $ip, IP $netmask)
- 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 $ip. Configured minimum length is 3. Open
public static function netmask2prefix(IP $ip)
- 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 $ip. Configured minimum length is 3. Open
public function setIP(IP $ip)
- 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
* @throws NetworkException
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new NetworkException('Invalid Netmask address format');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @throws NetworkException
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @throws NetworkException
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
#[ReturnTypeWillChange]
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @throws NetworkException
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new NetworkException("Wrong IP version");
- Exclude checks
Inline control structures are not allowed Open
if (++$newPrefixLength > $this->getNetwork()->getMaxPrefixLength()) break;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
#[ReturnTypeWillChange]
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new NetworkException('Invalid prefix length ');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new NetworkException('Exclude subnet not within target network');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
#[ReturnTypeWillChange]
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
#[ReturnTypeWillChange]
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new NetworkException('Invalid prefix length');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new NetworkException('Netmask version is not same as IP version');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
#[ReturnTypeWillChange]
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @throws NetworkException
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
throw new NetworkException('IP version is not same as Netmask version');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
#[ReturnTypeWillChange]
- Exclude checks
No space found after comma in function call Open
if (!preg_match('/^1*0*$/',$ip->toBin())) {
- Exclude checks
No space found after comma in function call Open
} elseif (strpos($data,' ')) {
- Exclude checks