__construct accesses the super-global variable $_COOKIE. Open
private function __construct()
{
$this->requestCookies = $_COOKIE ?? [];
}
- Read upRead up
- Exclude checks
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
File Api.php
has 347 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
declare(strict_types=1);
namespace Prismic;
The class Api has 12 public methods. Consider refactoring Api to keep number of public methods under 10. Open
class Api
{
/**
* Kit version number
- Read upRead up
- Exclude checks
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
- Exclude checks
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);
- Read upRead up
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
- Read upRead up
- Exclude checks
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)) {
- Read upRead up
- Exclude checks
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());
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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)
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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),
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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();
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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);
- Read upRead up
- Exclude checks
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);
- Exclude checks
Return type of getCache()
is undeclared type \Psr\Cache\CacheItemPoolInterface
Open
public function getCache() : CacheItemPoolInterface
- Exclude checks
@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
- Exclude checks
@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
- Exclude checks
Return type of apiDataCacheItem()
is undeclared type \Psr\Cache\CacheItemInterface
Open
private function apiDataCacheItem() : CacheItemInterface
- Exclude checks
Catching undeclared class \GuzzleHttp\Exception\GuzzleException
Open
} catch (GuzzleException $guzzleException) {
- Exclude checks
Call to method request
from undeclared class \GuzzleHttp\ClientInterface
Open
$response = $this->httpClient->request('GET', $token);
- Exclude checks
Catching undeclared class \Psr\Cache\CacheException
Open
} catch (CacheException $cacheException) {
- Exclude checks
Call to method request
from undeclared class \GuzzleHttp\ClientInterface
Open
$response = $this->httpClient->request('GET', $url);
- Exclude checks
Parameter $cache
has undeclared type ?\Psr\Cache\CacheItemPoolInterface
Open
public static function get(
- Exclude checks
Parameter $httpClient
has undeclared type ?\GuzzleHttp\ClientInterface
Open
public static function get(
- Exclude checks
Call to method getResponse
from undeclared class \GuzzleHttp\Exception\RequestException
Open
$apiResponse = $requestException->getResponse();
- Exclude checks
Property \Prismic\Api->cache
has undeclared type \Psr\Cache\CacheItemPoolInterface
Open
private $cache;
- Exclude checks
Call to method withQueryValue
from undeclared class \GuzzleHttp\Psr7\Uri
Open
? Uri::withQueryValue($url, 'access_token', $this->accessToken)
- Exclude checks
Catching undeclared class \GuzzleHttp\Exception\RequestException
Open
} catch (RequestException $requestException) {
- Exclude checks
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);
- Exclude checks
Catching undeclared class \GuzzleHttp\Exception\GuzzleException
Open
} catch (GuzzleException $exception) {
- Exclude checks
Call to method isHit
from undeclared class \Psr\Cache\CacheItemInterface
Open
if ($cacheItem->isHit()) {
- Exclude checks
Property \Prismic\Api->httpClient
has undeclared type \GuzzleHttp\ClientInterface
Open
private $httpClient;
- Exclude checks
Call to method getItem
from undeclared class \Psr\Cache\CacheItemPoolInterface
Open
return $this->cache->getItem($key);
- Exclude checks
@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
- Exclude checks
Call to method __construct
from undeclared class \GuzzleHttp\Client
Open
$api->httpClient = $httpClient ?? new Client();
- Exclude checks
Return type of getHttpClient()
is undeclared type \GuzzleHttp\ClientInterface
Open
public function getHttpClient() : ClientInterface
- Exclude checks
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
- Exclude checks
@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
- Exclude checks
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
- Exclude checks
Call to method __construct
from undeclared class \GuzzleHttp\Psr7\Uri
Open
$url = new Uri($this->url);
- Exclude checks
Call to method get
from undeclared class \Psr\Cache\CacheItemInterface
Open
$data = $cacheItem->get();
- Exclude checks
@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
- Exclude checks
@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
- Exclude checks
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
- Exclude checks
Call to method save
from undeclared class \Psr\Cache\CacheItemPoolInterface
Open
$this->cache->save($cacheItem);
- Exclude checks
@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
- Exclude checks
Avoid variables with short names like $q. Configured minimum length is 3. Open
public function query($q, array $options = []) : Response
- Read upRead up
- Exclude checks
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
- Read upRead up
- Exclude checks
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
- Read upRead up
- Exclude checks
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;
}
}
}