TikiWiki/tiki-manager

View on GitHub
src/Access/FTP.php

Summary

Maintainability
C
7 hrs
Test Coverage

synchronize accesses the super-global variable $_ENV.
Open

    public function synchronize($source, $mirror, $keepFolderName = false)
    {
        $source = rtrim($source, '/') . ($keepFolderName ? '' : '/');
        $mirror = rtrim($mirror, '/') . '/';

Severity: Minor
Found in src/Access/FTP.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

downloadFile accesses the super-global variable $_ENV.
Open

    public function downloadFile($filename, $target = ''): string
    {
        if ($filename[0] != '/') {
            $filename = $this->instance->getWebPath($filename);
        }
Severity: Minor
Found in src/Access/FTP.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

copyLocalFolder accesses the super-global variable $_ENV.
Open

    public function copyLocalFolder($localFolder, $remoteFolder = '')
    {
        if ($remoteFolder[0] != '/') {
            $remoteFolder = $this->instance->getWebPath($remoteFolder);
        }
Severity: Minor
Found in src/Access/FTP.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

The class FTP has 19 public methods. Consider refactoring FTP to keep number of public methods under 10.
Open

class FTP extends Access implements Mountable
{
    private $lastMount;

    public function __construct(Instance $instance)
Severity: Minor
Found in src/Access/FTP.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 FTP has an overall complexity of 51 which is very high. The configured complexity threshold is 50.
Open

class FTP extends Access implements Mountable
{
    private $lastMount;

    public function __construct(Instance $instance)
Severity: Minor
Found in src/Access/FTP.php by phpmd

FTP has 25 functions (exceeds 20 allowed). Consider refactoring.
Open

class FTP extends Access implements Mountable
{
    private $lastMount;

    public function __construct(Instance $instance)
Severity: Minor
Found in src/Access/FTP.php - About 2 hrs to fix

    File FTP.php has 261 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    // Copyright (c) 2016, Avan.Tech, et. al.
    // Copyright (c) 2008, Luis Argerich, Garland Foster, Eduardo Polidor, et. al.
    // All Rights Reserved. See copyright.txt for details and a complete list of authors.
    // Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
    Severity: Minor
    Found in src/Access/FTP.php - About 2 hrs to fix

      Method localizeFolder has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function localizeFolder($remoteLocation, $localMirror)
          {
              if ($remoteLocation[0] != '/') {
                  $remoteLocation = $this->instance->getWebPath($remoteLocation);
              }
      Severity: Minor
      Found in src/Access/FTP.php - About 1 hr to fix

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

            public function synchronize($source, $mirror, $keepFolderName = false)
        Severity: Minor
        Found in src/Access/FTP.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

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

                } else {
                    `tar -xf $eLoc`;
                }
        Severity: Minor
        Found in src/Access/FTP.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 uploadFile uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
        Open

                } else {
                    $host->sendFile($filename, $this->instance->getWebPath($remoteLocation));
                }
        Severity: Minor
        Found in src/Access/FTP.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

        TODO found
        Open

            // TODO: change directory using FTP
        Severity: Minor
        Found in src/Access/FTP.php by fixme

        Argument 1 (str) is int but \md5() takes string
        Open

                $name = md5(time()) . '.tar';
        Severity: Minor
        Found in src/Access/FTP.php by phan

        Argument 1 (str) is int but \md5() takes string
        Open

                $name = md5(time()) . '.tar';
        Severity: Minor
        Found in src/Access/FTP.php by phan

        Assigning 21 to property but \TikiManager\Access\FTP->port is string
        Open

                $this->port = 21;
        Severity: Minor
        Found in src/Access/FTP.php by phan

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

            public function moveFile($remoteSource, $remoteTarget)
            {
                if ($remoteSource[0] != '/') {
                    $remoteSource = $this->instance->getWebPath($remoteSource);
                }
        Severity: Minor
        Found in src/Access/FTP.php and 1 other location - About 30 mins to fix
        src/Access/FTP.php on lines 164..175

        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 90.

        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 copyFile($remoteSource, $remoteTarget)
            {
                if ($remoteSource[0] != '/') {
                    $remoteSource = $this->instance->getWebPath($remoteSource);
                }
        Severity: Minor
        Found in src/Access/FTP.php and 1 other location - About 30 mins to fix
        src/Access/FTP.php on lines 151..162

        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 90.

        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

        There are no issues that match your filters.

        Category
        Status