netglue/prismic-php-kit

View on GitHub

Showing 316 of 316 total issues

Function v1Factory has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    private function v1Factory(string $key, $value, LinkResolver $linkResolver) : void
    {
        $fragment = null;
        switch ($value->type) {
            case 'Image':
Severity: Minor
Found in src/Prismic/Document/Fragment/FragmentCollection.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 submit has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function submit() : Response
    {
        if ($this->form->getMethod() !== 'GET' ||
            $this->form->getEnctype() !== 'application/x-www-form-urlencoded' ||
            ! $this->form->getAction()
Severity: Minor
Found in src/Prismic/SearchForm.php - About 1 hr to fix

    Avoid using short method names like Predicates::in(). The configured minimum method name length is 3.
    Open

        public static function in(string $fragment, array $values) : Predicate
        {
            return new SimplePredicate("in", $fragment, [$values]);
        }
    Severity: Minor
    Found in src/Prismic/Predicates.php by phpmd

    ShortMethodName

    Since: 0.2

    Detects when very short method names are used.

    Example

    class ShortMethod {
        public function a( $index ) { // Violation
        }
    }

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

    Avoid using short method names like Predicates::gt(). The configured minimum method name length is 3.
    Open

        public static function gt(string $fragment, $upperBound) : Predicate
        {
            if (! \is_numeric($upperBound)) {
                throw new InvalidArgumentException(
                    'Predicates::gt() expects a number as it’s second argument'
    Severity: Minor
    Found in src/Prismic/Predicates.php by phpmd

    ShortMethodName

    Since: 0.2

    Detects when very short method names are used.

    Example

    class ShortMethod {
        public function a( $index ) { // Violation
        }
    }

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

    Avoid using short method names like Predicates::at(). The configured minimum method name length is 3.
    Open

        public static function at(string $fragment, $value) : Predicate
        {
            return new SimplePredicate("at", $fragment, [$value]);
        }
    Severity: Minor
    Found in src/Prismic/Predicates.php by phpmd

    ShortMethodName

    Since: 0.2

    Detects when very short method names are used.

    Example

    class ShortMethod {
        public function a( $index ) { // Violation
        }
    }

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

    Avoid using short method names like SimplePredicate::q(). The configured minimum method name length is 3.
    Open

        public function q() : string
        {
            $query = "[:d = " . $this->name . "(";
            if ($this->name === "similar") {
                $query .= "\"" . $this->fragment . "\"";
    Severity: Minor
    Found in src/Prismic/SimplePredicate.php by phpmd

    ShortMethodName

    Since: 0.2

    Detects when very short method names are used.

    Example

    class ShortMethod {
        public function a( $index ) { // Violation
        }
    }

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

    Avoid using short method names like Predicate::q(). The configured minimum method name length is 3.
    Open

        public function q() : string;
    Severity: Minor
    Found in src/Prismic/Predicate.php by phpmd

    ShortMethodName

    Since: 0.2

    Detects when very short method names are used.

    Example

    class ShortMethod {
        public function a( $index ) { // Violation
        }
    }

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

    Avoid using short method names like Predicates::lt(). The configured minimum method name length is 3.
    Open

        public static function lt(string $fragment, $lowerBound) : Predicate
        {
            if (! \is_numeric($lowerBound)) {
                throw new InvalidArgumentException(
                    'Predicates::lt() expects a number as it’s second argument'
    Severity: Minor
    Found in src/Prismic/Predicates.php by phpmd

    ShortMethodName

    Since: 0.2

    Detects when very short method names are used.

    Example

    class ShortMethod {
        public function a( $index ) { // Violation
        }
    }

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

    Method fromJsonObject has 33 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static function fromJsonObject(stdClass $data, Api $api) : DocumentInterface
        {
            $inst        = new static;
            $inst->api   = $api;
            $inst->id    = $inst->assertRequiredProperty($data, 'id', false);
    Severity: Minor
    Found in src/Prismic/Document.php - About 1 hr to fix

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

          public static function fromJson($value, LinkResolver $linkResolver) : self
          {
              // Type and Label are the same for V1 & V2
              $type    = isset($value->slice_type)
                       ? (string) $value->slice_type
      Severity: Minor
      Found in src/Prismic/Document/Fragment/Slice.php - About 1 hr to fix

        Method __construct has 8 arguments (exceeds 4 allowed). Consider refactoring.
        Open

                array $refs,
                array $bookmarks,
                array $types,
                array $tags,
                array $forms,
        Severity: Major
        Found in src/Prismic/ApiData.php - About 1 hr to fix

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

              public function set(string $key, $value) : self
              {
                  if (empty($key)) {
                      throw new Exception\InvalidArgumentException('Form parameter key must be a non-empty string');
                  }
          Severity: Minor
          Found in src/Prismic/SearchForm.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 previewSession has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              public function previewSession(string $token, string $defaultUrl) : string
              {
                  try {
                      // $token is untrusted input, possibly from a GET request and will be retrieved by the http client
                      $token = $this->validatePreviewToken($token);
          Severity: Minor
          Found in src/Prismic/Api.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

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

              private $id;
          Severity: Minor
          Found in src/Prismic/Ref.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 $oauth_initiate is not named in camelCase.
          Open

              private function __construct(
                  array $refs,
                  array $bookmarks,
                  array $types,
                  array $tags,
          Severity: Minor
          Found in src/Prismic/ApiData.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 $b. Configured minimum length is 3.
          Open

                      list($r, $g, $b) = sscanf($this->value, "#%02x%02x%02x");

          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

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

              private $id;
          Severity: Minor
          Found in src/Prismic/Experiment.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

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

                  private function invalidRepo(Exception\ExceptionInterface $e)
          Severity: Minor
          Found in samples/document-explorer.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

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

              private $id;
          Severity: Minor
          Found in src/Prismic/Variation.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

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

                      list($r, $g, $b) = sscanf($this->value, "#%02x%02x%02x");

          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

          Severity
          Category
          Status
          Source
          Language