guillaumemonet/Rad

View on GitHub

Showing 80 of 80 total issues

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

    private static function getTableIndexes(string $table_name): array {
        $indexes = ['primary' => [], 'unique' => [], 'key' => []];
        // Récupérer les informations sur les indexes depuis la base de données
        $pdo     = Database::getHandler();

Severity: Minor
Found in src/Rad/Model/ModelDatabase.php - About 1 hr to fix

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

        public function generateParse(ClassType $class, Table $table) {
            $parse = $class->addMethod('parse');
            $parse->setVisibility('public');
            $parse->addParameter("row")->setType("array");
            foreach ($table->columns as $col_name => $col) {
    Severity: Minor
    Found in src/Rad/Build/DatabaseBuilder/ClassesGenerator.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

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

        private static function getTableColumns(string $table_name): array {
            $columns = [];
            // Récupérer les informations sur les colonnes depuis la base de données
            $sql     = "SHOW COLUMNS FROM $table_name";
            $result  = Database::getHandler()->query($sql);
    Severity: Minor
    Found in src/Rad/Model/ModelDatabase.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

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

        private static function createTableIfNotExists(string $table_name, array $columns, array $indexes) {
            $pdo = Database::getHandler();
    
            // Vérifier si la table existe déjà dans la base de données
            $query        = "SHOW TABLES LIKE '$table_name'";
    Severity: Minor
    Found in src/Rad/Model/ModelDatabase.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

    Function generateIndexesGetter has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        public function generateIndexesGetter(ClassType $class, Table $table) {
            foreach ($table->indexes as $k => $i) {
                if ($i->name == "PRIMARY") {
                    $this->generatePrimaryIndexGetter($class, $k, $i);
                } else if ($i->unique) {
    Severity: Minor
    Found in src/Rad/Build/DatabaseBuilder/ClassesGeneratorStaticTrait.php - About 45 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

    Function getColumnDefinition has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        private static function getColumnDefinition(string $column_name, array $column_info): string {
            $column_definition = $column_name . ' ' . $column_info['type'];
            $nodefault         = false;
            // Ajouter la taille si spécifiée dans les commentaires
            if (isset($column_info['length'])) {
    Severity: Minor
    Found in src/Rad/Model/ModelDatabase.php - About 45 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

    Function getTableStructure has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function getTableStructure($table) {
            $columns = [];
            $result  = Database::getHandler()->query("SHOW FULL COLUMNS FROM `$table`;");
            while ($row     = $result->fetch()) {
                $column       = new Column();
    Severity: Minor
    Found in src/Rad/Build/DatabaseBuilder/GeneratorTools.php - About 45 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

    Method call has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        public function call(string $endpoint, array $get = null, array $post = null, array $header = [], bool $caching = true);
    Severity: Minor
    Found in src/Rad/ClientApi/ClientApiInterface.php - About 35 mins to fix

      Method call has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          public function call(string $endpoint, array $get = null, array $post = null, array $headers = [], bool $caching = true) {
      Severity: Minor
      Found in src/Rad/ClientApi/ClientApiHandler.php - About 35 mins to fix

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

            public static function addImageWithFade($imagePath, $position, $step = 30) {
                // Créer une image vide blanche de dimensions 1200x500
                $canvas          = imagecreatetruecolor(1200, 500);
                $backgroundColor = imagecolorallocate($canvas, 255, 255, 255);
                imagefill($canvas, 0, 0, $backgroundColor);
        Severity: Minor
        Found in src/Rad/Utils/Image.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

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

            public function loadTrads() {
                $filePath = Config::getApiConfig()->install_path . $this->config->locales_path;
                if (file_exists($filePath)) {
                    $fileContents = file_get_contents($filePath);
                    if ($fileContents === false) {
        Severity: Minor
        Found in src/Rad/Language/LanguageHandler.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

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

            public function generateProperties(ClassType $class, Table $table) {
                foreach ($table->columns as $col_name => $col) {
                    if (str_ends_with($col_name, "i18n") && $col->auto == 0 && !str_starts_with($table->name, "i18n")) {
                        $propertyName = str_replace("_i18n", "", $col_name);
                        $property     = $class->addProperty($propertyName)
        Severity: Minor
        Found in src/Rad/Build/DatabaseBuilder/ClassesGenerator.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

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

            public final function run(Closure $finalClosure = null, Closure $errorClosure = null): void {
                try {
                    $this->getRouter()
                            ->load($this->controllers)
                            ->route($this->request)
        Severity: Minor
        Found in src/Rad/Rad.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

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

            private function generateClasses(array $tables) {
                foreach ($tables as $name => $table) {
                    if (strpos($name, "_has_") !== false) {
                        continue;
                    }
        Severity: Minor
        Found in src/Rad/Build/DatabaseBuildHandler.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

        Remove this commented out code.
        Open

                header("Connection: close"); //or redirect to some url: header('Location: http://www.google.com');
        Severity: Major
        Found in src/Rad/Http/HttpBuffer.php by sonar-php

        Programmers should not comment out code as it bloats programs and reduces readability.

        Unused code should be deleted and can be retrieved from source control history if required.

        See

        • MISRA C:2004, 2.4 - Sections of code should not be "commented out".
        • MISRA C++:2008, 2-7-2 - Sections of code shall not be "commented out" using C-style comments.
        • MISRA C++:2008, 2-7-3 - Sections of code should not be "commented out" using C++ comments.
        • MISRA C:2012, Dir. 4.4 - Sections of code should not be "commented out"

        Define and throw a dedicated exception instead of using a generic one.
        Open

                    throw new Exception("La classe $class_name n'existe pas.");
        Severity: Major
        Found in src/Rad/Model/ModelDatabase.php by sonar-php

        If you throw a general exception type, such as ErrorException, RuntimeException, or Exception in a library or framework, it forces consumers to catch all exceptions, including unknown exceptions that they do not know how to handle.

        Instead, either throw a subtype that already exists in the Standard PHP Library, or create your own type that derives from Exception.

        Noncompliant Code Example

        throw new Exception();  // Noncompliant
        

        Compliant Solution

        throw new InvalidArgumentException();
        // or
        throw new UnexpectedValueException();
        

        See

        Refactor this function to reduce its Cognitive Complexity from 34 to the 15 allowed.
        Open

            private static function getClassAttributes(string $class_name): array {
        Severity: Critical
        Found in src/Rad/Model/ModelDatabase.php by sonar-php

        Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

        See

        Define a constant instead of duplicating this literal "array" 8 times.
        Open

                'middleware' => ['method' => 'addMiddlewares', 'type' => 'array'],
        Severity: Critical
        Found in src/Rad/Route/RouteParser.php by sonar-php

        Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

        On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

        Noncompliant Code Example

        With the default threshold of 3:

        function run() {
          prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
          execute('action1');
          release('action1');
        }
        

        Compliant Solution

        ACTION_1 = 'action1';
        
        function run() {
          prepare(ACTION_1);
          execute(ACTION_1);
          release(ACTION_1);
        }
        

        Exceptions

        To prevent generating some false-positives, literals having less than 5 characters are excluded.

        Reduce the number of returns of this function 4, down to the maximum allowed 3.
        Open

            private static function parseFile($file): ?string {
        Severity: Major
        Found in src/Rad/Config/AutoConfig.php by sonar-php

        Having too many return statements in a function increases the function's essential complexity because the flow of execution is broken each time a return statement is encountered. This makes it harder to read and understand the logic of the function.

        Noncompliant Code Example

        With the default threshold of 3:

        function myFunction(){ // Noncompliant as there are 4 return statements
          if (condition1) {
            return true;
          } else {
            if (condition2) {
              return false;
            } else {
              return true;
            }
          }
          return false;
        }
        

        Define a constant instead of duplicating this literal "string" 4 times.
        Open

                    "char"    => ["\\PDO::PARAM_STR", "string"],

        Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

        On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

        Noncompliant Code Example

        With the default threshold of 3:

        function run() {
          prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
          execute('action1');
          release('action1');
        }
        

        Compliant Solution

        ACTION_1 = 'action1';
        
        function run() {
          prepare(ACTION_1);
          execute(ACTION_1);
          release(ACTION_1);
        }
        

        Exceptions

        To prevent generating some false-positives, literals having less than 5 characters are excluded.

        Severity
        Category
        Status
        Source
        Language