From ec98ddc2dfd8ad3ab0fbdbafe426eeafbb40269d Mon Sep 17 00:00:00 2001 From: Thibaut HENIN Date: Fri, 7 May 2021 07:38:26 +0200 Subject: [PATCH] Improve PageCollectionInterface::dateRange signature and documentation. Report changes into implementations. --- .../Grav/Common/Flex/Types/Pages/PageCollection.php | 12 ++++++------ .../src/Grav/Common/Flex/Types/Pages/PageIndex.php | 12 ++++++------ system/src/Grav/Common/Page/Collection.php | 12 ++++++------ .../Page/Interfaces/PageCollectionInterface.php | 10 +++++----- system/src/Grav/Common/Page/Pages.php | 6 +++--- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/system/src/Grav/Common/Flex/Types/Pages/PageCollection.php b/system/src/Grav/Common/Flex/Types/Pages/PageCollection.php index 83c15e1be..781d25afe 100644 --- a/system/src/Grav/Common/Flex/Types/Pages/PageCollection.php +++ b/system/src/Grav/Common/Flex/Types/Pages/PageCollection.php @@ -426,17 +426,17 @@ class PageCollection extends FlexPageCollection implements PageCollectionInterfa /** * Returns the items between a set of date ranges of either the page date field (default) or - * an arbitrary datetime page field where end date is optional - * Dates can be passed in as text that strtotime() can process + * an arbitrary datetime page field where start date and end date are optional + * Dates must be passed in as text that strtotime() can process * http://php.net/manual/en/function.strtotime.php * - * @param string $startDate - * @param string|false $endDate + * @param string|null $startDate + * @param string|null $endDate * @param string|null $field - * @return static + * @return PageCollectionInterface * @throws Exception */ - public function dateRange($startDate, $endDate = false, $field = null) + public function dateRange($startDate = null, $endDate = null, $field = null) { $start = $startDate ? Utils::date2timestamp($startDate) : false; $end = $endDate ? Utils::date2timestamp($endDate) : false; diff --git a/system/src/Grav/Common/Flex/Types/Pages/PageIndex.php b/system/src/Grav/Common/Flex/Types/Pages/PageIndex.php index b536c4cdf..58c856d71 100644 --- a/system/src/Grav/Common/Flex/Types/Pages/PageIndex.php +++ b/system/src/Grav/Common/Flex/Types/Pages/PageIndex.php @@ -949,17 +949,17 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface /** * Returns the items between a set of date ranges of either the page date field (default) or - * an arbitrary datetime page field where end date is optional - * Dates can be passed in as text that strtotime() can process + * an arbitrary datetime page field where start date and end date are optional + * Dates must be passed in as text that strtotime() can process * http://php.net/manual/en/function.strtotime.php * - * @param string $startDate - * @param bool $endDate + * @param string|null $startDate + * @param string|null $endDate * @param string|null $field - * @return static + * @return PageCollectionInterface * @throws Exception */ - public function dateRange($startDate, $endDate = false, $field = null) + public function dateRange($startDate = null, $endDate = null, $field = null) { $collection = $this->__call('dateRange', [$startDate, $endDate, $field]); diff --git a/system/src/Grav/Common/Page/Collection.php b/system/src/Grav/Common/Page/Collection.php index c241f3629..643f8516a 100644 --- a/system/src/Grav/Common/Page/Collection.php +++ b/system/src/Grav/Common/Page/Collection.php @@ -319,17 +319,17 @@ class Collection extends Iterator implements PageCollectionInterface /** * Returns the items between a set of date ranges of either the page date field (default) or - * an arbitrary datetime page field where end date is optional - * Dates can be passed in as text that strtotime() can process + * an arbitrary datetime page field where start date and end date are optional + * Dates must be passed in as text that strtotime() can process * http://php.net/manual/en/function.strtotime.php * - * @param string $startDate - * @param bool $endDate + * @param string|null $startDate + * @param string|null $endDate * @param string|null $field - * @return $this + * @return PageCollectionInterface * @throws Exception */ - public function dateRange($startDate, $endDate = false, $field = null) + public function dateRange($startDate = null, $endDate = null, $field = null) { $start = $startDate ? Utils::date2timestamp($startDate) : false; $end = $endDate ? Utils::date2timestamp($endDate) : false; diff --git a/system/src/Grav/Common/Page/Interfaces/PageCollectionInterface.php b/system/src/Grav/Common/Page/Interfaces/PageCollectionInterface.php index 67c5b1e96..50029118f 100644 --- a/system/src/Grav/Common/Page/Interfaces/PageCollectionInterface.php +++ b/system/src/Grav/Common/Page/Interfaces/PageCollectionInterface.php @@ -158,17 +158,17 @@ interface PageCollectionInterface extends Traversable, ArrayAccess, Countable, S /** * Returns the items between a set of date ranges of either the page date field (default) or - * an arbitrary datetime page field where end date is optional - * Dates can be passed in as text that strtotime() can process + * an arbitrary datetime page field where start date and end date are optional + * Dates must be passed in as text that strtotime() can process * http://php.net/manual/en/function.strtotime.php * - * @param string $startDate - * @param bool $endDate + * @param string|null $startDate + * @param string|null $endDate * @param string|null $field * @return PageCollectionInterface * @throws Exception */ - public function dateRange($startDate, $endDate = false, $field = null); + public function dateRange($startDate = null, $endDate = null, $field = null); /** * Creates new collection with only visible pages diff --git a/system/src/Grav/Common/Page/Pages.php b/system/src/Grav/Common/Page/Pages.php index 3b3ce8ef3..97f6e1866 100644 --- a/system/src/Grav/Common/Page/Pages.php +++ b/system/src/Grav/Common/Page/Pages.php @@ -540,9 +540,9 @@ class Pages } if (isset($params['dateRange'])) { - $start = $params['dateRange']['start'] ?? 0; - $end = $params['dateRange']['end'] ?? false; - $field = $params['dateRange']['field'] ?? false; + $start = $params['dateRange']['start'] ?? null; + $end = $params['dateRange']['end'] ?? null; + $field = $params['dateRange']['field'] ?? null; $collection = $collection->dateRange($start, $end, $field); }