netglue/prismic-php-kit

View on GitHub
src/Prismic/Api.php

Summary

Maintainability
C
1 day
Test Coverage
A
90%

__construct accesses the super-global variable $_COOKIE.
Open

    private function __construct()
    {
        $this->requestCookies = $_COOKIE ?? [];
    }
Severity: Minor
Found in src/Prismic/Api.php by phpmd

Superglobals

Since: 0.2

Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.

Example

class Foo {
    public function bar() {
        $name = $_POST['foo'];
    }
}

Source

Api has 37 functions (exceeds 20 allowed). Consider refactoring.
Open

class Api
{

    /**
     * Kit version number
Severity: Minor
Found in src/Prismic/Api.php - About 4 hrs to fix

    File Api.php has 347 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    declare(strict_types=1);
    
    namespace Prismic;
    
    
    Severity: Minor
    Found in src/Prismic/Api.php - About 4 hrs to fix

      The class Api has 12 public methods. Consider refactoring Api to keep number of public methods under 10.
      Open

      class Api
      {
      
          /**
           * Kit version number
      Severity: Minor
      Found in src/Prismic/Api.php by phpmd

      TooManyPublicMethods

      Since: 0.1

      A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

      By default it ignores methods starting with 'get' or 'set'.

      Example

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

      The class Api has an overall complexity of 70 which is very high. The configured complexity threshold is 50.
      Open

      class Api
      {
      
          /**
           * Kit version number
      Severity: Minor
      Found in src/Prismic/Api.php by phpmd

      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

      The class Api has a coupling between objects value of 30. Consider to reduce the number of dependencies under 13.
      Open

      class Api
      {
      
          /**
           * Kit version number
      Severity: Minor
      Found in src/Prismic/Api.php by phpmd

      CouplingBetweenObjects

      Since: 1.1.0

      A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

      Example

      class Foo {
          /**
           * @var \foo\bar\X
           */
          private $x = null;
      
          /**
           * @var \foo\bar\Y
           */
          private $y = null;
      
          /**
           * @var \foo\bar\Z
           */
          private $z = null;
      
          public function setFoo(\Foo $foo) {}
          public function setBar(\Bar $bar) {}
          public function setBaz(\Baz $baz) {}
      
          /**
           * @return \SplObjectStorage
           * @throws \OutOfRangeException
           * @throws \InvalidArgumentException
           * @throws \ErrorException
           */
          public function process(\Iterator $it) {}
      
