TikiWiki/tiki-manager

View on GitHub
src/Libs/Host/Local.php

Summary

Maintainability
C
1 day
Test Coverage

__construct accesses the super-global variable $_ENV.
Open

    public function __construct()
    {
        $_ENV['HTTP_ACCEPT_ENCODING'] = '';
        $this->env = $_ENV ?: [];
        $this->io = App::get('io');
Severity: Minor
Found in src/Libs/Host/Local.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

__construct accesses the super-global variable $_ENV.
Open

    public function __construct()
    {
        $_ENV['HTTP_ACCEPT_ENCODING'] = '';
        $this->env = $_ENV ?: [];
        $this->io = App::get('io');
Severity: Minor
Found in src/Libs/Host/Local.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

openShell accesses the super-global variable $_ENV.
Open

    public function openShell($workingDir = '')
    {

        if (empty($workingDir)) {
            return;
Severity: Minor
Found in src/Libs/Host/Local.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

runCommands accesses the super-global variable $_ENV.
Open

    public function runCommands($commands, $output = false)
    {
        if (!is_array($commands)) {
            $commands = func_get_args();
        }
Severity: Minor
Found in src/Libs/Host/Local.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

runCommand accesses the super-global variable $_ENV.
Open

    public function runCommand(Command $command, array $options = [])
    {
        $cwd = !empty($options['cwd']) ? $options['cwd'] : $this->location;
        $env = !empty($options['env']) ? $options['env'] : [];

Severity: Minor
Found in src/Libs/Host/Local.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

mergeWithExistingEnvironmentVariables accesses the super-global variable $_ENV.
Open

    protected function mergeWithExistingEnvironmentVariables($newEnvironmentVariables)
    {
        $env = [];

        // getenv will only return all env variables starting 7.1.0
Severity: Minor
Found in src/Libs/Host/Local.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

mergeWithExistingEnvironmentVariables accesses the super-global variable $_SERVER.
Open

    protected function mergeWithExistingEnvironmentVariables($newEnvironmentVariables)
    {
        $env = [];

        // getenv will only return all env variables starting 7.1.0
Severity: Minor
Found in src/Libs/Host/Local.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

Method windowsSync has 38 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function windowsSync($remoteLocation, $localMirror, $files = [], $exclusions = [])
    {

        $exclude = '';
        $returnVar = 0;
Severity: Minor
Found in src/Libs/Host/Local.php - About 1 hr to fix

    Method rsync has 32 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function rsync($args = [])
        {
            $return_val = -1;
    
            if (empty($args['src']) || empty($args['dest'])) {
    Severity: Minor
    Found in src/Libs/Host/Local.php - About 1 hr to fix

      Function mergeWithExistingEnvironmentVariables has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function mergeWithExistingEnvironmentVariables($newEnvironmentVariables)
          {
              $env = [];
      
              // getenv will only return all env variables starting 7.1.0
      Severity: Minor
      Found in src/Libs/Host/Local.php - About 1 hr 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

      Method runCommands has 30 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function runCommands($commands, $output = false)
          {
              if (!is_array($commands)) {
                  $commands = func_get_args();
              }
      Severity: Minor
      Found in src/Libs/Host/Local.php - About 1 hr to fix

        Function runCommands has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

            public function runCommands($commands, $output = false)
            {
                if (!is_array($commands)) {
                    $commands = func_get_args();
                }
        Severity: Minor
        Found in src/Libs/Host/Local.php - About 55 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

        The method runCommands has a boolean flag argument $output, which is a certain sign of a Single Responsibility Principle violation.
        Open

            public function runCommands($commands, $output = false)
        Severity: Minor
        Found in src/Libs/Host/Local.php by phpmd

        BooleanArgumentFlag

        Since: 1.4.0

        A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

        Example

        class Foo {
            public function bar($flag = true) {
            }
        }

        Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

        Avoid using static access to class '\TikiManager\Libs\Helpers\ApplicationHelper' in method 'receiveFile'.
        Open

                if (ApplicationHelper::isWindows()) {
        Severity: Minor
        Found in src/Libs/Host/Local.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 receiveFile uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                } else {
                    $command = sprintf(
                        'rsync -av %s %s',
                        escapeshellarg($remoteFile),
                        escapeshellarg($localFile)
        Severity: Minor
        Found in src/Libs/Host/Local.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 runCommands uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                    } else {
                        $contents .= (!empty($contents) ? "\n" : '') . $result;
                    }
        Severity: Minor
        Found in src/Libs/Host/Local.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 '\Symfony\Component\Process\Process' in method 'runCommands'.
        Open

                    $process = Process::fromShellCommandline($cmd . ' 2>&1', $this->location, $this->env, null, $_ENV['COMMAND_EXECUTION_TIMEOUT']);
        Severity: Minor
        Found in src/Libs/Host/Local.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 '\TikiManager\Libs\Helpers\ApplicationHelper' in method 'sendFile'.
        Open

                if (ApplicationHelper::isWindows()) {
        Severity: Minor
        Found in src/Libs/Host/Local.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 assigning values to variables in if clauses and the like (line '54', column '13').
        Open

            public function runCommand(Command $command, array $options = [])
            {
                $cwd = !empty($options['cwd']) ? $options['cwd'] : $this->location;
                $env = !empty($options['env']) ? $options['env'] : [];
        
        
        Severity: Minor
        Found in src/Libs/Host/Local.php by phpmd

        IfStatementAssignment

        Since: 2.7.0

        Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

        Example

        class Foo
        {
            public function bar($flag)
            {
                if ($foo = 'bar') { // possible typo
                    // ...
                }
                if ($baz = 0) { // always false
                    // ...
                }
            }
        }

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

        Avoid assigning values to variables in if clauses and the like (line '298', column '17').
        Open

            protected function mergeWithExistingEnvironmentVariables($newEnvironmentVariables)
            {
                $env = [];
        
                // getenv will only return all env variables starting 7.1.0
        Severity: Minor
        Found in src/Libs/Host/Local.php by phpmd

        IfStatementAssignment

        Since: 2.7.0

        Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

        Example

        class Foo
        {
            public function bar($flag)
            {
                if ($foo = 'bar') { // possible typo
                    // ...
                }
                if ($baz = 0) { // always false
                    // ...
                }
            }
        }

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

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

                } else {
                    $command = sprintf(
                        'rsync -av %s %s',
                        escapeshellarg($localFile),
                        escapeshellarg($remoteFile)
        Severity: Minor
        Found in src/Libs/Host/Local.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 windowsSync uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                } else {
                    $files = '';
                }
        Severity: Minor
        Found in src/Libs/Host/Local.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 '$prefix'.
        Open

                    debug($result, $prefix = "({$exitCode})>>", "\n\n");
        Severity: Minor
        Found in src/Libs/Host/Local.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 unused local variables such as '$prefix'.
        Open

                debug($output, $prefix = "({$returnVar})>>", PHP_EOL . PHP_EOL);
        Severity: Minor
        Found in src/Libs/Host/Local.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 unused local variables such as '$tmp'.
        Open

                foreach ($_SERVER as $variable => $tmp) {
        Severity: Minor
        Found in src/Libs/Host/Local.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 unused local variables such as '$prefix'.
        Open

                debug($output, $prefix = "({$return_var})>>", "\n\n");
        Severity: Minor
        Found in src/Libs/Host/Local.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

        TODO found
        Open

                // TODO: There several calls to this function, each one with different
        Severity: Minor
        Found in src/Libs/Host/Local.php by fixme

        Call to deprecated function \warning() defined at /code/src/Libs/Helpers/functions.php:136
        Open

                            warning(sprintf('%s [%d]', $cmd, $exitCode));
        Severity: Minor
        Found in src/Libs/Host/Local.php by phan

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

            public function sendFile($localFile, $remoteFile)
            {
                if (ApplicationHelper::isWindows()) {
                    $localFile = str_replace('/', DIRECTORY_SEPARATOR, $localFile);
                    $remoteFile = str_replace('/', DIRECTORY_SEPARATOR, $remoteFile);
        Severity: Major
        Found in src/Libs/Host/Local.php and 1 other location - About 3 hrs to fix
        src/Libs/Host/Local.php on lines 140..160

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 147.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        Similar blocks of code found in 2 locations. Consider refactoring.
        Open

            public function receiveFile($remoteFile, $localFile)
            {
                if (ApplicationHelper::isWindows()) {
                    $remoteFile = str_replace('/', DIRECTORY_SEPARATOR, $remoteFile);
                    $localFile = str_replace('/', DIRECTORY_SEPARATOR, $localFile);
        Severity: Major
        Found in src/Libs/Host/Local.php and 1 other location - About 3 hrs to fix
        src/Libs/Host/Local.php on lines 118..138

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 147.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        The property $last_command_exit_code is not named in camelCase.
        Open

        class Local
        {
            private $env;
            private $last_command_exit_code = 0;
            private $location;
        Severity: Minor
        Found in src/Libs/Host/Local.php by phpmd

        CamelCasePropertyName

        Since: 0.2

        It is considered best practice to use the camelCase notation to name attributes.

        Example

        class ClassName {
            protected $property_name;
        }

        Source

        The variable $return_var is not named in camelCase.
        Open

            public function rsync($args = [])
            {
                $return_val = -1;
        
                if (empty($args['src']) || empty($args['dest'])) {
        Severity: Minor
        Found in src/Libs/Host/Local.php by phpmd

        CamelCaseVariableName

        Since: 0.2

        It is considered best practice to use the camelCase notation to name variables.

        Example

        class ClassName {
            public function doSomething() {
                $data_module = new DataModule();
            }
        }

        Source

        The variable $return_val is not named in camelCase.
        Open

            public function rsync($args = [])
            {
                $return_val = -1;
        
                if (empty($args['src']) || empty($args['dest'])) {
        Severity: Minor
        Found in src/Libs/Host/Local.php by phpmd

        CamelCaseVariableName

        Since: 0.2

        It is considered best practice to use the camelCase notation to name variables.

        Example

        class ClassName {
            public function doSomething() {
                $data_module = new DataModule();
            }
        }

        Source

        The variable $return_var is not named in camelCase.
        Open

            public function rsync($args = [])
            {
                $return_val = -1;
        
                if (empty($args['src']) || empty($args['dest'])) {
        Severity: Minor
        Found in src/Libs/Host/Local.php by phpmd

        CamelCaseVariableName

        Since: 0.2

        It is considered best practice to use the camelCase notation to name variables.

        Example

        class ClassName {
            public function doSomething() {
                $data_module = new DataModule();
            }
        }

        Source

        The variable $return_val is not named in camelCase.
        Open

            public function rsync($args = [])
            {
                $return_val = -1;
        
                if (empty($args['src']) || empty($args['dest'])) {
        Severity: Minor
        Found in src/Libs/Host/Local.php by phpmd

        CamelCaseVariableName

        Since: 0.2

        It is considered best practice to use the camelCase notation to name variables.

        Example

        class ClassName {
            public function doSomething() {
                $data_module = new DataModule();
            }
        }

        Source

        The variable $return_var is not named in camelCase.
        Open

            public function rsync($args = [])
            {
                $return_val = -1;
        
                if (empty($args['src']) || empty($args['dest'])) {
        Severity: Minor
        Found in src/Libs/Host/Local.php by phpmd

        CamelCaseVariableName

        Since: 0.2

        It is considered best practice to use the camelCase notation to name variables.

        Example

        class ClassName {
            public function doSomething() {
                $data_module = new DataModule();
            }
        }

        Source

        The variable $return_var is not named in camelCase.
        Open

            public function rsync($args = [])
            {
                $return_val = -1;
        
                if (empty($args['src']) || empty($args['dest'])) {
        Severity: Minor
        Found in src/Libs/Host/Local.php by phpmd

        CamelCaseVariableName

        Since: 0.2

        It is considered best practice to use the camelCase notation to name variables.

        Example

        class ClassName {
            public function doSomething() {
                $data_module = new DataModule();
            }
        }

        Source

        The variable $return_var is not named in camelCase.
        Open

            public function rsync($args = [])
            {
                $return_val = -1;
        
                if (empty($args['src']) || empty($args['dest'])) {
        Severity: Minor
        Found in src/Libs/Host/Local.php by phpmd

        CamelCaseVariableName

        Since: 0.2

        It is considered best practice to use the camelCase notation to name variables.

        Example

        class ClassName {
            public function doSomething() {
                $data_module = new DataModule();
            }
        }

        Source

        There are no issues that match your filters.

        Category
        Status