openva/rs-video-processor

View on GitHub
bin/detect_faces.php

Summary

Maintainability
A
2 hrs
Test Coverage

File detect_faces.php has 258 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

Severity: Minor
Found in bin/detect_faces.php - About 2 hrs to fix

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

                    if (($individual['center']['x'] > 40) && ($individual['center']['x'] < 60)) {
    Severity: Critical
    Found in bin/detect_faces.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.

    Define a constant instead of duplicating this literal "&api_secret=" 4 times.
    Open

            $json = get_content('http://api.face.com/faces/detect.json?api_key=' . FACE_API_KEY . '&api_secret='
    Severity: Critical
    Found in bin/detect_faces.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.

    Remove this commented out code.
    Open

    # Open a MySQL connection. require_once 'MDB2.php';
    Severity: Major
    Found in bin/detect_faces.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 a constant instead of duplicating this literal "smiling" 3 times.
    Open

                if (isset($face['attributes']['smiling'])) {
    Severity: Critical
    Found in bin/detect_faces.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.

    Define a constant instead of duplicating this literal "@richmondsunlight.com," 3 times.
    Open

        $senators_list = implode('@richmondsunlight.com,', $senators);
    Severity: Critical
    Found in bin/detect_faces.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.

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

                        mood_confidence=' . $face['attributes']['mood']['confidence'];
    Severity: Critical
    Found in bin/detect_faces.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.

    Define a constant instead of duplicating this literal "image" 5 times.
    Open

                . FACE_API_SECRET . '&urls=http://www.richmondsunlight.com/' . $screenshot['image']);
    Severity: Critical
    Found in bin/detect_faces.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.

    Define a constant instead of duplicating this literal "attributes" 6 times.
    Open

                if (isset($face['attributes']['mood'])) {
    Severity: Critical
    Found in bin/detect_faces.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.

    Define a constant instead of duplicating this literal "shortname" 9 times.
    Open

                    <p>' . $screenshot['shortname'] . '</p>
    Severity: Critical
    Found in bin/detect_faces.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.

    Remove this commented out code.
    Open

            //echo '<pre>'.print_r($face_data, true).'</pre>';
    Severity: Major
    Found in bin/detect_faces.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"

    A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 14 and the first side effect is on line 3.
    Open

    <?php
    Severity: Minor
    Found in bin/detect_faces.php by phpcodesniffer

    Line exceeds 120 characters; contains 123 characters
    Open

                <meta http-equiv=Refresh CONTENT="60; URL=http://www.richmondsunlight.com/utilities/detect_faces.php?op=train">
    Severity: Minor
    Found in bin/detect_faces.php by phpcodesniffer

    Line exceeds 120 characters; contains 124 characters
    Open

                <meta http-equiv=Refresh CONTENT="60; URL=http://www.richmondsunlight.com/utilities/detect_faces.php?op=detect">
    Severity: Minor
    Found in bin/detect_faces.php by phpcodesniffer

    Expected 1 space after closing brace; newline found
    Open

    }
    Severity: Minor
    Found in bin/detect_faces.php by phpcodesniffer

    Expected 1 space after closing brace; newline found
    Open

    }
    Severity: Minor
    Found in bin/detect_faces.php by phpcodesniffer

    Expected 1 space after closing brace; newline found
    Open

            }
    Severity: Minor
    Found in bin/detect_faces.php by phpcodesniffer

    There are no issues that match your filters.

    Category
    Status