          // ...
      }

      Source https://phpmd.org/rules/design.html#couplingbetweenobjects

      Avoid using static access to class '\Prismic\Exception\ExpiredPreviewTokenException' in method 'previewSession'.
      Open

                  if ($apiResponse && Exception\ExpiredPreviewTokenException::isTokenExpiryResponse($apiResponse)) {
      Severity: Minor
      Found in src/Prismic/Api.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

      Source https://phpmd.org/rules/cleancode.html#staticaccess

      Avoid using static access to class 'Prismic\ApiData' in method 'getApiData'.
      Open

                  return ApiData::withJsonString((string) $response->getBody());
      Severity: Minor
      Found in src/Prismic/Api.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

      Source https://phpmd.org/rules/cleancode.html#staticaccess

      Avoid using static access to class '\Prismic\Exception\RequestFailureException' in method 'previewSession'.
      Open

                  throw Exception\RequestFailureException::fromGuzzleException($requestException);
      Severity: Minor
      Found in src/Prismic/Api.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

      Source https://phpmd.org/rules/cleancode.html#staticaccess

      Avoid using static access to class '\Prismic\Exception\RequestFailureException' in method 'previewSession'.
      Open

                  throw Exception\RequestFailureException::fromGuzzleException($exception);
      Severity: Minor
      Found in src/Prismic/Api.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

      Source https://phpmd.org/rules/cleancode.html#staticaccess

      Avoid using static access to class '\GuzzleHttp\Psr7\Uri' in method 'apiDataUrl'.
      Open

                  ? Uri::withQueryValue($url, 'access_token', $this->accessToken)
      Severity: Minor
      Found in src/Prismic/Api.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

      Source https://phpmd.org/rules/cleancode.html#staticaccess

      Avoid using static access to class 'Prismic\Form' in method 'forms'.
      Open

                      $formObject = Form::withJsonObject($jsonObject);
      Severity: Minor
      Found in src/Prismic/Api.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

      Source https://phpmd.org/rules/cleancode.html#staticaccess

      Avoid using static access to class 'Prismic\Predicates' in method 'getSingle'.
      Open

              return $this->queryFirst(Predicates::at('document.type', $type), $options);
      Severity: Minor
      Found in src/Prismic/Api.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

      Source https://phpmd.org/rules/cleancode.html#staticaccess

      Avoid using static access to class 'Prismic\Predicates' in method 'getByUid'.
      Open

                  Predicates::at(sprintf(
                      'my.%s.uid',
                      $type
                  ), $uid),
      Severity: Minor
      Found in src/Prismic/Api.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

      Source https://phpmd.org/rules/cleancode.html#staticaccess

      Avoid using static access to class 'Prismic\Predicates' in method 'getByIds'.
      Open

              return $this->query(Predicates::in('document.id', $ids), $options);
      Severity: Minor
      Found in src/Prismic/Api.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

      Source https://phpmd.org/rules/cleancode.html#staticaccess

      Avoid using static access to class 'Prismic\Cache\DefaultCache' in method 'get'.
      Open

              $api->cache = $cache ?? Cache\DefaultCache::factory();
      Severity: Minor
      Found in src/Prismic/Api.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

      Source https://phpmd.org/rules/cleancode.html#staticaccess

      Avoid using static access to class '\Prismic\Exception\RequestFailureException' in method 'getApiData'.
      Open

                  throw Exception\RequestFailureException::fromGuzzleException($guzzleException);
      Severity: Minor
      Found in src/Prismic/Api.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

      Source https://phpmd.org/rules/cleancode.html#staticaccess

      Avoid using static access to class '\Prismic\Exception\ExpiredPreviewTokenException' in method 'previewSession'.
      Open

                      throw Exception\ExpiredPreviewTokenException::fromResponse($apiResponse);
      Severity: Minor
      Found in src/Prismic/Api.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

      Source https://phpmd.org/rules/cleancode.html#staticaccess

      Avoid using static access to class 'Prismic\Predicates' in method 'getById'.
      Open

              return $this->queryFirst(Predicates::at('document.id', $id), $options);
      Severity: Minor
      Found in src/Prismic/Api.php by phpmd

      StaticAccess

      Since: 1.4.0

      Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

      Example

      class Foo
      {
          public function bar()
          {
              Bar::baz();
          }
      }

      Source https://phpmd.org/rules/cleancode.html#staticaccess

      Call to method set from undeclared class \Psr\Cache\CacheItemInterface
      Open

              $cacheItem->set($data);
      Severity: Critical
      Found in src/Prismic/Api.php by phan

      Return type of getCache() is undeclared type \Psr\Cache\CacheItemPoolInterface
      Open

          public function getCache() : CacheItemPoolInterface
      Severity: Minor
      Found in src/Prismic/Api.php by phan

      @throws annotation of getSingle has suspicious interface type \Prismic\Exception\exceptioninterface for an @throws annotation, expected class (PHP allows interfaces to be caught, so this might be intentional)
      Open

          public function getSingle(string $type, array $options = []) :? DocumentInterface
      Severity: Minor
      Found in src/Prismic/Api.php by phan

      @throws annotation of getByIds has suspicious interface type \Prismic\Exception\exceptioninterface for an @throws annotation, expected class (PHP allows interfaces to be caught, so this might be intentional)
      Open

          public function getByIds(array $ids, array $options = []) : Response
      Severity: Minor
      Found in src/Prismic/Api.php by phan

      Return type of apiDataCacheItem() is undeclared type \Psr\Cache\CacheItemInterface
      Open

          private function apiDataCacheItem() : CacheItemInterface
      Severity: Minor
      Found in src/Prismic/Api.php by phan

      Catching undeclared class \GuzzleHttp\Exception\GuzzleException
      Open

              } catch (GuzzleException $guzzleException) {
      Severity: Critical
      Found in src/Prismic/Api.php by phan

      Call to method request from undeclared class \GuzzleHttp\ClientInterface
      Open

                  $response = $this->httpClient->request('GET', $token);
      Severity: Critical
      Found in src/Prismic/Api.php by phan

      Catching undeclared class \Psr\Cache\CacheException
      Open

              } catch (CacheException $cacheException) {
      Severity: Critical
      Found in src/Prismic/Api.php by phan

      Call to method request from undeclared class \GuzzleHttp\ClientInterface
      Open

                  $response = $this->httpClient->request('GET', $url);
      Severity: Critical
      Found in src/Prismic/Api.php by phan

      Parameter $cache has undeclared type ?\Psr\Cache\CacheItemPoolInterface
      Open

          public static function get(
      Severity: Minor
      Found in src/Prismic/Api.php by phan

      Parameter $httpClient has undeclared type ?\GuzzleHttp\ClientInterface
      Open

          public static function get(
      Severity: Minor
      Found in src/Prismic/Api.php by phan

      Call to method getResponse from undeclared class \GuzzleHttp\Exception\RequestException
      Open

                  $apiResponse = $requestException->getResponse();
      Severity: Critical
      Found in src/Prismic/Api.php by phan

      Property \Prismic\Api->cache has undeclared type \Psr\Cache\CacheItemPoolInterface
      Open

          private $cache;
      Severity: Minor
      Found in src/Prismic/Api.php by phan

      Call to method withQueryValue from undeclared class \GuzzleHttp\Psr7\Uri
      Open

                  ? Uri::withQueryValue($url, 'access_token', $this->accessToken)
      Severity: Critical
      Found in src/Prismic/Api.php by phan

      Catching undeclared class \GuzzleHttp\Exception\RequestException
      Open

              } catch (RequestException $requestException) {
      Severity: Critical
      Found in src/Prismic/Api.php by phan

      Argument 1 (e) is \GuzzleHttp\Exception\RequestException|\Throwable but \Prismic\Exception\RequestFailureException::fromGuzzleException() takes \GuzzleHttp\Exception\GuzzleException defined at /code/src/Prismic/Exception/RequestFailureException.php:25
      Open

                  throw Exception\RequestFailureException::fromGuzzleException($requestException);
      Severity: Minor
      Found in src/Prismic/Api.php by phan

      Catching undeclared class \GuzzleHttp\Exception\GuzzleException
      Open

              } catch (GuzzleException $exception) {
      Severity: Critical
      Found in src/Prismic/Api.php by phan

      Call to method isHit from undeclared class \Psr\Cache\CacheItemInterface
      Open

              if ($cacheItem->isHit()) {
      Severity: Critical
      Found in src/Prismic/Api.php by phan

      Property \Prismic\Api->httpClient has undeclared type \GuzzleHttp\ClientInterface
      Open

          private $httpClient;
      Severity: Minor
      Found in src/Prismic/Api.php by phan

      Call to method getItem from undeclared class \Psr\Cache\CacheItemPoolInterface
      Open

                  return $this->cache->getItem($key);
      Severity: Critical
      Found in src/Prismic/Api.php by phan

      @throws annotation of getById has suspicious interface type \Prismic\Exception\exceptioninterface for an @throws annotation, expected class (PHP allows interfaces to be caught, so this might be intentional)
      Open

          public function getById(string $id, array $options = []) :? DocumentInterface
      Severity: Minor
      Found in src/Prismic/Api.php by phan

      Call to method __construct from undeclared class \GuzzleHttp\Client
      Open

              $api->httpClient = $httpClient ?? new Client();
      Severity: Critical
      Found in src/Prismic/Api.php by phan

      Return type of getHttpClient() is undeclared type \GuzzleHttp\ClientInterface
      Open

          public function getHttpClient() : ClientInterface
      Severity: Minor
      Found in src/Prismic/Api.php by phan

      Doc-block of $accessToken in get is phpdoc param type string which is not a permitted replacement of the nullable param type ?string declared in the signature ('?T' should be documented as 'T|null' or '?T')
      Open

           * @param string $accessToken A permanent access token to use if your repository API is set to private
      Severity: Minor
      Found in src/Prismic/Api.php by phan

      @throws annotation of previewSession has suspicious interface type \Prismic\Exception\exceptioninterface for an @throws annotation, expected class (PHP allows interfaces to be caught, so this might be intentional)
      Open

          public function previewSession(string $token, string $defaultUrl) : string
      Severity: Minor
      Found in src/Prismic/Api.php by phan

      Doc-block of $cache in get is phpdoc param type \Psr\Cache\CacheItemPoolInterface which is not a permitted replacement of the nullable param type ?\Psr\Cache\CacheItemPoolInterface declared in the signature ('?T' should be documented as 'T|null' or '?T')
      Open

           * @param CacheItemPoolInterface $cache Cache implementation
      Severity: Minor
      Found in src/Prismic/Api.php by phan

      Call to method __construct from undeclared class \GuzzleHttp\Psr7\Uri
      Open

              $url = new Uri($this->url);
      Severity: Critical
      Found in src/Prismic/Api.php by phan

      Call to method get from undeclared class \Psr\Cache\CacheItemInterface
      Open

                  $data = $cacheItem->get();
      Severity: Critical
      Found in src/Prismic/Api.php by phan

      @throws annotation of queryFirst has suspicious interface type \Prismic\Exception\exceptioninterface for an @throws annotation, expected class (PHP allows interfaces to be caught, so this might be intentional)
      Open

          public function queryFirst($q, array $options = []) :? DocumentInterface
      Severity: Minor
      Found in src/Prismic/Api.php by phan

      @throws annotation of getByUid has suspicious interface type \Prismic\Exception\exceptioninterface for an @throws annotation, expected class (PHP allows interfaces to be caught, so this might be intentional)
      Open

          public function getByUid(string $type, string $uid, array $options = []) :? DocumentInterface
      Severity: Minor
      Found in src/Prismic/Api.php by phan

      Doc-block of $httpClient in get is phpdoc param type \GuzzleHttp\ClientInterface which is not a permitted replacement of the nullable param type ?\GuzzleHttp\ClientInterface declared in the signature ('?T' should be documented as 'T|null' or '?T')
      Open

           * @param ClientInterface $httpClient Custom Guzzle http client
      Severity: Minor
      Found in src/Prismic/Api.php by phan

      Call to method save from undeclared class \Psr\Cache\CacheItemPoolInterface
      Open

              $this->cache->save($cacheItem);
      Severity: Critical
      Found in src/Prismic/Api.php by phan

      @throws annotation of query has suspicious interface type \Prismic\Exception\exceptioninterface for an @throws annotation, expected class (PHP allows interfaces to be caught, so this might be intentional)
      Open

          public function query($q, array $options = []) : Response
      Severity: Minor
      Found in src/Prismic/Api.php by phan

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

          public function query($q, array $options = []) : Response
      Severity: Minor
      Found in src/Prismic/Api.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 $q. Configured minimum length is 3.
      Open

          public function queryFirst($q, array $options = []) :? DocumentInterface
      Severity: Minor
      Found in src/Prismic/Api.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

          public function getById(string $id, array $options = []) :? DocumentInterface
      Severity: Minor
      Found in src/Prismic/Api.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

      There are no issues that match your filters.

      Category
      Status