Skip to content

Commit

Permalink
wip PHP 8
Browse files Browse the repository at this point in the history
  • Loading branch information
npotier committed Jan 19, 2022
1 parent 0c6cd3c commit 4901daf
Show file tree
Hide file tree
Showing 43 changed files with 148 additions and 194 deletions.
4 changes: 2 additions & 2 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public function getConfigTreeBuilder()
->arrayNode('limits')
->performNoDeepMerging()
->beforeNormalization()
->ifTrue(function ($v) { return !is_array($v); })
->then(function ($v) { return [$v]; })
->ifTrue(fn($v) => !is_array($v))
->then(fn($v) => [$v])
->end()
->defaultValue([20 => '20', 50 => '50', 100 => '100'])
->prototype('scalar')->end()
Expand Down
2 changes: 1 addition & 1 deletion Grid/Columns.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function setColumnsOrder(array $columnIds, $keepOtherColumns = true)
}

if ($keepOtherColumns) {
$this->columns = array_merge($reorderedColumns, array_values($columnsIndexedByIds));
$this->columns = [...$reorderedColumns, ...array_values($columnsIndexedByIds)];
} else {
$this->columns = $reorderedColumns;
}
Expand Down
4 changes: 1 addition & 3 deletions Grid/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,8 @@ class Grid implements GridInterface

/**
* The grid configuration.
*
* @var GridConfigInterface
*/
private $config;
private \APY\DataGridBundle\Grid\GridConfigInterface $config;

/**
* Constructor.
Expand Down
10 changes: 3 additions & 7 deletions Grid/GridBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,20 @@ class GridBuilder extends GridConfigBuilder implements GridBuilderInterface
{
/**
* The container.
*
* @var Container
*/
private $container;
private \Symfony\Component\DependencyInjection\Container $container;

/**
* The factory.
*
* @var GridFactoryInterface
*/
private $factory;
private \APY\DataGridBundle\Grid\GridFactoryInterface $factory;

/**
* Columns of the grid builder.
*
* @var Column[]
*/
private $columns = [];
private array $columns = [];

/**
* Constructor.
Expand Down
9 changes: 2 additions & 7 deletions Grid/GridFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,10 @@ class GridFactory implements GridFactoryInterface
{
/**
* The service container.
*
* @var Container
*/
private $container;
private \Symfony\Component\DependencyInjection\Container $container;

/**
* @var GridRegistryInterface
*/
private $registry;
private \APY\DataGridBundle\Grid\GridRegistryInterface $registry;

/**
* Constructor.
Expand Down
4 changes: 2 additions & 2 deletions Grid/GridRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ class GridRegistry implements GridRegistryInterface
*
* @var GridTypeInterface[]
*/
private $types = [];
private array $types = [];

/**
* List of columns.
*
* @var Column[]
*/
private $columns = [];
private array $columns = [];

/**
* Add a grid type.
Expand Down
2 changes: 1 addition & 1 deletion Grid/Source/Vector.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +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)));
}

/**
Expand Down
20 changes: 7 additions & 13 deletions Tests/Action/MassActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,17 @@

class MassActionTest extends TestCase
{
/** @var MassAction */
private $massAction;
private \APY\DataGridBundle\Grid\Action\MassAction $massAction;

/** @var string */
private $title = 'foo';
private string $title = 'foo';

/** @var string */
private $callback = 'static::massAction';
private string $callback = 'static::massAction';

/** @var bool */
private $confirm = true;
private bool $confirm = true;

/** @var array */
private $parameters = ['foo' => 'foo', 'bar' => 'bar'];
private array $parameters = ['foo' => 'foo', 'bar' => 'bar'];

/** @var string */
private $role = 'ROLE_FOO';
private string $role = 'ROLE_FOO';

public function testMassActionConstruct()
{
Expand Down Expand Up @@ -135,7 +129,7 @@ public function testGetRole()
$this->assertEquals($role, $this->massAction->getRole());
}

