detain/iptools

View on GitHub
src/IP.php

Summary

Maintainability
A
0 mins
Test Coverage

The class IP has 13 public methods. Consider refactoring IP to keep number of public methods under 10.
Open

class IP
{
    use PropertyTrait;

    const IP_V4 = 'IPv4';
Severity: Minor
Found in src/IP.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 method parseLong uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $binary = array();
            for ($i = 0; $i < self::IP_V6_OCTETS; $i++) {
                $binary[] = bcmod($longIP, 256);
                $longIP = bcdiv($longIP, 256, 0);
Severity: Minor
Found in src/IP.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 toLong uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $octet = self::IP_V6_OCTETS - 1;
            foreach ($chars = unpack('C*', $this->in_addr) as $char) {
                $long = bcadd($long, bcmul($char, bcpow(256, $octet--)));
            }
Severity: Minor
Found in src/IP.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 prev uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

                } else {
                    $unpacked[$byte]--;
                    break;
                }
Severity: Minor
Found in src/IP.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 getReversePointer uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $unpacked = unpack('H*hex', $this->in_addr);
            $reverseOctets = array_reverse(str_split($unpacked['hex']));
            $reversePointer = implode('.', $reverseOctets) . '.ip6.arpa';
        }
Severity: Minor
Found in src/IP.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 unused local variables such as '$chars'.
Open

            foreach ($chars = unpack('C*', $this->in_addr) as $char) {
Severity: Minor
Found in src/IP.php by phpmd

UnusedLocalVariable

Since: 0.2

Detects when a local variable is declared and/or assigned, but not used.

Example

class Foo {
    public function doSomething()
    {
        $i = 5; // Unused
    }
}

Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable

Avoid variables with short names like $ip. Configured minimum length is 3.
Open

    public function __construct($ip)
Severity: Minor
Found in src/IP.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 $to. Configured minimum length is 3.
Open

    public function next($to=1)
Severity: Minor
Found in src/IP.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 $to. Configured minimum length is 3.
Open

    public function prev($to=1)
Severity: Minor
Found in src/IP.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 classes with short names like IP. Configured minimum length is 3.
Open

class IP
{
    use PropertyTrait;

    const IP_V4 = 'IPv4';
Severity: Minor
Found in src/IP.php by phpmd

ShortClassName

Since: 2.9

Detects when classes or interfaces have a very short name.

Example

class Fo {

}

interface Fo {

}

Source https://phpmd.org/rules/naming.html#shortclassname

Avoid variables with short names like $ip. Configured minimum length is 3.
Open

            $ip = new self(long2ip($longIP));
Severity: Minor
Found in src/IP.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 parse($ip)
Severity: Minor
Found in src/IP.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

Incorrect spacing between argument "$to" and equals sign; expected 1 but found 0
Open

    public function prev($to=1)
Severity: Minor
Found in src/IP.php by phpcodesniffer

Incorrect spacing between argument "$version" and equals sign; expected 1 but found 0
Open

    public static function parseLong($longIP, $version=self::IP_V4)
Severity: Minor
Found in src/IP.php by phpcodesniffer

Incorrect spacing between argument "$to" and equals sign; expected 1 but found 0
Open

    public function next($to=1)
Severity: Minor
Found in src/IP.php by phpcodesniffer

Incorrect spacing between default value and equals sign for argument "$version"; expected 1 but found 0
Open

    public static function parseLong($longIP, $version=self::IP_V4)
Severity: Minor
Found in src/IP.php by phpcodesniffer

Incorrect spacing between default value and equals sign for argument "$to"; expected 1 but found 0
Open

    public function next($to=1)
Severity: Minor
Found in src/IP.php by phpcodesniffer

Incorrect spacing between default value and equals sign for argument "$to"; expected 1 but found 0
Open

    public function prev($to=1)
Severity: Minor
Found in src/IP.php by phpcodesniffer

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

            throw new IpException("Invalid IP address format");
Severity: Minor
Found in src/IP.php by phpcodesniffer

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

            throw new IpException("Invalid binary IP address format");
Severity: Minor
Found in src/IP.php by phpcodesniffer

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

     * @throws IpException
Severity: Minor
Found in src/IP.php by phpcodesniffer

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

     * @throws IpException
Severity: Minor
Found in src/IP.php by phpcodesniffer

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

            throw new IpException("Number must be greater than 0");
Severity: Minor
Found in src/IP.php by phpcodesniffer

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

     * @throws IpException
Severity: Minor
Found in src/IP.php by phpcodesniffer

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

            throw new IpException("Invalid hexadecimal IP address format");
Severity: Minor
Found in src/IP.php by phpcodesniffer

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

            throw new IpException("Number must be greater than 0");
Severity: Minor
Found in src/IP.php by phpcodesniffer

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

     * @throws IpException
Severity: Minor
Found in src/IP.php by phpcodesniffer

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

     * @throws IpException
Severity: Minor
Found in src/IP.php by phpcodesniffer

Expected 1 space after closing parenthesis; found 4
Open

        for ($i = 0; $i < $to; $i++)    {
Severity: Minor
Found in src/IP.php by phpcodesniffer

Expected 1 space after closing parenthesis; found 4
Open

        for ($i = 0; $i < $to; $i++)    {
Severity: Minor
Found in src/IP.php by phpcodesniffer

There are no issues that match your filters.

Category
Status