Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop PHP 8.0 #339

Merged
merged 5 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
matrix:
include:
- description: 'Lowest'
php: '8.0'
php: '8.1'
composer_option: '--prefer-lowest'
- description: '8.1'
php: '8.1'
Expand Down
1 change: 1 addition & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
'php_unit_mock_short_will_return' => true,
'no_extra_blank_lines' => true,
'no_unused_imports' => true,
'nullable_type_declaration_for_default_null_value' => true,
])
->setFinder($finder)
;
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
}
],
"require": {
"php": "^8.0",
"php": "^8.1",
"symfony/event-dispatcher-contracts": "^3.0"
},
"require-dev": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@

final class RequestArgumentAccess implements ArgumentAccessInterface
{
private RequestStack $requestStack;

public function __construct(RequestStack $requestStack)
public function __construct(private readonly RequestStack $requestStack)
{
$this->requestStack = $requestStack;
}

public function has(string $name): bool
Expand Down
8 changes: 2 additions & 6 deletions src/Knp/Component/Pager/Event/AfterEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,11 @@
*/
final class AfterEvent extends Event
{
/** @var PaginationInterface<int, mixed> */
private PaginationInterface $pagination;

/**
* @param PaginationInterface<int, mixed> $paginationView
* @param PaginationInterface<int, mixed> $pagination
*/
public function __construct(PaginationInterface $paginationView)
public function __construct(private readonly PaginationInterface $pagination)
{
$this->pagination = $paginationView;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Knp/Component/Pager/Event/BeforeEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
final class BeforeEvent extends Event
{
public function __construct(
private EventDispatcherInterface $eventDispatcher,
private ArgumentAccessInterface $argumentAccess,
private ?Connection $connection = null
private readonly EventDispatcherInterface $eventDispatcher,
private readonly ArgumentAccessInterface $argumentAccess,
private readonly ?Connection $connection = null
) {
}

Expand Down
7 changes: 1 addition & 6 deletions src/Knp/Component/Pager/Event/ItemsEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,13 @@ final class ItemsEvent extends Event
*/
public int $count;

private int $offset;
private int $limit;

/**
* @var array<string, mixed>
*/
private array $customPaginationParams = [];

public function __construct(int $offset, int $limit)
public function __construct(private readonly int $offset, private readonly int $limit)
{
$this->offset = $offset;
$this->limit = $limit;
}

public function setCustomPaginationParameter(string $name, mixed $value): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@

class QuerySubscriber implements EventSubscriberInterface
{
private ArgumentAccessInterface $argumentAccess;

public function __construct(ArgumentAccessInterface $argumentAccess)
public function __construct(private readonly ArgumentAccessInterface $argumentAccess)
{
$this->argumentAccess = $argumentAccess;
}

public function items(ItemsEvent $event): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@

class PropelQuerySubscriber implements EventSubscriberInterface
{
private ArgumentAccessInterface $argumentAccess;

public function __construct(ArgumentAccessInterface $argumentAccess)
public function __construct(private readonly ArgumentAccessInterface $argumentAccess)
{
$this->argumentAccess = $argumentAccess;
}

public function items(ItemsEvent $event): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
class DBALQueryBuilderSubscriber implements EventSubscriberInterface
{
public function __construct(private Connection $connection)
public function __construct(private readonly Connection $connection)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,15 @@ class ArraySubscriber implements EventSubscriberInterface
*/
private string $sortDirection;

private ?PropertyAccessorInterface $propertyAccessor;
private readonly ?PropertyAccessorInterface $propertyAccessor;

private ArgumentAccessInterface $argumentAccess;

public function __construct(ArgumentAccessInterface $argumentAccess, PropertyAccessorInterface $accessor = null)
public function __construct(private readonly ArgumentAccessInterface $argumentAccess, ?PropertyAccessorInterface $accessor = null)
{
if (!$accessor && class_exists(PropertyAccess::class)) {
$accessor = PropertyAccess::createPropertyAccessorBuilder()->enableMagicCall()->getPropertyAccessor();
}

$this->propertyAccessor = $accessor;
$this->argumentAccess = $argumentAccess;
}

public function items(ItemsEvent $event): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@

class QuerySubscriber implements EventSubscriberInterface
{
private ArgumentAccessInterface $argumentAccess;

public function __construct(ArgumentAccessInterface $argumentAccess)
public function __construct(private readonly ArgumentAccessInterface $argumentAccess)
{
$this->argumentAccess = $argumentAccess;
}

public function items(ItemsEvent $event): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@

class QuerySubscriber implements EventSubscriberInterface
{
private ArgumentAccessInterface $argumentAccess;

public function __construct(ArgumentAccessInterface $argumentAccess)
public function __construct(private readonly ArgumentAccessInterface $argumentAccess)
{
$this->argumentAccess = $argumentAccess;
}

public function items(ItemsEvent $event): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@

class ElasticaQuerySubscriber implements EventSubscriberInterface
{
private ArgumentAccessInterface $argumentAccess;

public function __construct(ArgumentAccessInterface $argumentAccess)
public function __construct(private readonly ArgumentAccessInterface $argumentAccess)
{
$this->argumentAccess = $argumentAccess;
}

public function items(ItemsEvent $event): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@

class PropelQuerySubscriber implements EventSubscriberInterface
{
private ArgumentAccessInterface $argumentAccess;

public function __construct(ArgumentAccessInterface $argumentAccess)
public function __construct(private readonly ArgumentAccessInterface $argumentAccess)
{
$this->argumentAccess = $argumentAccess;
}

public function items(ItemsEvent $event): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@
*/
class SolariumQuerySubscriber implements EventSubscriberInterface
{
private ArgumentAccessInterface $argumentAccess;

public function __construct(ArgumentAccessInterface $argumentAccess)
public function __construct(private readonly ArgumentAccessInterface $argumentAccess)
{
$this->argumentAccess = $argumentAccess;
}

public function items(ItemsEvent $event): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@

class PageNumberOutOfRangeException extends OutOfRangeException
{
private int $maxPageNumber;

public function __construct(?string $message, int $maxPageNumber, ?Throwable $previousException = null)
public function __construct(?string $message, private readonly int $maxPageNumber, ?Throwable $previousException = null)
{
parent::__construct($message, 0, $previousException);

$this->maxPageNumber = $maxPageNumber;
}

public function getMaxPageNumber(): int
Expand Down
2 changes: 1 addition & 1 deletion src/Knp/Component/Pager/Pagination/SlidingPagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __toString(): string
$output = call_user_func($this->renderer, $data);
}

return $output;
return (string) $output;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Knp/Component/Pager/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ final class Paginator implements PaginatorInterface
];

public function __construct(
private EventDispatcherInterface $eventDispatcher,
private readonly EventDispatcherInterface $eventDispatcher,
private ArgumentAccessInterface $argumentAccess,
private ?Connection $connection = null
private readonly ?Connection $connection = null
) {
}

Expand All @@ -56,13 +56,13 @@ public function setDefaultPaginatorOptions(array $options): void
*
* @return PaginationInterface<int, mixed>
*/
public function paginate($target, int $page = 1, int $limit = null, array $options = []): PaginationInterface
public function paginate($target, int $page = 1, ?int $limit = null, array $options = []): PaginationInterface
{
if ($page <= 0) {
throw PageNumberInvalidException::create($page);
}

$limit = $limit ?? (int) $this->defaultOptions[self::DEFAULT_LIMIT];
$limit ??= (int) $this->defaultOptions[self::DEFAULT_LIMIT];
if ($limit <= 0) {
throw PageLimitInvalidException::create($limit);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Knp/Component/Pager/PaginatorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ interface PaginatorInterface
*
* @return PaginationInterface<int, mixed>
*/
public function paginate(mixed $target, int $page = 1, int $limit = null, array $options = []): PaginationInterface;
public function paginate(mixed $target, int $page = 1, ?int $limit = null, array $options = []): PaginationInterface;
}
5 changes: 1 addition & 4 deletions tests/Test/Fixture/TestItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@

class TestItem
{
private int $sortProperty;

public function __construct(int $sortProperty)
public function __construct(private readonly int $sortProperty)
{
$this->sortProperty = $sortProperty;
}

public function getSortProperty(): int
Expand Down
4 changes: 1 addition & 3 deletions tests/Test/Pager/Pagination/SlidingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ public function shouldBeAbleToProducePagination(): void
$items = \range(1, 23);
$view = $p->paginate($items, 1, 10);

$view->renderer = static function ($data) {
return 'custom';
};
$view->renderer = static fn($data) => 'custom';
$this->assertEquals('custom', (string) $view);

$pagination = $view->getPaginationData();
Expand Down
4 changes: 1 addition & 3 deletions tests/Test/Pager/Pagination/TraversableItemsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ public function shouldBeAbleToUseTraversableItems(): void
$items = new \ArrayObject(\range(1, 23));
$view = $p->paginate($items, 3, 10);

$view->renderer = static function ($data) {
return 'custom';
};
$view->renderer = static fn($data) => 'custom';
$this->assertEquals('custom', (string)$view);

$items = $view->getItems();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ public function shouldHandleApcQueryCache(): void

$connection = DriverManager::getConnection($conn, $config);
$em = new \Doctrine\ORM\EntityManager($connection, $config);
$schema = \array_map(static function (string $class) use ($em) {
return $em->getClassMetadata($class);
}, $this->getUsedEntityFixtures());
$schema = \array_map(static fn(string $class) => $em->getClassMetadata($class), $this->getUsedEntityFixtures());

$schemaTool = new \Doctrine\ORM\Tools\SchemaTool($em);
$schemaTool->dropSchema([]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,8 @@ private function givenCallbackPagination(): CallbackPagination
{
$data = \range(1, self::TOTAL_NUMBER_OF_ITEMS);

$count = function () use ($data) {
return \count($data);
};
$items = function ($offset, $limit) use ($data) {
return \array_slice($data, $offset, $limit);
};
$count = fn() => \count($data);
$items = fn($offset, $limit) => \array_slice($data, $offset, $limit);

return new CallbackPagination($count, $items);
}
Expand Down
12 changes: 8 additions & 4 deletions tests/Test/Pager/Subscriber/Sortable/Doctrine/ORM/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Test\Pager\Subscriber\Sortable\Doctrine\ORM;

use Composer\InstalledVersions;
use Doctrine\DBAL\DriverManager;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\SchemaTool;
Expand Down Expand Up @@ -41,9 +42,7 @@ public function shouldHandleApcQueryCache(): void

$connection = DriverManager::getConnection($conn, $config);
$em = new EntityManager($connection, $config);
$schema = \array_map(static function ($class) use ($em) {
return $em->getClassMetadata($class);
}, $this->getUsedEntityFixtures());
$schema = \array_map(static fn($class) => $em->getClassMetadata($class), $this->getUsedEntityFixtures());

$schemaTool = new SchemaTool($em);
$schemaTool->dropSchema([]);
Expand Down Expand Up @@ -218,7 +217,12 @@ public function shouldNotExecuteExtraQueriesWhenCountIsZero(): void
*/
public function shouldNotAcceptArrayParameter(): void
{
$this->expectException(\PHP_VERSION_ID < 80100 ? \TypeError::class : \UnexpectedValueException::class);
if (version_compare(InstalledVersions::getVersion('symfony/http-foundation'), '6.0', '<')) {
$this->expectException(\TypeError::class);
} else {
$this->expectException(\UnexpectedValueException::class);
}

$query = $this
->getMockSqliteEntityManager()
->createQuery('SELECT a FROM Test\Fixture\Entity\Article a')
Expand Down
6 changes: 3 additions & 3 deletions tests/Test/Tool/BaseTestCaseMongoODM.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ protected function tearDown(): void
* DocumentManager mock object together with
* annotation mapping driver and database
*/
protected function getMockDocumentManager(EventManager $evm = null): DocumentManager
protected function getMockDocumentManager(?EventManager $evm = null): DocumentManager
{
$conn = new Connection();
$config = $this->getMockAnnotatedConfig();

try {
$this->dm = DocumentManager::create($conn, $config, $evm ?: $this->getEventManager());
$this->dm->getConnection()->connect();
} catch (\MongoException $e) {
} catch (\MongoException) {
$this->markTestSkipped('Doctrine MongoDB ODM failed to connect');
}
return $this->dm;
Expand All @@ -59,7 +59,7 @@ protected function getMockDocumentManager(EventManager $evm = null): DocumentMan
* DocumentManager mock object with
* annotation mapping driver
*/
protected function getMockMappedDocumentManager(EventManager $evm = null): DocumentManager
protected function getMockMappedDocumentManager(?EventManager $evm = null): DocumentManager
{
$conn = $this->createMock(Connection::class);
$config = $this->getMockAnnotatedConfig();
Expand Down
Loading