From 37aa20a66b0661b4799f4053010117884be952d8 Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Thu, 9 Feb 2023 11:25:05 -0500 Subject: [PATCH 1/7] Remove .idea from .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 011b104..e01bc6a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ /vendor/ -/.idea/ /.phpunit.result.cache /composer.lock /phpunit.xml From c0e6acb25830075ed3b0f91bb17a28a36f862fae Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Thu, 9 Feb 2023 11:27:53 -0500 Subject: [PATCH 2/7] Clean up spacing --- tests/Grid/Column/ColumnTest.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/tests/Grid/Column/ColumnTest.php b/tests/Grid/Column/ColumnTest.php index cf3cc34..f29d3ac 100644 --- a/tests/Grid/Column/ColumnTest.php +++ b/tests/Grid/Column/ColumnTest.php @@ -1007,9 +1007,12 @@ public function testGetFiltersBtweWithoutFrom() $mock = $this->getMockForAbstractClass(Column::class); $mock->setData(['operator' => Column::OPERATOR_BTWE, 'to' => 10]); - $this->assertEquals([ - new Filter(Column::OPERATOR_LTE, 10), - ], $mock->getFilters('aSource')); + $this->assertEquals( + [ + new Filter(Column::OPERATOR_LTE, 10), + ], + $mock->getFilters('aSource') + ); } public function testGetFiltersBtweWithoutTo() @@ -1030,10 +1033,13 @@ public function testGetFiltersBtwe() $mock = $this->getMockForAbstractClass(Column::class); $mock->setData(['operator' => Column::OPERATOR_BTWE, 'from' => 1, 'to' => 10]); - $this->assertEquals([ - new Filter(Column::OPERATOR_GTE, 1), - new Filter(Column::OPERATOR_LTE, 10), - ], $mock->getFilters('aSource')); + $this->assertEquals( + [ + new Filter(Column::OPERATOR_GTE, 1), + new Filter(Column::OPERATOR_LTE, 10), + ], + $mock->getFilters('aSource') + ); } public function testGetFiltersNullNoNull() From 9dfcd3a7b8644d0c233405694235753160b4b01e Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Thu, 22 Jun 2023 10:52:36 -0400 Subject: [PATCH 3/7] Clean up --- src/Grid/Column/Column.php | 25 ++++++++++++++----------- src/Grid/Columns.php | 3 +-- src/Grid/Grid.php | 6 +++--- src/Grid/Row.php | 5 +++-- src/Grid/Source/Vector.php | 35 ++++++++++++++--------------------- 5 files changed, 35 insertions(+), 39 deletions(-) diff --git a/src/Grid/Column/Column.php b/src/Grid/Column/Column.php index c887e95..9ff03c5 100644 --- a/src/Grid/Column/Column.php +++ b/src/Grid/Column/Column.php @@ -132,7 +132,7 @@ abstract class Column */ public function __construct($params = null) { - $this->__initialize((array) $params); + $this->__initialize((array)$params); } public function __initialize(array $params) @@ -206,8 +206,8 @@ public function getParam($id, $default = null) /** * Draw cell. * - * @param mixed $value - * @param Row $row + * @param mixed $value + * @param Row $row * @param $router * * @return string @@ -218,8 +218,8 @@ public function renderCell($value, $row, $router) return call_user_func($this->callback, $value, $row, $router); } - $value = is_bool($value) ? (int) $value : $value; - if (array_key_exists((string) $value, $this->values)) { + $value = is_bool($value) ? (int)$value : $value; + if (array_key_exists((string)$value, $this->values)) { $value = $this->values[$value]; } @@ -240,7 +240,8 @@ public function manipulateRenderCell($callback) return $this; } - public function getCallback(): mixed { + public function getCallback(): ?\Closure + { return $this->callback; } @@ -567,7 +568,8 @@ public function getData() return $result; } - public function getDataAttribute(): array { + public function getDataAttribute(): array + { return $this->data; } @@ -700,7 +702,7 @@ public function setFilterType($filterType) { $this->filterType = strtolower($filterType); - return $this; + return $this; } public function getFilterType() @@ -750,7 +752,7 @@ public function getFilters($source) case self::OPERATOR_NEQ: case self::OPERATOR_NLIKE: case self::OPERATOR_NSLIKE: - foreach ((array) $this->data['from'] as $value) { + foreach ((array)$this->data['from'] as $value) { $filters[] = new Filter($this->data['operator'], $value); } break; @@ -806,7 +808,7 @@ public function getOperators() self::OPERATOR_GT, self::OPERATOR_GTE, self::OPERATOR_BTW, - self::OPERATOR_BTWE, ]); + self::OPERATOR_BTWE,]); } return $this->operators; @@ -918,7 +920,8 @@ public function setAuthorizationChecker(AuthorizationCheckerInterface $authoriza return $this; } - public function getAuthorizationChecker(): ?AuthorizationCheckerInterface { + public function getAuthorizationChecker(): ?AuthorizationCheckerInterface + { return $this->authorizationChecker; } diff --git a/src/Grid/Columns.php b/src/Grid/Columns.php index c1fed21..9166929 100644 --- a/src/Grid/Columns.php +++ b/src/Grid/Columns.php @@ -55,9 +55,8 @@ public function getIterator($showOnlySourceColumns = false) * * @return Columns */ - public function addColumn(Column $column, $position = 0) + public function addColumn(Column $column, int $position = 0) { - $position = (int)$position; $column->setAuthorizationChecker($this->authorizationChecker); if ($position == 0) { diff --git a/src/Grid/Grid.php b/src/Grid/Grid.php index 1408a89..2d63c2e 100644 --- a/src/Grid/Grid.php +++ b/src/Grid/Grid.php @@ -1341,7 +1341,7 @@ public function getTweaks() return $this->tweaks; } - public function getAllTweaks(): ?array { + public function getAllTweaks(): array { return $this->tweaks; } @@ -1788,7 +1788,7 @@ public function setDefaultTweak($tweakId) return $this; } - public function getDefaultTweak(): ?string + public function getDefaultTweak(): string { return $this->defaultTweak; } @@ -1879,7 +1879,7 @@ public function setMaxResults($maxResults = null) return $this; } - public function getMaxResults() + public function getMaxResults(): int { return $this->maxResults; } diff --git a/src/Grid/Row.php b/src/Grid/Row.php index 1408330..c9d6ceb 100644 --- a/src/Grid/Row.php +++ b/src/Grid/Row.php @@ -40,7 +40,7 @@ class Row public function __construct() { $this->fields = []; - $this->color = ''; + $this->color = ''; } /** @@ -51,7 +51,8 @@ public function setRepository(EntityRepository $repository) $this->repository = $repository; } - public function getRepository(): ?EntityRepository { + public function getRepository(): ?EntityRepository + { return $this->repository; } diff --git a/src/Grid/Source/Vector.php b/src/Grid/Source/Vector.php index a72f322..1540765 100644 --- a/src/Grid/Source/Vector.php +++ b/src/Grid/Source/Vector.php @@ -74,18 +74,18 @@ public function initialise($container) protected function guessColumns() { $guessedColumns = []; - $dataColumnIds = array_keys(reset($this->data)); + $dataColumnIds = array_keys(reset($this->data)); foreach ($dataColumnIds as $id) { if (!$this->hasColumn($id)) { - $params = [ - 'id' => $id, - 'title' => $id, - 'source' => true, + $params = [ + 'id' => $id, + 'title' => $id, + 'source' => true, 'filterable' => true, - 'sortable' => true, - 'visible' => true, - 'field' => $id, + 'sortable' => true, + 'visible' => true, + 'field' => $id, ]; $guessedColumns[] = new UntypedColumn($params); } @@ -101,7 +101,7 @@ protected function guessColumns() continue; } - $i = 0; + $i = 0; $fieldTypes = []; foreach ($this->data as $row) { @@ -199,10 +199,10 @@ public function getColumns($columns) /** * @param \APY\DataGridBundle\Grid\Column\Column[] $columns - * @param int $page Page Number - * @param int $limit Rows Per Page - * @param int $maxResults Max rows - * @param int $gridDataJunction Grid data junction + * @param int $page Page Number + * @param int $limit Rows Per Page + * @param int $maxResults Max rows + * @param int $gridDataJunction Grid data junction * * @return Rows */ @@ -223,14 +223,7 @@ public function getTotalCount($maxResults = null) public function getHash() { - return __CLASS__ . md5( - implode( - '', - array_map(function ($c) { - return $c->getId(); - }, $this->columns) - ) - ); + return __CLASS__ . md5(implode('', array_map(fn($c) => $c->getId(), $this->columns))); } /** From 38666a734d84a8c2676e0ab6495769c02350e7ac Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Thu, 22 Jun 2023 10:55:15 -0400 Subject: [PATCH 4/7] Updates to pass tests --- src/Grid/Grid.php | 2 +- tests/Grid/ColumnsTest.php | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Grid/Grid.php b/src/Grid/Grid.php index 2d63c2e..863f651 100644 --- a/src/Grid/Grid.php +++ b/src/Grid/Grid.php @@ -1879,7 +1879,7 @@ public function setMaxResults($maxResults = null) return $this; } - public function getMaxResults(): int + public function getMaxResults(): ?int { return $this->maxResults; } diff --git a/tests/Grid/ColumnsTest.php b/tests/Grid/ColumnsTest.php index ffc7711..61428aa 100644 --- a/tests/Grid/ColumnsTest.php +++ b/tests/Grid/ColumnsTest.php @@ -44,8 +44,7 @@ public function testAddColumnsOrder() ->addColumn($column1) ->addColumn($column2, 1) ->addColumn($column3, 2) - ->addColumn($column4, -1) - ->addColumn($column5, 'foo'); + ->addColumn($column4, -1); $this->assertSame([$column2, $column3, $column4, $column1, $column5], iterator_to_array($this->columns->getIterator())); } From 50876bfcef24cebb9ea44d5cf4c167776d0fa68f Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Thu, 22 Jun 2023 10:58:02 -0400 Subject: [PATCH 5/7] Remvoe test --- tests/Grid/GridTest.php | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tests/Grid/GridTest.php b/tests/Grid/GridTest.php index ad231ab..bb8cdd6 100644 --- a/tests/Grid/GridTest.php +++ b/tests/Grid/GridTest.php @@ -1084,15 +1084,6 @@ public function testSetMaxResultWithInvalidValueRaiseException() $this->grid->setMaxResults(-1); } - // @todo: has this case sense? Should not raise exception? - public function testSetMaxResultWithStringValue() - { - $maxResult = 'foo'; - $this->grid->setMaxResults($maxResult); - - $this->assertSame($maxResult, $this->grid->getMaxResults()); - } - public function testSetMaxResult() { $maxResult = 1; From 69da3814a4246359fc4372b5c4fb415d2c5287b9 Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Thu, 22 Jun 2023 11:33:02 -0400 Subject: [PATCH 6/7] Remove unused column from test --- tests/Grid/ColumnsTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Grid/ColumnsTest.php b/tests/Grid/ColumnsTest.php index 61428aa..35975fa 100644 --- a/tests/Grid/ColumnsTest.php +++ b/tests/Grid/ColumnsTest.php @@ -38,7 +38,7 @@ public function testAddColumn() public function testAddColumnsOrder() { - [$column1, $column2, $column3, $column4, $column5] = $this->buildColumnMocks(5); + [$column1, $column2, $column3, $column4] = $this->buildColumnMocks(5); $this->columns ->addColumn($column1) @@ -46,7 +46,7 @@ public function testAddColumnsOrder() ->addColumn($column3, 2) ->addColumn($column4, -1); - $this->assertSame([$column2, $column3, $column4, $column1, $column5], iterator_to_array($this->columns->getIterator())); + $this->assertSame([$column2, $column3, $column4, $column1], iterator_to_array($this->columns->getIterator())); } public function testRaiseExceptionIfGetColumnByIdDoesNotExists() From 50888d2c969758e626cc2b638155f34930e6025b Mon Sep 17 00:00:00 2001 From: Cody deVries Date: Thu, 22 Jun 2023 12:16:16 -0400 Subject: [PATCH 7/7] Build the correct number of mock columns --- tests/Grid/ColumnsTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Grid/ColumnsTest.php b/tests/Grid/ColumnsTest.php index 35975fa..a98d751 100644 --- a/tests/Grid/ColumnsTest.php +++ b/tests/Grid/ColumnsTest.php @@ -38,7 +38,7 @@ public function testAddColumn() public function testAddColumnsOrder() { - [$column1, $column2, $column3, $column4] = $this->buildColumnMocks(5); + [$column1, $column2, $column3, $column4] = $this->buildColumnMocks(4); $this->columns ->addColumn($column1)