Kanti/htmly-installer

View on GitHub
backer.php

Summary

Maintainability
A
35 mins
Test Coverage

testIfBackingIsNecessary accesses the super-global variable $_SERVER.
Open

    protected function testIfBackingIsNecessary()
    {
        if (!file_exists(dirname($_SERVER["SCRIPT_FILENAME"]) . "/" . "composer.json")) {
            return false;
        }
Severity: Minor
Found in backer.php by phpmd

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

testIfBackingIsNecessary accesses the super-global variable $_SERVER.
Open

    protected function testIfBackingIsNecessary()
    {
        if (!file_exists(dirname($_SERVER["SCRIPT_FILENAME"]) . "/" . "composer.json")) {
            return false;
        }
Severity: Minor
Found in backer.php by phpmd

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

back accesses the super-global variable $_SERVER.
Open

    protected function back()
    {
        $phar = new Phar(
            $this->tmpDir . $this->backedName . ".phar",
            FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME,
Severity: Minor
Found in backer.php by phpmd

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

testIfBackingIsNecessary accesses the super-global variable $_SERVER.
Open

    protected function testIfBackingIsNecessary()
    {
        if (!file_exists(dirname($_SERVER["SCRIPT_FILENAME"]) . "/" . "composer.json")) {
            return false;
        }
Severity: Minor
Found in backer.php by phpmd

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

testIfBackingIsNecessary accesses the super-global variable $_SERVER.
Open

    protected function testIfBackingIsNecessary()
    {
        if (!file_exists(dirname($_SERVER["SCRIPT_FILENAME"]) . "/" . "composer.json")) {
            return false;
        }
Severity: Minor
Found in backer.php by phpmd

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

Function addDirToPhar has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    public function addDirToPhar($dirName)
    {
        $dirName = rtrim($dirName, "/") . "/";
        foreach (scandir($dirName) as $key => $value) {
            if (!in_array($value, array(".", ".."))) {
Severity: Minor
Found in backer.php - About 35 mins to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Missing class import via use statement (line '73', column '21').
Open

        $phar = new Phar(
Severity: Minor
Found in backer.php by phpmd

MissingImport

Since: 2.7.0

Importing all external classes in a file through use statements makes them clearly visible.

Example

function make() {
    return new \stdClass();
}

Source http://phpmd.org/rules/cleancode.html#MissingImport

The method addDirToPhar uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

                } else {
                    $this->addFileToPhar($dirName . $value);
                }
Severity: Minor
Found in backer.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 '$key'.
Open

        foreach (scandir($dirName) as $key => $value) {
Severity: Minor
Found in backer.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

Each class must be in a namespace of at least one level (a top-level vendor name)
Open

class Backer
Severity: Minor
Found in backer.php by phpcodesniffer

A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 3 and the first side effect is on line 89.
Open

<?php
Severity: Minor
Found in backer.php by phpcodesniffer

Closing parenthesis of a multi-line function call must be on a line by itself
Open

            $this->backedName . ".phar");
Severity: Minor
Found in backer.php by phpcodesniffer

Multi-line function call not indented correctly; expected 8 spaces but found 12
Open

            $this->backedName . ".phar");
Severity: Minor
Found in backer.php by phpcodesniffer

Expected 1 newline at end of file; 0 found
Open

return ($backer->run());
Severity: Minor
Found in backer.php by phpcodesniffer

There are no issues that match your filters.

Category
Status