ampache/ampache

View on GitHub
src/Module/Util/Waveform.php

Summary

Maintainability
D
2 days
Test Coverage

Function get has a Cognitive Complexity of 72 (exceeds 5 allowed). Consider refactoring.
Open

    public static function get($media, string $object_type): ?string
    {
        $waveform = null;

        if ($media->isNew() === false) {
Severity: Minor
Found in src/Module/Util/Waveform.php - About 1 day 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 create_waveform has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

    protected static function create_waveform($filename): ?string
    {
        if (!file_exists($filename)) {
            debug_event(self::class, 'File ' . $filename . ' doesn\'t exists', 1);

Severity: Minor
Found in src/Module/Util/Waveform.php - About 3 hrs 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 class Waveform has an overall complexity of 50 which is very high. The configured complexity threshold is 50.
Open

class Waveform
{
    public $id;

    /**
Severity: Minor
Found in src/Module/Util/Waveform.php by phpmd

Avoid deeply nested control flow statements.
Open

                                if (!$tmpfile) {
                                    return null;
                                }
Severity: Major
Found in src/Module/Util/Waveform.php - About 45 mins to fix

    Avoid deeply nested control flow statements.
    Open

                                    if (!is_resource($filepointer)) {
                                        debug_event(self::class, "Failed to open " . $media->file . " for waveform.", 3);
    
                                        return null;
                                    }
    Severity: Major
    Found in src/Module/Util/Waveform.php - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                                      if (unlink($tmpfile) === false) {
                                          throw new RuntimeException('The file handle ' . $tmpfile . ' could not be unlinked');
                                      }
      Severity: Major
      Found in src/Module/Util/Waveform.php - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                            if ($buf = fread($filepointer, 2048)) {
                                                fwrite($tfp, $buf);
                                            }
        Severity: Major
        Found in src/Module/Util/Waveform.php - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                          if (!is_resource($tfp)) {
                                              debug_event(self::class, "Failed to open " . $tmpfile, 3);
          
                                              return null;
                                          }
          Severity: Major
          Found in src/Module/Util/Waveform.php - About 45 mins to fix

            The method create_waveform() has an NPath complexity of 1296. The configured NPath complexity threshold is 200.
            Open

                protected static function create_waveform($filename): ?string
                {
                    if (!file_exists($filename)) {
                        debug_event(self::class, 'File ' . $filename . ' doesn\'t exists', 1);
            
            
            Severity: Minor
            Found in src/Module/Util/Waveform.php by phpmd

            NPathComplexity

            Since: 0.1

            The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

            Example

            class Foo {
                function bar() {
                    // lots of complicated code
                }
            }

            Source https://phpmd.org/rules/codesize.html#npathcomplexity

            The method get() has an NPath complexity of 333. The configured NPath complexity threshold is 200.
            Open

                public static function get($media, string $object_type): ?string
                {
                    $waveform = null;
            
                    if ($media->isNew() === false) {
            Severity: Minor
            Found in src/Module/Util/Waveform.php by phpmd

            NPathComplexity

            Since: 0.1

            The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

            Example

            class Foo {
                function bar() {
                    // lots of complicated code
                }
            }

            Source https://phpmd.org/rules/codesize.html#npathcomplexity

            The method create_waveform() has 157 lines of code. Current threshold is set to 100. Avoid really long methods.
            Open

                protected static function create_waveform($filename): ?string
                {
                    if (!file_exists($filename)) {
                        debug_event(self::class, 'File ' . $filename . ' doesn\'t exists', 1);
            
            
            Severity: Minor
            Found in src/Module/Util/Waveform.php by phpmd

            The method get() has a Cyclomatic Complexity of 19. The configured cyclomatic complexity threshold is 10.
            Open

                public static function get($media, string $object_type): ?string
                {
                    $waveform = null;
            
                    if ($media->isNew() === false) {
            Severity: Minor
            Found in src/Module/Util/Waveform.php by phpmd

            CyclomaticComplexity

            Since: 0.1

            Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

            Example

            // Cyclomatic Complexity = 11
            class Foo {
            1   public function example() {
            2       if ($a == $b) {
            3           if ($a1 == $b1) {
                            fiddle();
            4           } elseif ($a2 == $b2) {
                            fiddle();
                        } else {
                            fiddle();
                        }
            5       } elseif ($c == $d) {
            6           while ($c == $d) {
                            fiddle();
                        }
            7        } elseif ($e == $f) {
            8           for ($n = 0; $n < $h; $n++) {
                            fiddle();
                        }
                    } else {
                        switch ($z) {
            9               case 1:
                                fiddle();
                                break;
            10              case 2:
                                fiddle();
                                break;
            11              case 3:
                                fiddle();
                                break;
                            default:
                                fiddle();
                                break;
                        }
                    }
                }
            }

            Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

            The method create_waveform() has a Cyclomatic Complexity of 16. The configured cyclomatic complexity threshold is 10.
            Open

                protected static function create_waveform($filename): ?string
                {
                    if (!file_exists($filename)) {
                        debug_event(self::class, 'File ' . $filename . ' doesn\'t exists', 1);
            
            
            Severity: Minor
            Found in src/Module/Util/Waveform.php by phpmd

            CyclomaticComplexity

            Since: 0.1

            Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

            Example

            // Cyclomatic Complexity = 11
            class Foo {
            1   public function example() {
            2       if ($a == $b) {
            3           if ($a1 == $b1) {
                            fiddle();
            4           } elseif ($a2 == $b2) {
                            fiddle();
                        } else {
                            fiddle();
                        }
            5       } elseif ($c == $d) {
            6           while ($c == $d) {
                            fiddle();
                        }
            7        } elseif ($e == $f) {
            8           for ($n = 0; $n < $h; $n++) {
                            fiddle();
                        }
                    } else {
                        switch ($z) {
            9               case 1:
                                fiddle();
                                break;
            10              case 2:
                                fiddle();
                                break;
            11              case 3:
                                fiddle();
                                break;
                            default:
                                fiddle();
                                break;
                        }
                    }
                }
            }

            Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

            This function "create_waveform" has 156 lines, which is greater than the 150 lines authorized. Split it into smaller functions.
            Open

                protected static function create_waveform($filename): ?string
            Severity: Major
            Found in src/Module/Util/Waveform.php by sonar-php

            A function that grows too large tends to aggregate too many responsibilities.

            Such functions inevitably become harder to understand and therefore harder to maintain.

            Above a specific threshold, it is strongly advised to refactor into smaller functions which focus on well-defined tasks.

            Those smaller functions will not only be easier to understand, but also probably easier to test.

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

                public static function get($media, string $object_type): ?string
            Severity: Critical
            Found in src/Module/Util/Waveform.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

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

                public static function get($media, string $object_type): ?string
            Severity: Major
            Found in src/Module/Util/Waveform.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;
            }
            

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

                protected static function create_waveform($filename): ?string
            Severity: Critical
            Found in src/Module/Util/Waveform.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

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

                protected static function create_waveform($filename): ?string
            Severity: Major
            Found in src/Module/Util/Waveform.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;
            }
            

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

                                    } else {
                                        debug_event(self::class, 'tmp_dir_path setting required for waveform.', 3);
                                    }
            Severity: Minor
            Found in src/Module/Util/Waveform.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 get uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
            Open

                        } else {
                            $waveform = $media->waveform;
                        }
            Severity: Minor
            Found in src/Module/Util/Waveform.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 get uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
            Open

                                } else {
                                    self::save_to_db($media->id, $object_type, $waveform);
                                }
            Severity: Minor
            Found in src/Module/Util/Waveform.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 create_waveform uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
            Open

                        } else {
                            // skip this one due to lack of detail
                            fseek($handle, (int)($ratio + $byte), SEEK_CUR);
                        }
            Severity: Minor
            Found in src/Module/Util/Waveform.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 create_waveform uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
            Open

                    } else {
                        imagepng($img);
                    }
            Severity: Minor
            Found in src/Module/Util/Waveform.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 get uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
            Open

                                        } else {
                                            debug_event(self::class, 'transcode setting to wav required for waveform.', 3);
                                        }
            Severity: Minor
            Found in src/Module/Util/Waveform.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 create_waveform uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
            Open

                                    } else {
                                        $temp = 128;
                                    }
            Severity: Minor
            Found in src/Module/Util/Waveform.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

            Avoid assigning values to variables in if clauses and the like (line '122', column '41').
            Open

                public static function get($media, string $object_type): ?string
                {
                    $waveform = null;
            
                    if ($media->isNew() === false) {
            Severity: Minor
            Found in src/Module/Util/Waveform.php by phpmd

            IfStatementAssignment

            Since: 2.7.0

            Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

            Example

            class Foo
            {
                public function bar($flag)
                {
                    if ($foo = 'bar') { // possible typo
                        // ...
                    }
                    if ($baz = 0) { // always false
                        // ...
                    }
                }
            }

            Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

            Take the required action to fix the issue indicated by this "FIXME" comment.
            Open

                    // FIXME remove...
            Severity: Major
            Found in src/Module/Util/Waveform.php by sonar-php

            FIXME tags are commonly used to mark places where a bug is suspected, but which the developer wants to deal with later.

            Sometimes the developer will not have the time or will simply forget to get back to that tag.

            This rule is meant to track those tags and to ensure that they do not go unnoticed.

            Noncompliant Code Example

            function divide($numerator, $denominator) {
              return $numerator / $denominator;              // FIXME denominator value might be  0
            }
            

            See

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

                                                throw new RuntimeException('The file handle ' . $tmpfile . ' could not be unlinked');
            Severity: Major
            Found in src/Module/Util/Waveform.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

            FIXME found
            Open

                    // FIXME remove...
            Severity: Minor
            Found in src/Module/Util/Waveform.php by fixme

            Call to deprecated function \debug_event() defined at /code/src/Config/functions.php:651
            Open

                                            debug_event(self::class, 'transcode setting to wav required for waveform.', 3);
            Severity: Minor
            Found in src/Module/Util/Waveform.php by phan

            Call to deprecated function \debug_event() defined at /code/src/Config/functions.php:651
            Open

                                                debug_event(self::class, "Failed to open " . $media->file . " for waveform.", 3);
            Severity: Minor
            Found in src/Module/Util/Waveform.php by phan

            Argument 1 (data) is null but \bin2hex() takes string
            Open

                    $byte2 = hexdec(bin2hex($byte2));
            Severity: Minor
            Found in src/Module/Util/Waveform.php by phan

            Call to deprecated function \debug_event() defined at /code/src/Config/functions.php:651
            Open

                        debug_event(self::class, 'Cannot create image.', 1);
            Severity: Minor
            Found in src/Module/Util/Waveform.php by phan

            Invalid offset 1 of array type array{0:false|string}
            Open

                                    $temp = chr((ord($bytes[1]) & 127) + $temp);
            Severity: Minor
            Found in src/Module/Util/Waveform.php by phan

            Call to method format from undeclared class \Ampache\Repository\Model\Song
            Open

                        $media->format();
            Severity: Critical
            Found in src/Module/Util/Waveform.php by phan

            Reference to instance property file from undeclared class \Ampache\Repository\Model\Song
            Open

                                    $waveform = self::create_waveform($media->file);
            Severity: Minor
            Found in src/Module/Util/Waveform.php by phan

            Call to deprecated function \debug_event() defined at /code/src/Config/functions.php:651
            Open

                        debug_event(self::class, 'local_metadata_dir setting is required to store waveform on disk.', 1);
            Severity: Minor
            Found in src/Module/Util/Waveform.php by phan

            Call to deprecated function \debug_event() defined at /code/src/Config/functions.php:651
            Open

                        debug_event(self::class, 'Moved: ' . $object_id . ' from: {' . $old_target_file . '}' . ' to: {' . $path . $object_id . ".png" . '}', 5);
            Severity: Minor
            Found in src/Module/Util/Waveform.php by phan

            Call to deprecated function \debug_event() defined at /code/src/Config/functions.php:651
            Open

                        debug_event(self::class, 'File ' . $filename . ' doesn\'t exists', 1);
            Severity: Minor
            Found in src/Module/Util/Waveform.php by phan

            Argument 1 (character) is null but \ord() takes string
            Open

                                    $temp = chr((ord($bytes[1]) & 127) + $temp);
            Severity: Minor
            Found in src/Module/Util/Waveform.php by phan

            Reference to instance property id from undeclared class \Ampache\Repository\Model\Song
            Open

                                    self::save_to_db($media->id, $object_type, $waveform);
            Severity: Minor
            Found in src/Module/Util/Waveform.php by phan

            Call to method write from undeclared class \Ampache\Module\System\Dba
            Open

                    return Dba::write($sql, array($waveform, $object_id));
            Severity: Critical
            Found in src/Module/Util/Waveform.php by phan

            Call to method create_from_id from undeclared class \Ampache\Repository\Model\Catalog
            Open

                            $catalog = Catalog::create_from_id($media->catalog);
            Severity: Critical
            Found in src/Module/Util/Waveform.php by phan

            Call to deprecated function \debug_event() defined at /code/src/Config/functions.php:651
            Open

                                                debug_event(self::class, "Failed to open " . $tmpfile, 3);
            Severity: Minor
            Found in src/Module/Util/Waveform.php by phan

            Call to deprecated function \debug_event() defined at /code/src/Config/functions.php:651
            Open

                        debug_event(self::class, 'get_from_file ' . $file, 5);
            Severity: Minor
            Found in src/Module/Util/Waveform.php by phan

            Invalid offset 1 of array type array{0:false|string}
            Open

                                    if (ord($bytes[1]) & 128) {
            Severity: Minor
            Found in src/Module/Util/Waveform.php by phan

            Reference to instance property id from undeclared class \Ampache\Repository\Model\Song
            Open

                            $waveform = self::get_from_file($media->id, $object_type);
            Severity: Minor
            Found in src/Module/Util/Waveform.php by phan

            Call to deprecated function \debug_event() defined at /code/src/Config/functions.php:651
            Open

                        debug_event(__CLASS__, 'GD extension must be loaded', 1);
            Severity: Minor
            Found in src/Module/Util/Waveform.php by phan

            Call to deprecated function \debug_event() defined at /code/src/Config/functions.php:651
            Open

                                        debug_event(self::class, 'tmp_dir_path setting required for waveform.', 3);
            Severity: Minor
            Found in src/Module/Util/Waveform.php by phan

            Reference to instance property file from undeclared class \Ampache\Repository\Model\Song
            Open

                                } elseif ($media->file !== null) {
            Severity: Minor
            Found in src/Module/Util/Waveform.php by phan

            Reference to instance property waveform from undeclared class \Ampache\Repository\Model\Song
            Open

                            $waveform = $media->waveform;
            Severity: Minor
            Found in src/Module/Util/Waveform.php by phan

            Reference to instance property file from undeclared class \Ampache\Repository\Model\Song
            Open

                                                debug_event(self::class, "Failed to open " . $media->file . " for waveform.", 3);
            Severity: Minor
            Found in src/Module/Util/Waveform.php by phan

            Parameter $media has undeclared type \Ampache\Repository\Model\Song
            Open

                public static function get($media, string $object_type): ?string
            Severity: Minor
            Found in src/Module/Util/Waveform.php by phan

            Reference to instance property type from undeclared class \Ampache\Repository\Model\Song
            Open

                                if ($media->type != $transcode_to) {
            Severity: Minor
            Found in src/Module/Util/Waveform.php by phan

            Invalid offset 1 of array type array{0:false|string}
            Open

                                    $data = self::findValues($bytes[0], $bytes[1]);
            Severity: Minor
            Found in src/Module/Util/Waveform.php by phan

            Call to method get_stream_types from undeclared class \Ampache\Repository\Model\Song
            Open

                                $valid_types   = $media->get_stream_types();
            Severity: Critical
            Found in src/Module/Util/Waveform.php by phan

            Call to method get_transcode_settings from undeclared class \Ampache\Repository\Model\Song
            Open

                                            $transcode_settings = $media->get_transcode_settings($transcode_to);
            Severity: Critical
            Found in src/Module/Util/Waveform.php by phan

            Parameter $media has undeclared type \Ampache\Repository\Model\Podcast_Episode
            Open

                public static function get($media, string $object_type): ?string
            Severity: Minor
            Found in src/Module/Util/Waveform.php by phan

            Reference to instance property id from undeclared class \Ampache\Repository\Model\Song
            Open

                                    self::save_to_file($media->id, $object_type, $waveform);
            Severity: Minor
            Found in src/Module/Util/Waveform.php by phan

            Call to method isNew from undeclared class \Ampache\Repository\Model\Song
            Open

                    if ($media->isNew() === false) {
            Severity: Critical
            Found in src/Module/Util/Waveform.php by phan

            Reference to instance property catalog from undeclared class \Ampache\Repository\Model\Song
            Open

                            $catalog = Catalog::create_from_id($media->catalog);
            Severity: Minor
            Found in src/Module/Util/Waveform.php by phan

            Argument 1 (character) is null but \ord() takes string
            Open

                                    if (ord($bytes[1]) & 128) {
            Severity: Minor
            Found in src/Module/Util/Waveform.php by phan

            The parameter $object_id is not named in camelCase.
            Open

                public static function get_filepath($object_id, $object_type)
                {
                    $path = AmpConfig::get('local_metadata_dir');
                    if (!$path) {
                        debug_event(self::class, 'local_metadata_dir setting is required to store waveform on disk.', 1);
            Severity: Minor
            Found in src/Module/Util/Waveform.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 $object_id is not named in camelCase.
            Open

                protected static function save_to_db($object_id, $object_type, $waveform)
                {
                    $sql = ($object_type == 'podcast_episode')
                        ? "UPDATE `podcast_episode` SET `waveform` = ? WHERE `id` = ?"
                        : "UPDATE `song_data` SET `waveform` = ? WHERE `song_id` = ?";
            Severity: Minor
            Found in src/Module/Util/Waveform.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 $object_id is not named in camelCase.
            Open

                public static function get_from_file($object_id, $object_type): ?string
                {
                    $file = self::get_filepath($object_id, $object_type);
                    if ($file !== false && file_exists($file)) {
                        debug_event(self::class, 'get_from_file ' . $file, 5);
            Severity: Minor
            Found in src/Module/Util/Waveform.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 $object_type is not named in camelCase.
            Open

                public static function get($media, string $object_type): ?string
                {
                    $waveform = null;
            
                    if ($media->isNew() === false) {
            Severity: Minor
            Found in src/Module/Util/Waveform.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 $object_type is not named in camelCase.
            Open

                public static function save_to_file($object_id, $object_type, $waveform)
                {
                    $file = self::get_filepath($object_id, $object_type);
            
                    return file_put_contents($file, $waveform);
            Severity: Minor
            Found in src/Module/Util/Waveform.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 $object_type is not named in camelCase.
            Open

                public static function get_filepath($object_id, $object_type)
                {
                    $path = AmpConfig::get('local_metadata_dir');
                    if (!$path) {
                        debug_event(self::class, 'local_metadata_dir setting is required to store waveform on disk.', 1);
            Severity: Minor
            Found in src/Module/Util/Waveform.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

            Avoid variables with short names like $id. Configured minimum length is 3.
            Open

                public $id;
            Severity: Minor
            Found in src/Module/Util/Waveform.php by phpmd

            ShortVariable

            Since: 0.2

            Detects when a field, local, or parameter has a very short name.

            Example

            class Something {
                private $q = 15; // VIOLATION - Field
                public static function main( array $as ) { // VIOLATION - Formal
                    $r = 20 + $this->q; // VIOLATION - Local
                    for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                        $r += $this->q;
                    }
                }
            }

            Source https://phpmd.org/rules/naming.html#shortvariable

            The parameter $object_type is not named in camelCase.
            Open

                public static function get_from_file($object_id, $object_type): ?string
                {
                    $file = self::get_filepath($object_id, $object_type);
                    if ($file !== false && file_exists($file)) {
                        debug_event(self::class, 'get_from_file ' . $file, 5);
            Severity: Minor
            Found in src/Module/Util/Waveform.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 $object_id is not named in camelCase.
            Open

                public static function save_to_file($object_id, $object_type, $waveform)
                {
                    $file = self::get_filepath($object_id, $object_type);
            
                    return file_put_contents($file, $waveform);
            Severity: Minor
            Found in src/Module/Util/Waveform.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 $object_type is not named in camelCase.
            Open

                protected static function save_to_db($object_id, $object_type, $waveform)
                {
                    $sql = ($object_type == 'podcast_episode')
                        ? "UPDATE `podcast_episode` SET `waveform` = ? WHERE `id` = ?"
                        : "UPDATE `song_data` SET `waveform` = ? WHERE `song_id` = ?";
            Severity: Minor
            Found in src/Module/Util/Waveform.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

            There are no issues that match your filters.

            Category
            Status