diff --git a/system/src/Grav/Common/GPM/Installer.php b/system/src/Grav/Common/GPM/Installer.php index caf6bc1a5..cd5116383 100644 --- a/system/src/Grav/Common/GPM/Installer.php +++ b/system/src/Grav/Common/GPM/Installer.php @@ -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() { diff --git a/system/src/Grav/Framework/Object/Access/NestedPropertyTrait.php b/system/src/Grav/Framework/Object/Access/NestedPropertyTrait.php index 9dff34b57..1896f47a5 100644 --- a/system/src/Grav/Framework/Object/Access/NestedPropertyTrait.php +++ b/system/src/Grav/Framework/Object/Access/NestedPropertyTrait.php @@ -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); diff --git a/system/src/Grav/Framework/Object/Base/ObjectCollectionTrait.php b/system/src/Grav/Framework/Object/Base/ObjectCollectionTrait.php index 21b7112d5..7e71d9199 100644 --- a/system/src/Grav/Framework/Object/Base/ObjectCollectionTrait.php +++ b/system/src/Grav/Framework/Object/Base/ObjectCollectionTrait.php @@ -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; diff --git a/system/src/Grav/Framework/Object/Base/ObjectTrait.php b/system/src/Grav/Framework/Object/Base/ObjectTrait.php index 519d4dca7..baeeb2bb7 100644 --- a/system/src/Grav/Framework/Object/Base/ObjectTrait.php +++ b/system/src/Grav/Framework/Object/Base/ObjectTrait.php @@ -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) { diff --git a/system/src/Grav/Framework/Object/Interfaces/NestedObjectInterface.php b/system/src/Grav/Framework/Object/Interfaces/NestedObjectInterface.php index 90e6dc935..8d6025a32 100644 --- a/system/src/Grav/Framework/Object/Interfaces/NestedObjectInterface.php +++ b/system/src/Grav/Framework/Object/Interfaces/NestedObjectInterface.php @@ -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 */ diff --git a/system/src/Grav/Framework/Object/Interfaces/ObjectCollectionInterface.php b/system/src/Grav/Framework/Object/Interfaces/ObjectCollectionInterface.php index fc65f4406..7323294b1 100644 --- a/system/src/Grav/Framework/Object/Interfaces/ObjectCollectionInterface.php +++ b/system/src/Grav/Framework/Object/Interfaces/ObjectCollectionInterface.php @@ -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. diff --git a/system/src/Grav/Framework/Object/Interfaces/ObjectInterface.php b/system/src/Grav/Framework/Object/Interfaces/ObjectInterface.php index 475c5dc04..88c80ab66 100644 --- a/system/src/Grav/Framework/Object/Interfaces/ObjectInterface.php +++ b/system/src/Grav/Framework/Object/Interfaces/ObjectInterface.php @@ -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); diff --git a/system/src/Grav/Framework/Object/ObjectCollection.php b/system/src/Grav/Framework/Object/ObjectCollection.php index b1670fdfc..e0216aa1a 100644 --- a/system/src/Grav/Framework/Object/ObjectCollection.php +++ b/system/src/Grav/Framework/Object/ObjectCollection.php @@ -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(); diff --git a/system/src/Grav/Framework/Object/ObjectIndex.php b/system/src/Grav/Framework/Object/ObjectIndex.php index 16453e983..4ba9b75e6 100644 --- a/system/src/Grav/Framework/Object/ObjectIndex.php +++ b/system/src/Grav/Framework/Object/ObjectIndex.php @@ -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) { diff --git a/system/src/Grav/Framework/Object/Property/ArrayPropertyTrait.php b/system/src/Grav/Framework/Object/Property/ArrayPropertyTrait.php index 3606386db..2673f0c40 100644 --- a/system/src/Grav/Framework/Object/Property/ArrayPropertyTrait.php +++ b/system/src/Grav/Framework/Object/Property/ArrayPropertyTrait.php @@ -32,7 +32,7 @@ trait ArrayPropertyTrait public function __construct(array $elements = [], $key = null) { $this->setElements($elements); - $this->setKey($key); + $this->setKey($key ?? ''); } /** diff --git a/system/src/Grav/Framework/Object/Property/ObjectPropertyTrait.php b/system/src/Grav/Framework/Object/Property/ObjectPropertyTrait.php index cd7bca4b9..efc0c7f05 100644 --- a/system/src/Grav/Framework/Object/Property/ObjectPropertyTrait.php +++ b/system/src/Grav/Framework/Object/Property/ObjectPropertyTrait.php @@ -38,7 +38,7 @@ trait ObjectPropertyTrait { $this->initObjectProperties(); $this->setElements($elements); - $this->setKey($key); + $this->setKey($key ?? ''); } /** diff --git a/system/src/Grav/Framework/Pagination/AbstractPagination.php b/system/src/Grav/Framework/Pagination/AbstractPagination.php index 54a2f60d3..acdad77bf 100644 --- a/system/src/Grav/Framework/Pagination/AbstractPagination.php +++ b/system/src/Grav/Framework/Pagination/AbstractPagination.php @@ -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. */ diff --git a/system/src/Grav/Framework/RequestHandler/Middlewares/Exceptions.php b/system/src/Grav/Framework/RequestHandler/Middlewares/Exceptions.php index 8801b1512..568b89a6b 100644 --- a/system/src/Grav/Framework/RequestHandler/Middlewares/Exceptions.php +++ b/system/src/Grav/Framework/RequestHandler/Middlewares/Exceptions.php @@ -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); } } } diff --git a/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php b/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php index 2de870fc8..153d1a160 100644 --- a/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php +++ b/system/src/Grav/Framework/RequestHandler/Traits/RequestHandlerTrait.php @@ -19,13 +19,13 @@ use Psr\Http\Server\MiddlewareInterface; trait RequestHandlerTrait { - /** @var string[]|MiddlewareInterface[]|array */ + /** @var array */ 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 diff --git a/system/src/Grav/Framework/Route/RouteFactory.php b/system/src/Grav/Framework/Route/RouteFactory.php index ac9efcdd0..6b3414a48 100644 --- a/system/src/Grav/Framework/Route/RouteFactory.php +++ b/system/src/Grav/Framework/Route/RouteFactory.php @@ -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]; } } diff --git a/system/src/Grav/Framework/Uri/UriFactory.php b/system/src/Grav/Framework/Uri/UriFactory.php index acbdfa6e5..e5cb1d319 100644 --- a/system/src/Grav/Framework/Uri/UriFactory.php +++ b/system/src/Grav/Framework/Uri/UriFactory.php @@ -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); } } diff --git a/system/src/Grav/Framework/Uri/UriPartsFilter.php b/system/src/Grav/Framework/Uri/UriPartsFilter.php index 13063b2c5..88fe3e64e 100644 --- a/system/src/Grav/Framework/Uri/UriPartsFilter.php +++ b/system/src/Grav/Framework/Uri/UriPartsFilter.php @@ -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 - ); + ) ?? ''; } }