TikiWiki/tiki-manager

View on GitHub
src/Libs/VersionControl/Src.php

Summary

Maintainability
A
3 hrs
Test Coverage

getAvailableVersions accesses the super-global variable $_ENV.
Open

    private function getAvailableVersions()
    {
        $versions = array_values(array_filter(array_map(function ($file) {
            preg_match(Src::$pattern, $file, $matches);
            return (count($matches) == 3) ? trim($matches[1]) : null;
Severity: Minor
Found in src/Libs/VersionControl/Src.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

findFileForBranch accesses the super-global variable $_ENV.
Open

    public function findFileForBranch($branchName): array
    {
        //find file for branch name
        return array_values(array_filter(scandir($_ENV['TRIM_SRC_FOLDER']), function ($file) use ($branchName) {
            preg_match(Src::$pattern, $file, $matches);
Severity: Minor
Found in src/Libs/VersionControl/Src.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

update accesses the super-global variable $_ENV.
Open

    public function update(string $targetFolder, string $branch, int $lag = 0)
    {
        if (preg_match('/(\d+)\.(\d+).*/', $branch, $matches1)) {
            $version = $matches1[0];
            $cacheFolder = $_ENV['CACHE_FOLDER'] . DIRECTORY_SEPARATOR . 'tiki-src-' . $version;
Severity: Minor
Found in src/Libs/VersionControl/Src.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 Src has 11 public methods. Consider refactoring Src to keep number of public methods under 10.
Open

class Src extends VersionControlSystem
{
    use FileArchive;

    public static $pattern = '/tiki-(.*)\.(tar\.bz2|zip|7z|tar\.gz)/';
Severity: Minor
Found in src/Libs/VersionControl/Src.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

Src has 22 functions (exceeds 20 allowed). Consider refactoring.
Open

class Src extends VersionControlSystem
{
    use FileArchive;

    public static $pattern = '/tiki-(.*)\.(tar\.bz2|zip|7z|tar\.gz)/';
Severity: Minor
Found in src/Libs/VersionControl/Src.php - About 2 hrs to fix

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

        public function getBranchToUpdate($branch)
        {
            if (preg_match('/(\d+)\.(\d+).*/', $branch, $matches1)) {
                $major = $matches1[1];
                $toUpdate = $matches1[0];
    Severity: Minor
    Found in src/Libs/VersionControl/Src.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

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

        public function info($targetFolder, $raw = false)
    Severity: Minor
    Found in src/Libs/VersionControl/Src.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\Application\Version' in method 'getAvailableBranches'.
    Open

                return Version::buildFake('src', trim($v));
    Severity: Minor
    Found in src/Libs/VersionControl/Src.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

    There are no issues that match your filters.

    Category
    Status