mirror of
https://github.com/getgrav/grav.git
synced 2026-03-24 13:30:11 +01:00
Fixed few phpstan level 3-7 issues
This commit is contained in:
@@ -523,7 +523,7 @@ class Installer
|
||||
|
||||
/**
|
||||
* Returns the last error code of the occurred error
|
||||
* @return int The code of the last error
|
||||
* @return int|string The code of the last error
|
||||
*/
|
||||
public static function lastErrorCode()
|
||||
{
|
||||
|
||||
@@ -38,8 +38,8 @@ trait NestedPropertyTrait
|
||||
public function getNestedProperty($property, $default = null, $separator = null)
|
||||
{
|
||||
$separator = $separator ?: '.';
|
||||
$path = explode($separator, $property);
|
||||
$offset = array_shift($path);
|
||||
$path = explode($separator, $property) ?: [];
|
||||
$offset = array_shift($path) ?? '';
|
||||
|
||||
if (!$this->hasProperty($offset)) {
|
||||
return $default;
|
||||
@@ -81,8 +81,8 @@ trait NestedPropertyTrait
|
||||
public function setNestedProperty($property, $value, $separator = null)
|
||||
{
|
||||
$separator = $separator ?: '.';
|
||||
$path = explode($separator, $property);
|
||||
$offset = array_shift($path);
|
||||
$path = explode($separator, $property) ?: [];
|
||||
$offset = array_shift($path) ?? '';
|
||||
|
||||
if (!$path) {
|
||||
$this->setProperty($offset, $value);
|
||||
@@ -123,8 +123,8 @@ trait NestedPropertyTrait
|
||||
public function unsetNestedProperty($property, $separator = null)
|
||||
{
|
||||
$separator = $separator ?: '.';
|
||||
$path = explode($separator, $property);
|
||||
$offset = array_shift($path);
|
||||
$path = explode($separator, $property) ?: [];
|
||||
$offset = array_shift($path) ?? '';
|
||||
|
||||
if (!$path) {
|
||||
$this->unsetProperty($offset);
|
||||
|
||||
@@ -46,7 +46,7 @@ trait ObjectCollectionTrait
|
||||
|
||||
/**
|
||||
* @param string $property Object property to be matched.
|
||||
* @return array Key/Value pairs of the properties.
|
||||
* @return bool[] Key/Value pairs of the properties.
|
||||
*/
|
||||
public function doHasProperty($property)
|
||||
{
|
||||
@@ -63,7 +63,7 @@ trait ObjectCollectionTrait
|
||||
/**
|
||||
* @param string $property Object property to be fetched.
|
||||
* @param mixed $default Default value if not set.
|
||||
* @return array Key/Value pairs of the properties.
|
||||
* @return mixed[] Key/Value pairs of the properties.
|
||||
*/
|
||||
public function doGetProperty($property, $default = null)
|
||||
{
|
||||
@@ -79,7 +79,7 @@ trait ObjectCollectionTrait
|
||||
|
||||
/**
|
||||
* @param string $property Object property to be updated.
|
||||
* @param string $value New value.
|
||||
* @param mixed $value New value.
|
||||
* @return $this
|
||||
*/
|
||||
public function doSetProperty($property, $value)
|
||||
@@ -108,7 +108,7 @@ trait ObjectCollectionTrait
|
||||
|
||||
/**
|
||||
* @param string $property Object property to be updated.
|
||||
* @param string $default Default value.
|
||||
* @param mixed $default Default value.
|
||||
* @return $this
|
||||
*/
|
||||
public function doDefProperty($property, $default)
|
||||
@@ -124,15 +124,19 @@ trait ObjectCollectionTrait
|
||||
/**
|
||||
* @param string $method Method name.
|
||||
* @param array $arguments List of arguments passed to the function.
|
||||
* @return array Return values.
|
||||
* @return mixed[] Return values.
|
||||
*/
|
||||
public function call($method, array $arguments = [])
|
||||
{
|
||||
$list = [];
|
||||
|
||||
/**
|
||||
* @var string|int $id
|
||||
* @var ObjectInterface $element
|
||||
*/
|
||||
foreach ($this->getIterator() as $id => $element) {
|
||||
$list[$id] = method_exists($element, $method)
|
||||
? \call_user_func_array([$element, $method], $arguments) : null;
|
||||
$callable = method_exists($element, $method) ? [$element, $method] : null;
|
||||
$list[$id] = $callable ? \call_user_func_array($callable, $arguments) : null;
|
||||
}
|
||||
|
||||
return $list;
|
||||
|
||||
@@ -66,7 +66,7 @@ trait ObjectTrait
|
||||
|
||||
/**
|
||||
* @param string $property Object property name.
|
||||
* @return bool True if property has been defined (can be null).
|
||||
* @return bool|bool[] True if property has been defined (can be null).
|
||||
*/
|
||||
public function hasProperty($property)
|
||||
{
|
||||
@@ -76,7 +76,7 @@ trait ObjectTrait
|
||||
/**
|
||||
* @param string $property Object property to be fetched.
|
||||
* @param mixed $default Default value if property has not been set.
|
||||
* @return mixed Property value.
|
||||
* @return mixed|mixed[] Property value.
|
||||
*/
|
||||
public function getProperty($property, $default = null)
|
||||
{
|
||||
|
||||
@@ -10,47 +10,47 @@
|
||||
namespace Grav\Framework\Object\Interfaces;
|
||||
|
||||
/**
|
||||
* Object Interface
|
||||
* Common Interface for both Objects and Collections
|
||||
* @package Grav\Framework\Object
|
||||
*/
|
||||
interface NestedObjectInterface extends ObjectInterface
|
||||
{
|
||||
/**
|
||||
* @param string $property Object property name.
|
||||
* @param string $separator Separator, defaults to '.'
|
||||
* @return bool True if property has been defined (can be null).
|
||||
* @param string $property Object property name.
|
||||
* @param string|null $separator Separator, defaults to '.'
|
||||
* @return bool|bool[] True if property has been defined (can be null).
|
||||
*/
|
||||
public function hasNestedProperty($property, $separator = null);
|
||||
|
||||
/**
|
||||
* @param string $property Object property to be fetched.
|
||||
* @param mixed $default Default value if property has not been set.
|
||||
* @param string $separator Separator, defaults to '.'
|
||||
* @return mixed Property value.
|
||||
* @param string $property Object property to be fetched.
|
||||
* @param mixed|null $default Default value if property has not been set.
|
||||
* @param string|null $separator Separator, defaults to '.'
|
||||
* @return mixed|mixed[] Property value.
|
||||
*/
|
||||
public function getNestedProperty($property, $default = null, $separator = null);
|
||||
|
||||
/**
|
||||
* @param string $property Object property to be updated.
|
||||
* @param string $value New value.
|
||||
* @param string $separator Separator, defaults to '.'
|
||||
* @param string $property Object property to be updated.
|
||||
* @param mixed $value New value.
|
||||
* @param string|null $separator Separator, defaults to '.'
|
||||
* @return $this
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function setNestedProperty($property, $value, $separator = null);
|
||||
|
||||
/**
|
||||
* @param string $property Object property to be defined.
|
||||
* @param string $default Default value.
|
||||
* @param string $separator Separator, defaults to '.'
|
||||
* @param string $property Object property to be defined.
|
||||
* @param mixed $default Default value.
|
||||
* @param string|null $separator Separator, defaults to '.'
|
||||
* @return $this
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function defNestedProperty($property, $default, $separator = null);
|
||||
|
||||
/**
|
||||
* @param string $property Object property to be unset.
|
||||
* @param string $separator Separator, defaults to '.'
|
||||
* @param string $property Object property to be unset.
|
||||
* @param string|null $separator Separator, defaults to '.'
|
||||
* @return $this
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
|
||||
@@ -36,13 +36,6 @@ interface ObjectCollectionInterface extends CollectionInterface, Selectable, Obj
|
||||
*/
|
||||
public function getObjectKeys();
|
||||
|
||||
/**
|
||||
* @param string $property Object property to be fetched.
|
||||
* @param mixed $default Default value if not set.
|
||||
* @return array Property value.
|
||||
*/
|
||||
public function getProperty($property, $default = null);
|
||||
|
||||
/**
|
||||
* @param string $name Method name.
|
||||
* @param array $arguments List of arguments passed to the function.
|
||||
|
||||
@@ -26,34 +26,34 @@ interface ObjectInterface extends \Serializable, \JsonSerializable
|
||||
public function getKey();
|
||||
|
||||
/**
|
||||
* @param string $property Object property name.
|
||||
* @return bool True if property has been defined (can be null).
|
||||
* @param string $property Object property name.
|
||||
* @return bool|bool[] True if property has been defined (can be null).
|
||||
*/
|
||||
public function hasProperty($property);
|
||||
|
||||
/**
|
||||
* @param string $property Object property to be fetched.
|
||||
* @param mixed $default Default value if property has not been set.
|
||||
* @return mixed Property value.
|
||||
* @param string $property Object property to be fetched.
|
||||
* @param mixed|null $default Default value if property has not been set.
|
||||
* @return mixed|mixed[] Property value.
|
||||
*/
|
||||
public function getProperty($property, $default = null);
|
||||
|
||||
/**
|
||||
* @param string $property Object property to be updated.
|
||||
* @param string $value New value.
|
||||
* @param string $property Object property to be updated.
|
||||
* @param mixed $value New value.
|
||||
* @return $this
|
||||
*/
|
||||
public function setProperty($property, $value);
|
||||
|
||||
/**
|
||||
* @param string $property Object property to be defined.
|
||||
* @param mixed $default Default value.
|
||||
* @param string $property Object property to be defined.
|
||||
* @param mixed $default Default value.
|
||||
* @return $this
|
||||
*/
|
||||
public function defProperty($property, $default);
|
||||
|
||||
/**
|
||||
* @param string $property Object property to be unset.
|
||||
* @param string $property Object property to be unset.
|
||||
* @return $this
|
||||
*/
|
||||
public function unsetProperty($property);
|
||||
|
||||
@@ -36,7 +36,7 @@ class ObjectCollection extends ArrayCollection implements ObjectCollectionInterf
|
||||
{
|
||||
parent::__construct($this->setElements($elements));
|
||||
|
||||
$this->setKey($key);
|
||||
$this->setKey($key ?? '');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,11 +76,17 @@ class ObjectCollection extends ArrayCollection implements ObjectCollectionInterf
|
||||
|
||||
if ($orderings = $criteria->getOrderings()) {
|
||||
$next = null;
|
||||
/**
|
||||
* @var string $field
|
||||
* @var string $ordering
|
||||
*/
|
||||
foreach (array_reverse($orderings) as $field => $ordering) {
|
||||
$next = ObjectExpressionVisitor::sortByField($field, $ordering === Criteria::DESC ? -1 : 1, $next);
|
||||
}
|
||||
|
||||
uasort($filtered, $next);
|
||||
if ($next) {
|
||||
uasort($filtered, $next);
|
||||
}
|
||||
}
|
||||
|
||||
$offset = $criteria->getFirstResult();
|
||||
|
||||
@@ -68,7 +68,7 @@ abstract class ObjectIndex extends AbstractIndexCollection implements ObjectColl
|
||||
|
||||
/**
|
||||
* @param string $property Object property name.
|
||||
* @return bool True if property has been defined (can be null).
|
||||
* @return array True if property has been defined (can be null).
|
||||
*/
|
||||
public function hasProperty($property)
|
||||
{
|
||||
@@ -78,7 +78,7 @@ abstract class ObjectIndex extends AbstractIndexCollection implements ObjectColl
|
||||
/**
|
||||
* @param string $property Object property to be fetched.
|
||||
* @param mixed $default Default value if property has not been set.
|
||||
* @return mixed Property value.
|
||||
* @return array Property values.
|
||||
*/
|
||||
public function getProperty($property, $default = null)
|
||||
{
|
||||
|
||||
@@ -32,7 +32,7 @@ trait ArrayPropertyTrait
|
||||
public function __construct(array $elements = [], $key = null)
|
||||
{
|
||||
$this->setElements($elements);
|
||||
$this->setKey($key);
|
||||
$this->setKey($key ?? '');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -38,7 +38,7 @@ trait ObjectPropertyTrait
|
||||
{
|
||||
$this->initObjectProperties();
|
||||
$this->setElements($elements);
|
||||
$this->setKey($key);
|
||||
$this->setKey($key ?? '');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,10 +17,10 @@ class AbstractPagination implements PaginationInterface
|
||||
/** @var Route Base rouse used for the pagination. */
|
||||
protected $route;
|
||||
|
||||
/** @var int Current page. */
|
||||
/** @var int|null Current page. */
|
||||
protected $page;
|
||||
|
||||
/** @var int The record number to start displaying from. */
|
||||
/** @var int|null The record number to start displaying from. */
|
||||
protected $start;
|
||||
|
||||
/** @var int Number of records to display per page. */
|
||||
|
||||
@@ -35,7 +35,10 @@ class Exceptions implements MiddlewareInterface
|
||||
]
|
||||
];
|
||||
|
||||
return new Response($exception->getCode() ?: 500, [], json_encode($response));
|
||||
/** @var string $json */
|
||||
$json = json_encode($response);
|
||||
|
||||
return new Response($exception->getCode() ?: 500, [], $json);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,13 +19,13 @@ use Psr\Http\Server\MiddlewareInterface;
|
||||
|
||||
trait RequestHandlerTrait
|
||||
{
|
||||
/** @var string[]|MiddlewareInterface[]|array */
|
||||
/** @var array<string|MiddlewareInterface> */
|
||||
protected $middleware;
|
||||
|
||||
/** @var callable */
|
||||
private $handler;
|
||||
|
||||
/** @var ContainerInterface */
|
||||
/** @var ContainerInterface|null */
|
||||
private $container;
|
||||
|
||||
/**
|
||||
@@ -45,7 +45,7 @@ trait RequestHandlerTrait
|
||||
return $middleware->process($request, clone $this);
|
||||
}
|
||||
|
||||
if (!$this->container || !$this->container->has($middleware)) {
|
||||
if (null === $this->container || !$this->container->has($middleware)) {
|
||||
throw new InvalidArgumentException(
|
||||
sprintf('The middleware is not a valid %s and is not passed in the Container', MiddlewareInterface::class),
|
||||
$middleware
|
||||
|
||||
@@ -73,7 +73,7 @@ class RouteFactory
|
||||
|
||||
public static function setParamValueDelimiter($delimiter)
|
||||
{
|
||||
self::$delimiter = $delimiter;
|
||||
self::$delimiter = $delimiter ?: ':';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -134,13 +134,21 @@ class RouteFactory
|
||||
*/
|
||||
public static function parseParams($str)
|
||||
{
|
||||
if ($str === '') {
|
||||
return [];
|
||||
}
|
||||
|
||||
$delimiter = self::$delimiter;
|
||||
|
||||
/** @var array $params */
|
||||
$params = explode('/', $str);
|
||||
foreach ($params as &$param) {
|
||||
/** @var array $parts */
|
||||
$parts = explode($delimiter, $param, 2);
|
||||
if (isset($parts[1])) {
|
||||
$param[rawurldecode($parts[0])] = rawurldecode($parts[1]);
|
||||
$var = rawurldecode($parts[0]);
|
||||
$val = rawurldecode($parts[1]);
|
||||
$param = [$var => $val];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -126,9 +126,9 @@ class UriFactory
|
||||
$url
|
||||
);
|
||||
|
||||
$parts = parse_url($encodedUrl);
|
||||
$parts = \is_string($encodedUrl) ? parse_url($encodedUrl) : false;
|
||||
if ($parts === false) {
|
||||
throw new \InvalidArgumentException('Malformed URL: ' . $encodedUrl);
|
||||
throw new \InvalidArgumentException("Malformed URL: {$url}");
|
||||
}
|
||||
|
||||
return $parts;
|
||||
@@ -155,6 +155,12 @@ class UriFactory
|
||||
*/
|
||||
public static function buildQuery(array $params)
|
||||
{
|
||||
return $params ? http_build_query($params, null, ini_get('arg_separator.output'), PHP_QUERY_RFC3986) : '';
|
||||
if (!$params) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$separator = ini_get('arg_separator.output') ?: '&';
|
||||
|
||||
return http_build_query($params, '', $separator, PHP_QUERY_RFC3986);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ class UriPartsFilter
|
||||
return rawurlencode($match[0]);
|
||||
},
|
||||
$info
|
||||
);
|
||||
) ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -114,7 +114,7 @@ class UriPartsFilter
|
||||
return rawurlencode($match[0]);
|
||||
},
|
||||
$path
|
||||
);
|
||||
) ?? '';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -136,6 +136,6 @@ class UriPartsFilter
|
||||
return rawurlencode($match[0]);
|
||||
},
|
||||
$query
|
||||
);
|
||||
) ?? '';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user