From a8731dc05c4546d83149576ee446dc1cc1daf7db Mon Sep 17 00:00:00 2001 From: Fran Moreno Date: Wed, 21 Apr 2021 15:44:01 +0200 Subject: [PATCH] Extract magic numbers --- src/Admin/AbstractAdmin.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Admin/AbstractAdmin.php b/src/Admin/AbstractAdmin.php index 5ea81dcf4e..e925afd3d3 100644 --- a/src/Admin/AbstractAdmin.php +++ b/src/Admin/AbstractAdmin.php @@ -102,6 +102,9 @@ abstract class AbstractAdmin extends AbstractTaggedAdmin implements AdminInterfa private const MASK_OF_ACTION_LIST = self::ACTION_SHOW | self::ACTION_EDIT | self::ACTION_DELETE | self::ACTION_ACL | self::ACTION_BATCH; private const MASK_OF_ACTIONS_USING_OBJECT = self::MASK_OF_ACTION_SHOW | self::MASK_OF_ACTION_EDIT | self::MASK_OF_ACTION_HISTORY | self::MASK_OF_ACTION_ACL; + private const DEFAULT_LIST_PER_PAGE_RESULTS = 32; + private const DEFAULT_LIST_PER_PAGE_OPTIONS = [16, 32, 64, 128, 256]; + /** * The list FieldDescription constructed from the configureListField method. * @@ -139,7 +142,7 @@ abstract class AbstractAdmin extends AbstractTaggedAdmin implements AdminInterfa * * @var int */ - protected $maxPerPage = 32; + protected $maxPerPage = self::DEFAULT_LIST_PER_PAGE_RESULTS; /** * The maximum number of page numbers to display in the list. @@ -196,7 +199,7 @@ abstract class AbstractAdmin extends AbstractTaggedAdmin implements AdminInterfa */ protected $datagridValues = [ DatagridInterface::PAGE => 1, - DatagridInterface::PER_PAGE => 32, + DatagridInterface::PER_PAGE => self::DEFAULT_LIST_PER_PAGE_RESULTS, ]; /** @@ -208,7 +211,7 @@ abstract class AbstractAdmin extends AbstractTaggedAdmin implements AdminInterfa * * @var array */ - protected $perPageOptions = [16, 32, 64, 128, 256]; + protected $perPageOptions = self::DEFAULT_LIST_PER_PAGE_OPTIONS; /** * Array of routes related to this admin. @@ -1605,7 +1608,7 @@ public function getMaxPerPage() return $this->maxPerPage; // $sortValues = $this->getDefaultSortValues(); - // return $sortValues[DatagridInterface::PER_PAGE] ?? 25; + // return $sortValues[DatagridInterface::PER_PAGE] ?? self::DEFAULT_LIST_PER_PAGE_RESULTS; } /** @@ -2656,7 +2659,7 @@ public function getPerPageOptions() { // NEXT_MAJOR: Remove this line and uncomment the following return $this->perPageOptions; -// $perPageOptions = [10, 25, 50, 100, 250]; +// $perPageOptions = self::DEFAULT_LIST_PER_PAGE_OPTIONS; // $perPageOptions[] = $this->getMaxPerPage(); // // $perPageOptions = array_unique($perPageOptions); @@ -3146,7 +3149,7 @@ final protected function getDefaultSortValues(): array { // NEXT_MAJOR: Use the next line instead. $defaultSortValues = []; - // $defaultSortValues = [DatagridInterface::PAGE => 1, DatagridInterface::PER_PAGE => 25]; + // $defaultSortValues = [DatagridInterface::PAGE => 1, DatagridInterface::PER_PAGE => self::DEFAULT_LIST_PER_PAGE_RESULTS]; $this->configureDefaultSortValues($defaultSortValues);