TikiWiki/tiki-manager

View on GitHub
src/Libs/Database/Database.php

Summary

Maintainability
C
7 hrs
Test Coverage

File Database.php has 307 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/Libs/Database/Database.php - About 3 hrs to fix

    The class Database has 14 public methods. Consider refactoring Database to keep number of public methods under 10.
    Open

    class Database
    {
        /** @var Instance */
        private $instance;
        private $access;
    Severity: Minor
    Found in src/Libs/Database/Database.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 Database has an overall complexity of 65 which is very high. The configured complexity threshold is 50.
    Open

    class Database
    {
        /** @var Instance */
        private $instance;
        private $access;
    Severity: Minor
    Found in src/Libs/Database/Database.php by phpmd

    Database has 24 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Database
    {
        /** @var Instance */
        private $instance;
        private $access;
    Severity: Minor
    Found in src/Libs/Database/Database.php - About 2 hrs to fix

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

          public function setupConnection()
          {
              $config = $this->instance->getDatabaseConfig();
      
              if ($config instanceof Database) {
      Severity: Minor
      Found in src/Libs/Database/Database.php - About 1 hr to fix

        Function setupConnection has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            public function setupConnection()
            {
                $config = $this->instance->getDatabaseConfig();
        
                if ($config instanceof Database) {
        Severity: Minor
        Found in src/Libs/Database/Database.php - About 25 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

        Avoid using undefined variables such as '$db_tiki' which will lead to PHP notices.
        Open

                        'type' => $db_tiki ?? '',
        Severity: Minor
        Found in src/Libs/Database/Database.php by phpmd

        UndefinedVariable

        Since: 2.8.0

        Detects when a variable is used that has not been defined before.

        Example

        class Foo
        {
            private function bar()
            {
                // $message is undefined
                echo $message;
            }
        }

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

        Avoid using undefined variables such as '$dbs_tiki' which will lead to PHP notices.
        Open

                        'dbname' => $dbs_tiki ?? '',
        Severity: Minor
        Found in src/Libs/Database/Database.php by phpmd

        UndefinedVariable

        Since: 2.8.0

        Detects when a variable is used that has not been defined before.

        Example

        class Foo
        {
            private function bar()
            {
                // $message is undefined
                echo $message;
            }
        }

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

        Avoid using undefined variables such as '$user_tiki' which will lead to PHP notices.
        Open

                        'user' => $user_tiki ?? '',
        Severity: Minor
        Found in src/Libs/Database/Database.php by phpmd

        UndefinedVariable

        Since: 2.8.0

        Detects when a variable is used that has not been defined before.

        Example

        class Foo
        {
            private function bar()
            {
                // $message is undefined
                echo $message;
            }
        }

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

        Avoid using undefined variables such as '$host_tiki' which will lead to PHP notices.
        Open

                        'host' => $host_tiki ?? '',
        Severity: Minor
        Found in src/Libs/Database/Database.php by phpmd

        UndefinedVariable

        Since: 2.8.0

        Detects when a variable is used that has not been defined before.

        Example

        class Foo
        {
            private function bar()
            {
                // $message is undefined
                echo $message;
            }
        }

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

        Avoid using undefined variables such as '$pass_tiki' which will lead to PHP notices.
        Open

                        'pass' => $pass_tiki ?? '',
        Severity: Minor
        Found in src/Libs/Database/Database.php by phpmd

        UndefinedVariable

        Since: 2.8.0

        Detects when a variable is used that has not been defined before.

        Example

        class Foo
        {
            private function bar()
            {
                // $message is undefined
                echo $message;
            }
        }

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

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

            public function getCurrentUserPermissions($refresh = false)
        Severity: Minor
        Found in src/Libs/Database/Database.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

        Missing class import via use statement (line '385', column '23').
        Open

                    throw new \RuntimeException("Can't setup database!\nError: " . $e->getMessage());
        Severity: Minor
        Found in src/Libs/Database/Database.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

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

                if (ApplicationHelper::isWindows()) {
        Severity: Minor
        Found in src/Libs/Database/Database.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\Ext\Password' in method 'createAccess'.
        Open

                $pass = $pass ?: Password::create(12, 'unpronounceable');
        Severity: Minor
        Found in src/Libs/Database/Database.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 unused local variables such as '$result'.
        Open

                $result = $this->query($sql);
        Severity: Minor
        Found in src/Libs/Database/Database.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 '$db_tiki'.
        Open

                        'type' => $db_tiki ?? '',
        Severity: Minor
        Found in src/Libs/Database/Database.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 '$result'.
        Open

                $result = $this->query($sql);
        Severity: Minor
        Found in src/Libs/Database/Database.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 '$host_tiki'.
        Open

                        'host' => $host_tiki ?? '',
        Severity: Minor
        Found in src/Libs/Database/Database.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 '$user_tiki'.
        Open

                        'user' => $user_tiki ?? '',
        Severity: Minor
        Found in src/Libs/Database/Database.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 '$success'.
        Open

                $success = $this->createDatabase($dbname)
        Severity: Minor
        Found in src/Libs/Database/Database.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 '$result'.
        Open

                $result = $this->query($sql);
        Severity: Minor
        Found in src/Libs/Database/Database.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 '$result'.
        Open

                $result = $this->query($sql);
        Severity: Minor
        Found in src/Libs/Database/Database.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 '$dbs_tiki'.
        Open

                        'dbname' => $dbs_tiki ?? '',
        Severity: Minor
        Found in src/Libs/Database/Database.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 '$pass_tiki'.
        Open

                        'pass' => $pass_tiki ?? '',
        Severity: Minor
        Found in src/Libs/Database/Database.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

        Saw an @param annotation for config, but the param list of function setupConnection() : \TikiManager\Libs\Database\Database|null|static is empty
        Open

             * @param Database|array $config
        Severity: Info
        Found in src/Libs/Database/Database.php by phan

        The parameter $db_local_path is not named in camelCase.
        Open

            public static function createFromConfig($instance, $db_local_path)
            {
                if (! (file_exists($db_local_path) && filesize($db_local_path) > 0)) {
                    return null;
                }
        Severity: Minor
        Found in src/Libs/Database/Database.php by phpmd

        CamelCaseParameterName

        Since: 0.2

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

        Example

        class ClassName {
            public function doSomething($user_name) {
            }
        }

        Source

        The parameter $db_local_path is not named in camelCase.
        Open

            public static function getInstanceDataBaseConfig($db_local_path)
            {
                $getConfig = function ($db_local_path) {
                    include($db_local_path);
                    return array(
        Severity: Minor
        Found in src/Libs/Database/Database.php by phpmd

        CamelCaseParameterName

        Since: 0.2

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

        Example

        class ClassName {
            public function doSomething($user_name) {
            }
        }

        Source

        The variable $host_tiki is not named in camelCase.
        Open

            public static function getInstanceDataBaseConfig($db_local_path)
            {
                $getConfig = function ($db_local_path) {
                    include($db_local_path);
                    return array(
        Severity: Minor
        Found in src/Libs/Database/Database.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 $command_result is not named in camelCase.
        Open

            public function query($sql)
            {
                $args = array(
                    '-u', $this->user,
                    '-p'. escapeshellarg($this->pass),
        Severity: Minor
        Found in src/Libs/Database/Database.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 $db_local_path is not named in camelCase.
        Open

            public static function getInstanceDataBaseConfig($db_local_path)
            {
                $getConfig = function ($db_local_path) {
                    include($db_local_path);
                    return array(
        Severity: Minor
        Found in src/Libs/Database/Database.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 $command_result is not named in camelCase.
        Open

            public function query($sql)
            {
                $args = array(
                    '-u', $this->user,
                    '-p'. escapeshellarg($this->pass),
        Severity: Minor
        Found in src/Libs/Database/Database.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 $db_local_path is not named in camelCase.
        Open

            public static function getInstanceDataBaseConfig($db_local_path)
            {
                $getConfig = function ($db_local_path) {
                    include($db_local_path);
                    return array(
        Severity: Minor
        Found in src/Libs/Database/Database.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 $pass_tiki is not named in camelCase.
        Open

            public static function getInstanceDataBaseConfig($db_local_path)
            {
                $getConfig = function ($db_local_path) {
                    include($db_local_path);
                    return array(
        Severity: Minor
        Found in src/Libs/Database/Database.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 $dbs_tiki is not named in camelCase.
        Open

            public static function getInstanceDataBaseConfig($db_local_path)
            {
                $getConfig = function ($db_local_path) {
                    include($db_local_path);
                    return array(
        Severity: Minor
        Found in src/Libs/Database/Database.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 $user_tiki is not named in camelCase.
        Open

            public static function getInstanceDataBaseConfig($db_local_path)
            {
                $getConfig = function ($db_local_path) {
                    include($db_local_path);
                    return array(
        Severity: Minor
        Found in src/Libs/Database/Database.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 $command_result is not named in camelCase.
        Open

            public function query($sql)
            {
                $args = array(
                    '-u', $this->user,
                    '-p'. escapeshellarg($this->pass),
        Severity: Minor
        Found in src/Libs/Database/Database.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 $db_local_path is not named in camelCase.
        Open

            public static function createFromConfig($instance, $db_local_path)
            {
                if (! (file_exists($db_local_path) && filesize($db_local_path) > 0)) {
                    return null;
                }
        Severity: Minor
        Found in src/Libs/Database/Database.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 $db_local_path is not named in camelCase.
        Open

            public static function createFromConfig($instance, $db_local_path)
            {
                if (! (file_exists($db_local_path) && filesize($db_local_path) > 0)) {
                    return null;
                }
        Severity: Minor
        Found in src/Libs/Database/Database.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 $db_local_path is not named in camelCase.
        Open

            public static function createFromConfig($instance, $db_local_path)
            {
                if (! (file_exists($db_local_path) && filesize($db_local_path) > 0)) {
                    return null;
                }
        Severity: Minor
        Found in src/Libs/Database/Database.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 $db_local_path is not named in camelCase.
        Open

            public static function createFromConfig($instance, $db_local_path)
            {
                if (! (file_exists($db_local_path) && filesize($db_local_path) > 0)) {
                    return null;
                }
        Severity: Minor
        Found in src/Libs/Database/Database.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 $db_tiki is not named in camelCase.
        Open

            public static function getInstanceDataBaseConfig($db_local_path)
            {
                $getConfig = function ($db_local_path) {
                    include($db_local_path);
                    return array(
        Severity: Minor
        Found in src/Libs/Database/Database.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