Skip to content

Commit

Permalink
General: Fix phpstan level 4 and 5 issues
Browse files Browse the repository at this point in the history
  • Loading branch information
pprkut committed Feb 11, 2025
1 parent 1e87d1a commit 3d88327
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/php-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
php-tests:
uses: lunr-php/actions-templates/.github/workflows/php-composer.yml@master
with:
phpstan-level: 3
phpstan-level: 5
allow-style-failures: false
allow-phpstan-failures: false
codestyle-branch: '0.10.2'
Expand Down
2 changes: 1 addition & 1 deletion src/Lunr/Gravity/DMLQueryBuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ public function where_null($left, $negate = FALSE): static;
*
* @return $this Self reference
*/
public function group_by($expr): static;
public function group_by(string $expr): static;

/**
* Define HAVING clause of the SQL statement.
Expand Down
10 changes: 5 additions & 5 deletions src/Lunr/Gravity/DatabaseDMLQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ protected function sql_with($alias, $sql_query, $recursive_query = NULL, $union
$column_names = ' (' . implode(', ', $column_names) . ')';
}

if ($recursive_query != '' && $recursive_query !== NULL)
if ($recursive_query != '')
{
$this->is_recursive = TRUE;

Expand All @@ -485,7 +485,7 @@ protected function sql_with($alias, $sql_query, $recursive_query = NULL, $union

if ($this->with != '')
{
if ($recursive_query != '' && $recursive_query !== NULL)
if ($recursive_query != '')
{
$this->with = $alias . $column_names . ' AS ( ' . $sql_query . $recursive_query . ' ), ' . $this->with;
}
Expand Down Expand Up @@ -943,13 +943,13 @@ protected function implode_query($components): string
/**
* Prepare the list of index hints for a table reference.
*
* @param array $index_hints Array of Index Hints
* @param array|null $index_hints Array of Index Hints
*
* @return string $hints Comma separated list of index hints.
*/
protected function prepare_index_hints($index_hints): string
protected function prepare_index_hints(?array $index_hints): string
{
if (is_array($index_hints) && !empty($index_hints))
if (!empty($index_hints))
{
$index_hints = array_diff($index_hints, [ NULL ]);
$hints = ' ' . implode(', ', $index_hints);
Expand Down
8 changes: 4 additions & 4 deletions src/Lunr/Gravity/MySQL/MySQLDMLQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,16 @@ public function where_regexp($left, $right, $negate = FALSE): static
/**
* Define GROUP BY clause of the SQL statement.
*
* @param string $expr Expression to group by
* @param bool $order Order ASCending/TRUE or DESCending/FALSE, default no order/NULL
* @param string $expr Expression to group by
* @param bool|null $order Order ASCending/TRUE or DESCending/FALSE, default no order/NULL
*
* @return $this Self reference
*/
public function group_by($expr, $order = NULL): static
public function group_by(string $expr, ?bool $order = NULL): static
{
$this->sql_group_by($expr);

if ($order !== NULL && is_bool($order))
if ($order !== NULL)
{
$direction = ($order === TRUE) ? ' ASC' : ' DESC';
$this->group_by .= $direction;
Expand Down
4 changes: 2 additions & 2 deletions src/Lunr/Gravity/MySQL/MySQLQueryEscaper.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ public function geovalue($value, $srid = NULL): string
*
* @return string|null $return NULL for invalid indices, escaped string otherwise.
*/
public function index_hint($keyword, $indices, $for = ''): ?string
public function index_hint(string $keyword, array $indices, string $for = ''): ?string
{
if (!is_array($indices) || empty($indices))
if (empty($indices))
{
return NULL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ public function testEscapingLikeValueUnsupported(): void
*/
public function testEscapingIndexHintWithInvalidIndices($indices): void
{
$this->assertNull($this->class->index_hint('', '', $indices));
$this->assertNull($this->class->index_hint('', $indices));
}

/**
Expand Down
5 changes: 0 additions & 5 deletions src/Lunr/Gravity/MySQL/Tests/MySQLQueryEscaperTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

use Lunr\Gravity\MySQL\MySQLQueryEscaper;
use Lunr\Halo\LunrBaseTestCase;
use stdClass;

/**
* This class contains the tests for the MySQLQueryEscaper class.
Expand Down Expand Up @@ -66,10 +65,6 @@ public function tearDown(): void
public function invalidIndicesProvider(): array
{
$indices = [];
$indices[] = [ NULL ];
$indices[] = [ FALSE ];
$indices[] = [ 'string' ];
$indices[] = [ new stdClass() ];
$indices[] = [ [] ];

return $indices;
Expand Down
6 changes: 3 additions & 3 deletions src/Lunr/Gravity/SQLite3/SQLite3DMLQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,12 @@ public function where_regexp($left, $right, $negate = FALSE): static
/**
* Define GROUP BY clause of the SQL statement.
*
* @param string $expr Expression to group by
* @param bool $order Not supported by SQLite
* @param string $expr Expression to group by
* @param bool|null $order Not supported by SQLite
*
* @return $this Self reference
*/
public function group_by($expr, $order = NULL): static
public function group_by(string $expr, ?bool $order = NULL): static
{
$this->sql_group_by($expr);
return $this;
Expand Down
4 changes: 2 additions & 2 deletions src/Lunr/Gravity/SQLite3/SQLite3QueryEscaper.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ public function likevalue($value, $match = 'both', $collation = '', $charset = '
*
* @return string|null $return NULL for invalid indices, escaped string otherwise.
*/
public function index_hint($keyword, $indices, $for = ''): ?string
public function index_hint(string $keyword, array $indices, string $for = ''): ?string
{
if (!is_array($indices) || empty($indices))
if (empty($indices))
{
return NULL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function testEscapingLikeValueUnsupported(): void
*/
public function testEscapingIndexHintWithInvalidIndices($indices): void
{
$this->assertNull($this->class->index_hint('', '', $indices));
$this->assertNull($this->class->index_hint('', $indices));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

use Lunr\Gravity\SQLite3\SQLite3QueryEscaper;
use Lunr\Halo\LunrBaseTestCase;
use stdClass;

/**
* This class contains the tests for the SQLite3QueryEscaper class.
Expand Down Expand Up @@ -66,10 +65,6 @@ public function tearDown(): void
public function invalidIndicesProvider(): array
{
$indices = [];
$indices[] = [ NULL ];
$indices[] = [ FALSE ];
$indices[] = [ 'string' ];
$indices[] = [ new stdClass() ];
$indices[] = [ [] ];

return $indices;
Expand Down
5 changes: 0 additions & 5 deletions src/Lunr/Gravity/Tests/DatabaseDMLQueryBuilderTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Lunr\Halo\LunrBaseTestCase;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\MockObject\Stub;
use stdClass;

/**
* This class contains common setup routines, providers
Expand Down Expand Up @@ -108,10 +107,6 @@ public function invalidIndexHintProvider(): array
$hints = [];
$hints[] = [ [] ];
$hints[] = [ NULL ];
$hints[] = [ FALSE ];
$hints[] = [ 1 ];
$hints[] = [ 'string' ];
$hints[] = [ new stdClass() ];

return $hints;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: CC0-1.0

parameters:
level: 3
level: 5
paths:
- ../src
bootstrapFiles:
Expand Down

0 comments on commit 3d88327

Please sign in to comment.