detain/iptools

View on GitHub
src/Network.php

Summary

Maintainability
A
0 mins
Test Coverage

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;

    /**
Severity: Minor
Found in src/Network.php by phpmd

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;

    /**
Severity: Minor
Found in src/Network.php by phpmd

Avoid using static access to class 'IPTools\IP' in method 'parse'.
Open

            $netmask = IP::parse($netmask);
Severity: Minor
Found in src/Network.php by phpmd

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);
Severity: Minor
Found in src/Network.php by phpmd

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());
        }
Severity: Minor
Found in src/Network.php by phpmd

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;
            }
Severity: Minor
Found in src/Network.php by phpmd

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);
Severity: Minor
Found in src/Network.php by phpmd

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);
Severity: Minor
Found in src/Network.php by phpmd

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');
Severity: Minor
Found in src/Network.php by phpmd

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');
Severity: Minor
Found in src/Network.php by phpmd

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]);
Severity: Minor
Found in src/Network.php by phpmd

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)
Severity: Minor
Found in src/Network.php by phpmd

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;
Severity: Minor
Found in src/Network.php by phpmd

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]);
Severity: Minor
Found in src/Network.php by phpmd

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)
Severity: Minor
Found in src/Network.php by phpmd

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)
Severity: Minor
Found in src/Network.php by phpmd

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)
Severity: Minor
Found in src/Network.php by phpmd

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
Severity: Minor
Found in src/Network.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            throw new NetworkException('Invalid Netmask address format');
Severity: Minor
Found in src/Network.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     * @throws NetworkException
Severity: Minor
Found in src/Network.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     * @throws NetworkException
Severity: Minor
Found in src/Network.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    #[ReturnTypeWillChange]
Severity: Minor
Found in src/Network.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     * @throws NetworkException
Severity: Minor
Found in src/Network.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            throw new NetworkException("Wrong IP version");
Severity: Minor
Found in src/Network.php by phpcodesniffer

Inline control structures are not allowed
Open

            if (++$newPrefixLength > $this->getNetwork()->getMaxPrefixLength()) break;
Severity: Minor
Found in src/Network.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    #[ReturnTypeWillChange]
Severity: Minor
Found in src/Network.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            throw new NetworkException('Invalid prefix length ');
Severity: Minor
Found in src/Network.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            throw new NetworkException('Exclude subnet not within target network');
Severity: Minor
Found in src/Network.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    #[ReturnTypeWillChange]
Severity: Minor
Found in src/Network.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    #[ReturnTypeWillChange]
Severity: Minor
Found in src/Network.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            throw new NetworkException('Invalid prefix length');
Severity: Minor
Found in src/Network.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            throw new NetworkException('Netmask version is not same as IP version');
Severity: Minor
Found in src/Network.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    #[ReturnTypeWillChange]
Severity: Minor
Found in src/Network.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

     * @throws NetworkException
Severity: Minor
Found in src/Network.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

            throw new NetworkException('IP version is not same as Netmask version');
Severity: Minor
Found in src/Network.php by phpcodesniffer

Spaces must be used to indent lines; tabs are not allowed
Open

    #[ReturnTypeWillChange]
Severity: Minor
Found in src/Network.php by phpcodesniffer

No space found after comma in function call
Open

        if (!preg_match('/^1*0*$/',$ip->toBin())) {
Severity: Minor
Found in src/Network.php by phpcodesniffer

No space found after comma in function call
Open

        } elseif (strpos($data,' ')) {
Severity: Minor
Found in src/Network.php by phpcodesniffer

There are no issues that match your filters.

Category
Status