public function setUp()
public function setUp(): void
{
$this->massAction = new MassAction($this->title, $this->callback, $this->confirm, $this->parameters, $this->role);
}
Expand Down
32 changes: 12 additions & 20 deletions Tests/Grid/Action/RowActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,23 @@
use APY\DataGridBundle\Grid\Action\RowAction;
use APY\DataGridBundle\Grid\Row;

class RowActionTest extends \PHPUnit_Framework_TestCase
class RowActionTest extends \PHPUnit\Framework\TestCase
{
/** @var string */
private $title = 'title';
private string $title = 'title';

/** @var string */
private $route = 'vendor.bundle.controller.route_name';
private string $route = 'vendor.bundle.controller.route_name';

/** @var bool */
private $confirm = true;
private bool $confirm = true;

/** @var string */
private $target = '_parent';
private string $target = '_parent';

/** @var array */
private $attributes = ['foo' => 'foo', 'bar' => 'bar'];
private array $attributes = ['foo' => 'foo', 'bar' => 'bar'];

/** @var string */
private $role = 'ROLE_FOO';
private string $role = 'ROLE_FOO';

/** @var array */
private $callbacks = [];
private array $callbacks = [];

/** @var RowAction */
private $rowAction;
private \APY\DataGridBundle\Grid\Action\RowAction $rowAction;

/** @var \PHPUnit_Framework_MockObject_MockObject */
private $row;
Expand Down Expand Up @@ -243,8 +235,8 @@ public function testGetRole()

public function testManipulateRender()
{
$callback1 = function () { return 1; };
$callback2 = function () { return 2; };
$callback1 = fn() => 1;
$callback2 = fn() => 2;

$this->rowAction->manipulateRender($callback1);
$this->rowAction->manipulateRender($callback2);
Expand Down Expand Up @@ -327,7 +319,7 @@ public function testGetEnabled()
$this->assertTrue($this->rowAction->getEnabled());
}

protected function setUp()
protected function setUp(): void
{
$this->rowAction = new RowAction(
$this->title, $this->route, $this->confirm, $this->target, $this->attributes, $this->role
Expand Down
5 changes: 2 additions & 3 deletions Tests/Grid/Column/ActionsColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

class ActionsColumnTest extends TestCase
{
/** @var ActionsColumn */
private $column;
private \APY\DataGridBundle\Grid\Column\ActionsColumn $column;

public function testConstructor()
{
Expand Down Expand Up @@ -162,7 +161,7 @@ public function testGetRouteParameters()
], $this->column->getRouteParameters($row, $rowAction));
}

public function setUp()
public function setUp(): void
{
$rowAction1 = $this->createMock(RowAction::class);
$rowAction2 = $this->createMock(RowAction::class);
Expand Down
9 changes: 3 additions & 6 deletions Tests/Grid/Column/ArrayColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

class ArrayColumnTest extends TestCase
{
/** @var ArrayColumn */
private $column;
private \APY\DataGridBundle\Grid\Column\ArrayColumn $column;

public function testGetType()
{
Expand Down Expand Up @@ -129,9 +128,7 @@ public function testRenderCellWithoutCallback()
public function testRenderCellWithCallback()
{
$values = ['foo' => 'a', 'bar' => 'b', 'foobar' => ['c', 'd']];
$this->column->manipulateRenderCell(function ($value, $row, $router) {
return ['bar' => 'a', 'foo' => 'b'];
});
$this->column->manipulateRenderCell(fn($value, $row, $router) => ['bar' => 'a', 'foo' => 'b']);

$result = $this->column->renderCell(
$values,
Expand All @@ -142,7 +139,7 @@ public function testRenderCellWithCallback()
$this->assertEquals($result, ['bar' => 'a', 'foo' => 'b']);
}

public function setUp()
public function setUp(): void
{
$this->column = new ArrayColumn();
}
Expand Down
13 changes: 4 additions & 9 deletions Tests/Grid/Column/BooleanColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

class BooleanColumnTest extends TestCase
{
/** @var BooleanColumn */
private $column;
private \APY\DataGridBundle\Grid\Column\BooleanColumn $column;

public function testGetType()
{
Expand Down Expand Up @@ -102,18 +101,14 @@ public function testRenderCell()
public function testRenderCellWithCallback()
{
$this->column->manipulateRenderCell(
function ($value, $row, $router) {
return 'true';
}
fn($value, $row, $router) => 'true'
);
$this->assertEquals('true', $this->column->renderCell(
0, $this->createMock(Row::class), $this->createMock(Router::class)
));

$this->column->manipulateRenderCell(
function ($value, $row, $router) {
return 'false';
}
fn($value, $row, $router) => 'false'
);
$this->assertEquals('false', $this->column->renderCell(
1, $this->createMock(Row::class), $this->createMock(Router::class)
Expand All @@ -129,7 +124,7 @@ function ($value, $row, $router) {
));
}

public function setUp()
public function setUp(): void
{
$this->column = new BooleanColumn();
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/Grid/Column/ColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function testRenderCellWithCallback()
$row = $this->createMock(Row::class);
$router = $this->createMock(Router::class);

$mock->manipulateRenderCell(function ($value, $row, $router) { return 1; });
$mock->manipulateRenderCell(fn($value, $row, $router) => 1);

$this->assertEquals(1, $mock->renderCell($value, $row, $router));
}
Expand Down Expand Up @@ -197,7 +197,7 @@ public function testManipulateRenderCell()
$row = $this->createMock(Row::class);
$router = $this->createMock(Router::class);

$callback = function ($value, $row, $router) { return 1; };
$callback = fn($value, $row, $router) => 1;
$mock->manipulateRenderCell($callback);

$this->assertAttributeEquals($callback, 'callback', $mock);
Expand Down
5 changes: 2 additions & 3 deletions Tests/Grid/Column/DateColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

class DateColumnTest extends TestCase
{
/** @var DateColumn */
private $column;
private \APY\DataGridBundle\Grid\Column\DateColumn $column;

public function testGetType()
{
Expand Down Expand Up @@ -119,7 +118,7 @@ public function testGetFiltersOperatorLte()
);
}

public function setUp()
public function setUp(): void
{
$this->column = new DateColumn();
}
Expand Down
6 changes: 2 additions & 4 deletions Tests/Grid/Column/DateTimeColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use APY\DataGridBundle\Grid\Row;
use Symfony\Bundle\FrameworkBundle\Routing\Router;

class DateTimeColumnTest extends \PHPUnit_Framework_TestCase
class DateTimeColumnTest extends \PHPUnit\Framework\TestCase
{
public function testGetType()
{
Expand Down Expand Up @@ -98,9 +98,7 @@ public function testRenderCellWithCallback()
{
$column = new DateTimeColumn();
$column->setFormat('Y-m-d H:i:s');
$column->manipulateRenderCell(function ($value, $row, $router) {
return '01:00:00';
});
$column->manipulateRenderCell(fn($value, $row, $router) => '01:00:00');

$dateTime = '2000-01-01 01:00:00';
$now = new \DateTime($dateTime);
Expand Down
5 changes: 2 additions & 3 deletions Tests/Grid/Column/JoinColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

class JoinColumnTest extends TestCase
{
/** @var JoinColumn */
private $column;
private \APY\DataGridBundle\Grid\Column\JoinColumn $column;

public function testGetType()
{
Expand Down Expand Up @@ -88,7 +87,7 @@ public function testSetColumnNameOnFilters()
], $column->getFilters('asource'));
}

public function setUp()
public function setUp(): void
{
$this->column = new JoinColumn();
}
Expand Down
5 changes: 2 additions & 3 deletions Tests/Grid/Column/MassActionColumnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

class MassActionColumnTest extends TestCase
{
/** @var MassActionColumn */
private $column;
private \APY\DataGridBundle\Grid\Column\MassActionColumn $column;

public function testGetType()
{
Expand Down Expand Up @@ -40,7 +39,7 @@ public function testInitialize()
], 'params', $this->column);
}

public function setUp()
public function setUp(): void
{
$this->column = new MassActionColumn();
}
Expand Down
Loading

0 comments on commit 4901daf

Please sign in to comment.