Skip to content

Commit

Permalink
Increase PHPStan level (#60)
Browse files Browse the repository at this point in the history
* Improve workflows

* Increase PHPStan level

* Increase PHPStan level

* Increase PHPStan level

* Increase PHPStan level

* Increase PHPStan level

* Improve contributing manual

* Refactoring
  • Loading branch information
staudenmeir authored Oct 2, 2024
1 parent 120fd74 commit f560c6f
Show file tree
Hide file tree
Showing 26 changed files with 187 additions and 111 deletions.
3 changes: 2 additions & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ We accept contributions via Pull Requests on [GitHub](https://github.com/stauden

- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.

## Running Tests
## Running Tests & Static Analysis

```
docker compose run --rm php8.3 composer install
docker compose run --rm php8.3 vendor/bin/phpunit
docker compose run --rm php8.3 vendor/bin/phpstan analyse --memory-limit=-1
```
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

[![CI](https://github.com/staudenmeir/laravel-cte/actions/workflows/ci.yml/badge.svg)](https://github.com/staudenmeir/laravel-cte/actions/workflows/ci.yml?query=branch%3Amain)
[![Code Coverage](https://codecov.io/gh/staudenmeir/laravel-cte/graph/badge.svg?token=JWHOOEYYGG)](https://codecov.io/gh/staudenmeir/laravel-cte)
[![PHPStan](https://img.shields.io/badge/PHPStan-level%209-brightgreen.svg?style=flat)](https://github.com/staudenmeir/laravel-cte/actions/workflows/static-analysis.yml?query=branch%3Amain)
[![Latest Stable Version](https://poser.pugx.org/staudenmeir/laravel-cte/v/stable)](https://packagist.org/packages/staudenmeir/laravel-cte)
[![Total Downloads](https://poser.pugx.org/staudenmeir/laravel-cte/downloads)](https://packagist.org/packages/staudenmeir/laravel-cte/stats)
[![License](https://poser.pugx.org/staudenmeir/laravel-cte/license)](https://github.com/staudenmeir/laravel-cte/blob/main/LICENSE)
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@
},
"require-dev": {
"harrygulliford/laravel-firebird": "dev-laravel-11.x",
"larastan/larastan": "^2.9",
"orchestra/testbench": "^9.0",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan": "^1.12",
"phpunit/phpunit": "^11.0",
"singlestoredb/singlestoredb-laravel": "^1.5.4",
"yajra/laravel-oci8": "^11.2.4"
Expand Down
5 changes: 1 addition & 4 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
includes:
- ./vendor/larastan/larastan/extension.neon
parameters:
level: 1
level: 9
paths:
- src
- tests
6 changes: 1 addition & 5 deletions src/Connections/CreatesQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@

trait CreatesQueryBuilder
{
/**
* Get a new query builder instance.
*
* @return \Illuminate\Database\Query\Builder
*/
/** @inheritDoc */
public function query()
{
return new Builder($this);
Expand Down
6 changes: 1 addition & 5 deletions src/Connections/SingleStoreConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@

class SingleStoreConnection extends Connection
{
/**
* Get a new query builder instance.
*
* @return \Illuminate\Database\Query\Builder
*/
/** @inheritDoc */
public function query()
{
return new SingleStoreBuilder($this);
Expand Down
2 changes: 1 addition & 1 deletion src/Connectors/ConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ConnectionFactory extends Base
* @param \PDO|\Closure $connection
* @param string $database
* @param string $prefix
* @param array $config
* @param array<array-key, mixed> $config
* @return \Illuminate\Database\Connection
*
* @throws \InvalidArgumentException
Expand Down
6 changes: 1 addition & 5 deletions src/DatabaseServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@

class DatabaseServiceProvider extends ServiceProvider
{
/**
* Register the service provider.
*
* @return void
*/
/** @inheritDoc */
public function register()
{
$this->app->singleton('db.factory', function ($app) {
Expand Down
50 changes: 50 additions & 0 deletions src/Query/Grammars/ExpressionGrammar.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Staudenmeir\LaravelCte\Query\Grammars;

use Illuminate\Database\Query\Builder;

interface ExpressionGrammar
{
/**
* Compile an insert statement using a subquery into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @param list<string|\Illuminate\Database\Query\Expression> $columns
* @param string $sql
* @return string
*/
public function compileInsertUsing(Builder $query, array $columns, string $sql);

/**
* Compile an update statement into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array<string, mixed> $values
* @return string
*/
public function compileUpdate(Builder $query, array $values);

/**
* Prepare the bindings for an update statement.
*
* @param array{expressions: list<mixed>, select: list<mixed>, from: list<mixed>, join: list<mixed>,
* where: list<mixed>, having: list<mixed>, order: list<mixed>, union: list<mixed>,
* unionOrder: list<mixed>} $bindings
* @param array<string, mixed> $values
* @return list<mixed>
*/
public function prepareBindingsForUpdate(array $bindings, array $values);

/**
* Get the bindings for an update statement.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array{expressions: list<mixed>, select: list<mixed>, from: list<mixed>, join: list<mixed>,
* where: list<mixed>, having: list<mixed>, order: list<mixed>, union: list<mixed>,
* unionOrder: list<mixed>} $bindings
* @param array<string, mixed> $values
* @return list<mixed>
*/
public function getBindingsForUpdate(Builder $query, array $bindings, array $values);
}
2 changes: 1 addition & 1 deletion src/Query/Grammars/FirebirdGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use HarryGulliford\Firebird\Query\Grammars\FirebirdGrammar as Base;
use Staudenmeir\LaravelCte\Query\Grammars\Traits\CompilesFirebirdExpressions;

class FirebirdGrammar extends Base
class FirebirdGrammar extends Base implements ExpressionGrammar
{
use CompilesFirebirdExpressions;
}
2 changes: 1 addition & 1 deletion src/Query/Grammars/MySqlGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Illuminate\Database\Query\Grammars\MySqlGrammar as Base;
use Staudenmeir\LaravelCte\Query\Grammars\Traits\CompilesMySqlExpressions;

class MySqlGrammar extends Base
class MySqlGrammar extends Base implements ExpressionGrammar
{
use CompilesMySqlExpressions;
}
2 changes: 1 addition & 1 deletion src/Query/Grammars/OracleGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Staudenmeir\LaravelCte\Query\Grammars\Traits\CompilesOracleExpressions;
use Yajra\Oci8\Query\Grammars\OracleGrammar as Base;

class OracleGrammar extends Base
class OracleGrammar extends Base implements ExpressionGrammar
{
use CompilesOracleExpressions;
}
2 changes: 1 addition & 1 deletion src/Query/Grammars/PostgresGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Illuminate\Database\Query\Grammars\PostgresGrammar as Base;
use Staudenmeir\LaravelCte\Query\Grammars\Traits\CompilesPostgresExpressions;

class PostgresGrammar extends Base
class PostgresGrammar extends Base implements ExpressionGrammar
{
use CompilesPostgresExpressions;
}
2 changes: 1 addition & 1 deletion src/Query/Grammars/SQLiteGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Illuminate\Database\Query\Grammars\SQLiteGrammar as Base;
use Staudenmeir\LaravelCte\Query\Grammars\Traits\CompilesSQLiteExpressions;

class SQLiteGrammar extends Base
class SQLiteGrammar extends Base implements ExpressionGrammar
{
use CompilesSQLiteExpressions;
}
2 changes: 1 addition & 1 deletion src/Query/Grammars/SingleStoreGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use SingleStore\Laravel\Query\Grammar;
use Staudenmeir\LaravelCte\Query\Grammars\Traits\CompilesMySqlExpressions;

class SingleStoreGrammar extends Grammar
class SingleStoreGrammar extends Grammar implements ExpressionGrammar
{
use CompilesMySqlExpressions;
}
2 changes: 1 addition & 1 deletion src/Query/Grammars/SqlServerGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Illuminate\Database\Query\Grammars\SqlServerGrammar as Base;
use Staudenmeir\LaravelCte\Query\Grammars\Traits\CompilesSqlServerExpressions;

class SqlServerGrammar extends Base
class SqlServerGrammar extends Base implements ExpressionGrammar
{
use CompilesSqlServerExpressions;
}
38 changes: 27 additions & 11 deletions src/Query/Grammars/Traits/CompilesExpressions.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public function __construct()
* Compile the common table expressions.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $expressions
* @param list<array{name: string, query: string, columns: list<string|\Illuminate\Database\Query\Expression>,
* recursive: bool, materialized: bool|null,
* cycle: array{columns: list<string>, markColumn: string, pathColumn: string}|null}> $expressions
* @return string
*/
public function compileExpressions(Builder $query, array $expressions)
Expand Down Expand Up @@ -55,7 +57,9 @@ public function compileExpressions(Builder $query, array $expressions)
/**
* Get the "recursive" keyword.
*
* @param array $expressions
* @param list<array{name: string, query: string, columns: list<string|\Illuminate\Database\Query\Expression>,
* recursive: bool, materialized: bool|null,
* cycle: array{columns: list<string>, markColumn: string, pathColumn: string}|null}> $expressions
* @return string
*/
protected function recursiveKeyword(array $expressions)
Expand Down Expand Up @@ -83,7 +87,9 @@ public function compileRecursionLimit(Builder $query, $recursionLimit)
* Compile the cycle detection.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $expression
* @param array{name: string, query: string, columns: list<string|\Illuminate\Database\Query\Expression>,
* recursive: bool, materialized: bool|null,
* cycle: array{columns: list<string>, markColumn: string, pathColumn: string}|null} $expression
* @return string
*/
public function compileCycle(Builder $query, array $expression)
Expand Down Expand Up @@ -126,12 +132,14 @@ public function compileSelect(Builder $query)
* Compile an insert statement using a subquery into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $columns
* @param list<string|\Illuminate\Database\Query\Expression> $columns
* @param string $sql
* @return string
*/
public function compileInsertUsing(Builder $query, array $columns, string $sql)
{
/** @var \Staudenmeir\LaravelCte\Query\Builder $query */

$expressions = $this->compileExpressions($query, $query->expressions);

$recursionLimit = $this->compileRecursionLimit($query, $query->recursionLimit);
Expand All @@ -148,11 +156,13 @@ public function compileInsertUsing(Builder $query, array $columns, string $sql)
* Compile an update statement into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $values
* @param array<string, mixed> $values
* @return string
*/
public function compileUpdate(Builder $query, array $values)
{
/** @var \Staudenmeir\LaravelCte\Query\Builder $query */

$compiled = parent::compileUpdate($query, $values);

return (string) Str::of($compiled)
Expand All @@ -163,9 +173,11 @@ public function compileUpdate(Builder $query, array $values)
/**
* Prepare the bindings for an update statement.
*
* @param array $bindings
* @param array $values
* @return array
* @param array{expressions: list<mixed>, select: list<mixed>, from: list<mixed>, join: list<mixed>,
* where: list<mixed>, having: list<mixed>, order: list<mixed>, union: list<mixed>,
* unionOrder: list<mixed>} $bindings
* @param array<string, mixed> $values
* @return list<mixed>
*/
public function prepareBindingsForUpdate(array $bindings, array $values)
{
Expand All @@ -180,9 +192,11 @@ public function prepareBindingsForUpdate(array $bindings, array $values)
* Get the bindings for an update statement.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $bindings
* @param array $values
* @return array
* @param array{expressions: list<mixed>, select: list<mixed>, from: list<mixed>, join: list<mixed>,
* where: list<mixed>, having: list<mixed>, order: list<mixed>, union: list<mixed>,
* unionOrder: list<mixed>} $bindings
* @param array<string, mixed> $values
* @return list<mixed>
*/
public function getBindingsForUpdate(Builder $query, array $bindings, array $values)
{
Expand All @@ -197,6 +211,8 @@ public function getBindingsForUpdate(Builder $query, array $bindings, array $val
*/
public function compileDelete(Builder $query)
{
/** @var \Staudenmeir\LaravelCte\Query\Builder $query */

$compiled = parent::compileDelete($query);

return (string) Str::of($compiled)
Expand Down
4 changes: 3 additions & 1 deletion src/Query/Grammars/Traits/CompilesFirebirdExpressions.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ trait CompilesFirebirdExpressions
* Compile an insert statement using a subquery into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $columns
* @param list<string|\Illuminate\Database\Query\Expression> $columns
* @param string $sql
* @return string
*/
public function compileInsertUsing(Builder $query, array $columns, string $sql)
{
/** @var \Staudenmeir\LaravelCte\Query\FirebirdBuilder $query */

$insert = "insert into {$this->wrapTable($query->from)} ({$this->columnize($columns)}) ";

return "$insert{$this->compileExpressions($query, $query->expressions)} $sql";
Expand Down
8 changes: 6 additions & 2 deletions src/Query/Grammars/Traits/CompilesMySqlExpressions.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ trait CompilesMySqlExpressions
* Compile the cycle detection.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $expression
* @param array{name: string, query: string, columns: list<string|\Illuminate\Database\Query\Expression>,
* recursive: bool, materialized: bool|null,
* cycle: array{columns: list<string>, markColumn: string, pathColumn: string}|null} $expression
* @return string
*/
public function compileCycle(Builder $query, array $expression)
Expand All @@ -30,12 +32,14 @@ public function compileCycle(Builder $query, array $expression)
* Compile an insert statement using a subquery into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $columns
* @param list<string|\Illuminate\Database\Query\Expression> $columns
* @param string $sql
* @return string
*/
public function compileInsertUsing(Builder $query, array $columns, string $sql)
{
/** @var \Staudenmeir\LaravelCte\Query\Builder $query */

$insert = "insert into {$this->wrapTable($query->from)} ({$this->columnize($columns)}) ";

return $insert.$this->compileExpressions($query, $query->expressions).' '.$sql;
Expand Down
8 changes: 6 additions & 2 deletions src/Query/Grammars/Traits/CompilesOracleExpressions.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ trait CompilesOracleExpressions
/**
* Get the "recursive" keyword.
*
* @param array $expressions
* @param list<array{name: string, query: string, columns: list<string|\Illuminate\Database\Query\Expression>,
* recursive: bool, materialized: bool|null,
* cycle: array{columns: list<string>, markColumn: string, pathColumn: string}|null}> $expressions
* @return string
*/
protected function recursiveKeyword(array $expressions)
Expand All @@ -23,12 +25,14 @@ protected function recursiveKeyword(array $expressions)
* Compile an insert statement using a subquery into SQL.
*
* @param \Illuminate\Database\Query\Builder $query
* @param array $columns
* @param list<string|\Illuminate\Database\Query\Expression> $columns
* @param string $sql
* @return string
*/
public function compileInsertUsing(Builder $query, array $columns, string $sql)
{
/** @var \Staudenmeir\LaravelCte\Query\OracleBuilder $query */

$insert = "insert into {$this->wrapTable($query->from)} ({$this->columnize($columns)}) ";

return "$insert{$this->compileExpressions($query, $query->expressions)} $sql";
Expand Down
Loading

0 comments on commit f560c6f

Please sign in to comment.