Skip to content

Commit

Permalink
Switch fully to PHP8
Browse files Browse the repository at this point in the history
- Use new PHP8 features in code
- Minimum version is now PHP8
- Drop PHP 7.4 tests in Travis
- Change doctrine method call from execute to
  executeQuery, as execute was deprecated
- Add new PHPCS rules for PHP8
  • Loading branch information
iquito committed May 26, 2021
1 parent c03cd44 commit 2ddb3dd
Show file tree
Hide file tree
Showing 25 changed files with 193 additions and 217 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ env:
- XDEBUG_MODE=coverage
language: php
php:
- '7.4'
- '8.0'

before_script:
Expand Down
16 changes: 7 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}
],
"require": {
"php": ">=7.4",
"php": ">=8.0",
"ext-pdo": "*",
"squirrelphp/debug": "^0.5",
"doctrine/dbal": "^3.0"
Expand All @@ -36,10 +36,7 @@
"squirrelphp/entities-bundle": "Automatic integration of squirrelphp/entities in Symfony"
},
"config": {
"sort-packages": false,
"platform": {
"php": "7.4"
}
"sort-packages": false
},
"autoload": {
"psr-4": {
Expand All @@ -53,15 +50,16 @@
},
"scripts": {
"phpstan": "vendor/bin/phpstan analyse",
"phpstan_full": "vendor/bin/phpstan clear-result-cache && vendor/bin/phpstan analyse",
"phpstan_base": "vendor/bin/phpstan analyse --generate-baseline",
"phpstan_clear": "vendor/bin/phpstan clear-result-cache",
"psalm": "vendor/bin/psalm --show-info=false --diff",
"psalm_full": "vendor/bin/psalm --show-info=false",
"psalm": "vendor/bin/psalm --show-info=false",
"psalm_full": "vendor/bin/psalm --clear-cache && vendor/bin/psalm --show-info=false",
"psalm_base": "vendor/bin/psalm --set-baseline=psalm-baseline.xml",
"phpunit": "vendor/bin/phpunit --colors=always",
"phpunit_clover": "vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml",
"coverage": "vendor/bin/phpunit --coverage-html tests/_reports",
"coverage": "XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-html tests/_reports",
"phpcs": "vendor/bin/phpcs --standard=ruleset.xml --extensions=php --cache=.phpcs-cache --colors src tests",
"phpcsd": "vendor/bin/phpcs -s --standard=ruleset.xml --extensions=php --cache=.phpcs-cache --colors src tests",
"phpcsfix": "vendor/bin/phpcbf --standard=ruleset.xml --extensions=php --cache=.phpcs-cache src tests",
"binupdate": "@composer bin all update --ansi",
"bininstall": "@composer bin all install --ansi"
Expand Down
1 change: 1 addition & 0 deletions docker/compose-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ services:
# We currently use PCOV because it is at least 8x faster
# - 3 seconds compared to 23 seconds (or 5 minutes with path coverage enabled)
PHP_EXTENSION_XDEBUG: 1
XDEBUG_MODE: coverage
#PHP_EXTENSION_PCOV: 1
PHP_EXTENSION_APCU: 0
PHP_EXTENSION_REDIS: 0
Expand Down
5 changes: 4 additions & 1 deletion ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@
<rule ref="SlevomatCodingStandard.Operators.DisallowEqualOperators"/>
<rule ref="SlevomatCodingStandard.PHP.DisallowReference"/>
<rule ref="SlevomatCodingStandard.PHP.UselessSemicolon"/>
<!--<rule ref="SlevomatCodingStandard.Variables.DisallowSuperGlobalVariable"/>-->
<rule ref="SlevomatCodingStandard.ControlStructures.NewWithParentheses"/>
<rule ref="SlevomatCodingStandard.Functions.DisallowEmptyFunction"/>
<rule ref="SlevomatCodingStandard.Functions.TrailingCommaInCall"/>
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInCall"/>
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration"/>
<rule ref="SlevomatCodingStandard.TypeHints.LongTypeHints"/>
<rule ref="SlevomatCodingStandard.TypeHints.UnionTypeHintFormat"/>
<rule ref="SlevomatCodingStandard.PHP.ShortList"/>
<rule ref="SlevomatCodingStandard.PHP.TypeCast"/>
<rule ref="SlevomatCodingStandard.Classes.ClassConstantVisibility"/>
Expand Down
8 changes: 3 additions & 5 deletions src/Builder/CountEntries.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
*/
class CountEntries implements BuilderInterface
{
private DBInterface $db;

/**
* @var array<int|string,mixed> Explicit connections between the repositories
*/
Expand All @@ -26,9 +24,9 @@ class CountEntries implements BuilderInterface
*/
private bool $blocking = false;

public function __construct(DBInterface $db)
{
$this->db = $db;
public function __construct(
private DBInterface $db,
) {
}

public function inTable(string $table): self
Expand Down
7 changes: 3 additions & 4 deletions src/Builder/DeleteEntries.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
*/
class DeleteEntries implements BuilderInterface
{
private DBInterface $db;
private string $table = '';

/**
Expand All @@ -24,9 +23,9 @@ class DeleteEntries implements BuilderInterface
*/
private bool $confirmNoWhere = false;

public function __construct(DBInterface $db)
{
$this->db = $db;
public function __construct(
private DBInterface $db,
) {
}

public function inTable(string $table): self
Expand Down
7 changes: 3 additions & 4 deletions src/Builder/InsertEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@
*/
class InsertEntry implements BuilderInterface
{
private DBInterface $db;
private string $table = '';

/**
* @var array<string,mixed> VALUES clauses for the query
*/
private array $values = [];

public function __construct(DBInterface $db)
{
$this->db = $db;
public function __construct(
private DBInterface $db,
) {
}

public function inTable(string $table): self
Expand Down
11 changes: 5 additions & 6 deletions src/Builder/InsertOrUpdateEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/
class InsertOrUpdateEntry implements BuilderInterface
{
private DBInterface $db;
private string $table = '';

/**
Expand All @@ -27,9 +26,9 @@ class InsertOrUpdateEntry implements BuilderInterface
*/
private ?array $valuesOnUpdate = null;

public function __construct(DBInterface $db)
{
$this->db = $db;
public function __construct(
private DBInterface $db,
) {
}

public function inTable(string $table): self
Expand All @@ -50,7 +49,7 @@ public function set(array $values): self
/**
* @param string[]|string $indexFields
*/
public function index($indexFields): self
public function index(array|string $indexFields): self
{
if (\is_string($indexFields)) {
$indexFields = [$indexFields];
Expand All @@ -63,7 +62,7 @@ public function index($indexFields): self
/**
* @param array<int|string,mixed>|string|null $values
*/
public function setOnUpdate($values): self
public function setOnUpdate(array|string|null $values): self
{
if (\is_string($values)) {
$values = [$values];
Expand Down
12 changes: 5 additions & 7 deletions src/Builder/SelectEntries.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ class SelectEntries implements BuilderInterface, \IteratorAggregate
{
use FlattenedFieldsWithTypeTrait;

private DBInterface $db;

/**
* @var array<int|string,string> Only retrieve these fields of the tables
*/
Expand Down Expand Up @@ -55,9 +53,9 @@ class SelectEntries implements BuilderInterface, \IteratorAggregate
*/
private bool $blocking = false;

public function __construct(DBInterface $db)
{
$this->db = $db;
public function __construct(
private DBInterface $db,
) {
}

public function field(string $getThisField): self
Expand Down Expand Up @@ -101,7 +99,7 @@ public function where(array $whereClauses): self
/**
* @param array<int|string,string>|string $orderByClauses
*/
public function orderBy($orderByClauses): self
public function orderBy(array|string $orderByClauses): self
{
if (\is_string($orderByClauses)) {
$orderByClauses = [$orderByClauses];
Expand All @@ -114,7 +112,7 @@ public function orderBy($orderByClauses): self
/**
* @param array<int|string,string>|string $groupByClauses
*/
public function groupBy($groupByClauses): self
public function groupBy(array|string $groupByClauses): self
{
if (\is_string($groupByClauses)) {
$groupByClauses = [$groupByClauses];
Expand Down
7 changes: 3 additions & 4 deletions src/Builder/UpdateEntries.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
*/
class UpdateEntries implements BuilderInterface
{
private DBInterface $db;
private string $table = '';

/**
Expand All @@ -29,9 +28,9 @@ class UpdateEntries implements BuilderInterface
*/
private bool $confirmNoWhere = false;

public function __construct(DBInterface $db)
{
$this->db = $db;
public function __construct(
private DBInterface $db,
) {
}

public function inTable(string $table): self
Expand Down
10 changes: 4 additions & 6 deletions src/DBBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
*/
class DBBuilder implements DBBuilderInterface
{
private DBInterface $db;

public function __construct(DBInterface $db)
{
$this->db = $db;
public function __construct(
private DBInterface $db,
) {
}

public function count(): CountEntries
Expand Down Expand Up @@ -51,7 +49,7 @@ public function delete(): DeleteEntries
return new DeleteEntries($this->db);
}

public function transaction(callable $func, ...$arguments)
public function transaction(callable $func, mixed ...$arguments): mixed
{
return $this->db->transaction($func, ...$arguments);
}
Expand Down
6 changes: 1 addition & 5 deletions src/DBBuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,13 @@ public function delete(): DeleteEntries;
* Process $func within a transaction. Any additional arguments after
* $func are passed to $func as arguments
*
* @param callable $func
* @param mixed ...$arguments
* @return mixed
*
* @template TReturn
* @psalm-param callable(mixed ...$arguments): TReturn $func
* @psalm-return TReturn
*
* @throws DBException Common minimal exception thrown if anything goes wrong
*/
public function transaction(callable $func, ...$arguments);
public function transaction(callable $func, mixed ...$arguments): mixed;

public function getDBInterface(): DBInterface;
}
Loading

0 comments on commit 2ddb3dd

Please sign in to comment.