Skip to content

Commit

Permalink
Chore/support php84 (#170)
Browse files Browse the repository at this point in the history
* Fixed implicit nullable php 8.4 deprecations

* Fixed parameter type mismatch

* Removed left over ray call

* Suppressed BooleanArgumentFlag phpmd warning

* Suppressed CyclomaticComplexity phpmd warning

* Suppressed UnusedFormalParameter phpmd warning

* Removed ray call

* Added php 8.4 to the test matrix

* Added support for testing transactions on multiple connections
  • Loading branch information
LaravelFreelancerNL authored Nov 23, 2024
1 parent 8b405eb commit e248271
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
matrix:
arangodb: ['3.11', '3.12']
php: ['8.2', '8.3']
php: ['8.2', '8.3', '8.4']
laravel: ['^11.0']
include:
- laravel: '^11.0'
Expand Down
1 change: 0 additions & 1 deletion src/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function createOrFirst(array $attributes = [], array $values = [])
try {
return $this->withSavepointIfNeeded(fn() => $this->create(array_merge($attributes, $values)));
} catch (UniqueConstraintViolationException $e) {
ray($e);
return $this->useWritePdo()->where($attributes)->first() ?? throw $e;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Eloquent/Concerns/QueriesAranguentRelationships.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function withAggregate($relations, $column, $function = null)
$query = $relation->getRelationExistenceQuery(
$relation->getRelated()->newQuery(),
$this,
new Expression($expression),
[$expression],
)->setBindings([], 'select');

$query->callScope($constraints);
Expand Down
2 changes: 0 additions & 2 deletions src/Eloquent/Relations/Concerns/IsAranguentRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace LaravelFreelancerNL\Aranguent\Eloquent\Relations\Concerns;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Query\Expression;

trait IsAranguentRelation
{
Expand Down Expand Up @@ -41,7 +40,6 @@ public function getRelationExistenceCountQuery(Builder $query, Builder $parentQu
return $this->getRelationExistenceQuery(
$query,
$parentQuery,
new Expression('*'),
);
}
}
6 changes: 3 additions & 3 deletions src/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ class Builder extends IlluminateQueryBuilder
*/
public function __construct(
IlluminateConnectionInterface $connection,
IlluminateQueryGrammar $grammar = null,
IlluminateProcessor $processor = null,
AQB $aqb = null,
?IlluminateQueryGrammar $grammar = null,
?IlluminateProcessor $processor = null,
?AQB $aqb = null,
) {
assert($connection instanceof IlluminateConnectionInterface);
assert($processor instanceof IlluminateProcessor);
Expand Down
2 changes: 2 additions & 0 deletions src/Query/Concerns/BuildsWheres.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,8 @@ public function whereJsonLength($column, $operator, $value = null, $boolean = 'a
* @param string $boolean
* @param bool $not
* @return $this
*
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function whereLike($column, $value, $caseSensitive = false, $boolean = 'and', $not = false)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Query/Concerns/CompilesColumns.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ protected function prepareColumns(IlluminateQueryBuilder $query, array $columns)
/**
* @throws Exception
*/
protected function normalizeColumn(IlluminateQueryBuilder $query, mixed $column, string $table = null): mixed
protected function normalizeColumn(IlluminateQueryBuilder $query, mixed $column, ?string $table = null): mixed
{
assert($query instanceof Builder);

Expand Down Expand Up @@ -137,7 +137,7 @@ protected function normalizeColumn(IlluminateQueryBuilder $query, mixed $column,
* @return array<mixed>
* @throws Exception
*/
protected function normalizeStringColumn(Builder $query, int|string $key, string $column, string $table = null): array
protected function normalizeStringColumn(Builder $query, int|string $key, string $column, ?string $table = null): array
{
[$column, $alias] = $query->extractAlias($column, $key);

Expand All @@ -158,7 +158,7 @@ protected function normalizeStringColumn(Builder $query, int|string $key, string
* @param string|null $table
* @return string
*/
protected function normalizeColumnReferences(IlluminateQueryBuilder $query, string $column, string $table = null): string
protected function normalizeColumnReferences(IlluminateQueryBuilder $query, string $column, ?string $table = null): string
{
assert($query instanceof Builder);

Expand Down
6 changes: 3 additions & 3 deletions src/Query/Concerns/CompilesDataManipulations.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ trait CompilesDataManipulations
* @param string|null $bindVar
* @return string
*/
public function compileInsert(Builder|IlluminateQueryBuilder $query, array $values, string $bindVar = null)
public function compileInsert(Builder|IlluminateQueryBuilder $query, array $values, ?string $bindVar = null)
{
$table = $this->prefixTable($query->from);

Expand All @@ -41,7 +41,7 @@ public function compileInsert(Builder|IlluminateQueryBuilder $query, array $valu
* @param string|null $bindVar
* @return string
*/
public function compileInsertGetId(IlluminateQueryBuilder $query, $values, $sequence = '_key', string $bindVar = null)
public function compileInsertGetId(IlluminateQueryBuilder $query, $values, $sequence = '_key', ?string $bindVar = null)
{
$table = $this->prefixTable($query->from);

Expand All @@ -68,7 +68,7 @@ public function compileInsertGetId(IlluminateQueryBuilder $query, $values, $sequ
* @param array<mixed> $values
* @return string
*/
public function compileInsertOrIgnore(IlluminateQueryBuilder $query, array $values, string $bindVar = null)
public function compileInsertOrIgnore(IlluminateQueryBuilder $query, array $values, ?string $bindVar = null)
{
$table = $this->prefixTable($query->from);

Expand Down
9 changes: 6 additions & 3 deletions src/Query/Concerns/HandlesAliases.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function convertColumnId(array|string|Expression $column): array|string|E
*
* @throws Exception
*/
public function extractAlias(string $entity, int|string $key = null): array
public function extractAlias(string $entity, int|null|string $key = null): array
{
$results = preg_split("/\sas\s/i", $entity);

Expand Down Expand Up @@ -155,7 +155,7 @@ public function prefixAlias(string $target, string $value): string
/**
* @throws Exception
*/
public function registerColumnAlias(string $column, string $alias = null): bool
public function registerColumnAlias(string $column, ?string $alias = null): bool
{
if (preg_match("/\sas\s/i", $column)) {
[$column, $alias] = $this->extractAlias($column);
Expand All @@ -170,7 +170,10 @@ public function registerColumnAlias(string $column, string $alias = null): bool
return false;
}

public function registerTableAlias(string|Expression $table, string $alias = null): string
/**
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function registerTableAlias(string|Expression $table, ?string $alias = null): string
{
if ($table instanceof Expression && $alias !== null) {
$table = 'Expression' . spl_object_id($table);
Expand Down
2 changes: 1 addition & 1 deletion src/Query/Concerns/HandlesBindings.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected function getLastBindVariable(string $type = 'where'): string
* @param string|null $type
* @return void
*/
public function importBindings($query, string $type = null): void
public function importBindings($query, ?string $type = null): void
{
if ($type) {
$this->bindings[$type] = array_merge($this->bindings[$type], $query->bindings[$type]);
Expand Down
2 changes: 2 additions & 0 deletions src/Testing/Concerns/InteractsWithDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ trait InteractsWithDatabase
* @param array<mixed>|object|string $value
* @param string|null $connection
* @return \Illuminate\Contracts\Database\Query\Expression
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function castAsJson($value, $connection = null)
{
Expand Down
4 changes: 3 additions & 1 deletion src/Testing/DatabaseTransactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public function beginDatabaseTransaction()
{
$database = $this->app->make('db');

$this->app->instance('db.transactions', $transactionsManager = new DatabaseTransactionsManager());
$connections = $this->connectionsToTransact();

$this->app->instance('db.transactions', $transactionsManager = new DatabaseTransactionsManager($connections));

foreach ($this->connectionsToTransact() as $name) {
$connection = $database->connection($name);
Expand Down
4 changes: 3 additions & 1 deletion src/Testing/RefreshDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public function beginDatabaseTransaction()
{
$database = $this->app->make('db');

$this->app->instance('db.transactions', $transactionsManager = new DatabaseTransactionsManager());
$connections = $this->connectionsToTransact();

$this->app->instance('db.transactions', $transactionsManager = new DatabaseTransactionsManager($connections));

foreach ($this->connectionsToTransact() as $name) {
$connection = $database->connection($name);
Expand Down

0 comments on commit e248271

Please sign in to comment.