pixelfed/pixelfed

View on GitHub
app/Util/Blurhash/Blurhash.php

Summary

Maintainability
C
1 day
Test Coverage

Function encode has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

    public static function encode(array $image, int $components_x = 4, int $components_y = 4, bool $linear = false): string {
        if (($components_x < 1 || $components_x > 9) || ($components_y < 1 || $components_y > 9)) {
            throw new InvalidArgumentException("x and y component counts must be between 1 and 9 inclusive.");
        }
        $height = count($image);
Severity: Minor
Found in app/Util/Blurhash/Blurhash.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

Method encode has 64 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static function encode(array $image, int $components_x = 4, int $components_y = 4, bool $linear = false): string {
        if (($components_x < 1 || $components_x > 9) || ($components_y < 1 || $components_y > 9)) {
            throw new InvalidArgumentException("x and y component counts must be between 1 and 9 inclusive.");
        }
        $height = count($image);
Severity: Major
Found in app/Util/Blurhash/Blurhash.php - About 2 hrs to fix

    Function decode has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

        public static function decode (string $blurhash, int $width, int $height, float $punch = 1.0, bool $linear = false): array {
            if (empty($blurhash) || strlen($blurhash) < 6) {
                throw new InvalidArgumentException("Blurhash string must be at least 6 characters");
            }
    
    
    Severity: Minor
    Found in app/Util/Blurhash/Blurhash.php - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method decode has 43 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static function decode (string $blurhash, int $width, int $height, float $punch = 1.0, bool $linear = false): array {
            if (empty($blurhash) || strlen($blurhash) < 6) {
                throw new InvalidArgumentException("Blurhash string must be at least 6 characters");
            }
    
    
    Severity: Minor
    Found in app/Util/Blurhash/Blurhash.php - About 1 hr to fix

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

          public static function decode (string $blurhash, int $width, int $height, float $punch = 1.0, bool $linear = false): array {
      Severity: Minor
      Found in app/Util/Blurhash/Blurhash.php - About 35 mins to fix

        There are no issues that match your filters.

        Category
        Status