Skip to content

Commit

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

* Increase PHPStan level

* Increase PHPStan level

* Increase PHPStan level

* Increase PHPStan level

* Increase PHPStan level

* Increase PHPStan level

* Improve contributing manual

* Increase PHPStan level

* Formatting
  • Loading branch information
staudenmeir authored Sep 29, 2024
1 parent 2de397b commit 26e29fd
Show file tree
Hide file tree
Showing 33 changed files with 482 additions and 311 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/eloquent-json-relations/actions/workflows/ci.yml/badge.svg)](https://github.com/staudenmeir/eloquent-json-relations/actions/workflows/ci.yml?query=branch%3Amain)
[![Code Coverage](https://codecov.io/gh/staudenmeir/eloquent-json-relations/graph/badge.svg?token=T41IX53I5U)](https://codecov.io/gh/staudenmeir/eloquent-json-relations)
[![PHPStan](https://img.shields.io/badge/PHPStan-level%209-brightgreen.svg?style=flat)](https://github.com/staudenmeir/eloquent-json-relations/actions/workflows/static-analysis.yml?query=branch%3Amain)
[![Latest Stable Version](https://poser.pugx.org/staudenmeir/eloquent-json-relations/v/stable)](https://packagist.org/packages/staudenmeir/eloquent-json-relations)
[![Total Downloads](https://poser.pugx.org/staudenmeir/eloquent-json-relations/downloads)](https://packagist.org/packages/staudenmeir/eloquent-json-relations/stats)
[![License](https://poser.pugx.org/staudenmeir/eloquent-json-relations/license)](https://github.com/staudenmeir/eloquent-json-relations/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 @@ -15,9 +15,8 @@
},
"require-dev": {
"barryvdh/laravel-ide-helper": "^3.0",
"larastan/larastan": "^2.9",
"orchestra/testbench": "^9.0",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan": "^1.12",
"phpunit/phpunit": "^11.0",
"staudenmeir/eloquent-has-many-deep": "^1.20"
},
Expand Down
7 changes: 1 addition & 6 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
includes:
- ./vendor/larastan/larastan/extension.neon
parameters:
level: 2
level: 9
paths:
- src
ignoreErrors:
- "#Called 'first' on Laravel collection, but could have been retrieved as a query.#"
- '#Call to private method take\(\) of parent class Illuminate\\Database\\Eloquent\\Relations\\BelongsTo#'
14 changes: 10 additions & 4 deletions src/Casts/Uuid.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

use Illuminate\Contracts\Database\Eloquent\CastsAttributes;

/**
* @template TGet
* @template TSet
*
* @implements \Illuminate\Contracts\Database\Eloquent\CastsAttributes<TGet, TSet>
*/
class Uuid implements CastsAttributes
{
/**
Expand All @@ -12,8 +18,8 @@ class Uuid implements CastsAttributes
* @param \Illuminate\Database\Eloquent\Model $model
* @param string $key
* @param mixed $value
* @param array $attributes
* @return mixed
* @param array<string, mixed> $attributes
* @return TGet|null
*/
public function get($model, $key, $value, $attributes)
{
Expand All @@ -25,8 +31,8 @@ public function get($model, $key, $value, $attributes)
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param string $key
* @param mixed $value
* @param array $attributes
* @param TSet|null $value
* @param array<string, mixed> $attributes
* @return mixed
*/
public function set($model, $key, $value, $attributes)
Expand Down
4 changes: 2 additions & 2 deletions src/Grammars/JsonGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface JsonGrammar
/**
* Compile a "JSON array" statement into SQL.
*
* @param string $column
* @param string|\Illuminate\Database\Query\Expression $column
* @return string
*/
public function compileJsonArray($column);
Expand Down Expand Up @@ -53,7 +53,7 @@ public function compileMemberOf(string $column, ?string $objectKey, mixed $value
* Prepare the bindings for a "member of" statement.
*
* @param mixed $value
* @return array
* @return list<mixed>
*/
public function prepareBindingsForMemberOf(mixed $value): array;

Expand Down
4 changes: 2 additions & 2 deletions src/Grammars/PostgresGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class PostgresGrammar extends Base implements JsonGrammar
/**
* Compile a "JSON array" statement into SQL.
*
* @param string $column
* @param string|\Illuminate\Database\Query\Expression $column
* @return string
*/
public function compileJsonArray($column)
Expand Down Expand Up @@ -75,7 +75,7 @@ public function compileMemberOf(string $column, ?string $objectKey, mixed $value
* Prepare the bindings for a "member of" statement.
*
* @param mixed $value
* @return array
* @return list<mixed>
*/
public function prepareBindingsForMemberOf(mixed $value): array
{
Expand Down
4 changes: 2 additions & 2 deletions src/Grammars/SQLiteGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class SQLiteGrammar extends Base implements JsonGrammar
/**
* Compile a "JSON array" statement into SQL.
*
* @param string $column
* @param string|\Illuminate\Database\Query\Expression $column
* @return string
*/
public function compileJsonArray($column)
Expand Down Expand Up @@ -70,7 +70,7 @@ public function compileMemberOf(string $column, ?string $objectKey, mixed $value
* Prepare the bindings for a "member of" statement.
*
* @param mixed $value
* @return array
* @return list<mixed>
*/
public function prepareBindingsForMemberOf(mixed $value): array
{
Expand Down
4 changes: 2 additions & 2 deletions src/Grammars/SqlServerGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class SqlServerGrammar extends Base implements JsonGrammar
/**
* Compile a "JSON array" statement into SQL.
*
* @param string $column
* @param string|\Illuminate\Database\Query\Expression $column
* @return string
*/
public function compileJsonArray($column)
Expand Down Expand Up @@ -72,7 +72,7 @@ public function compileMemberOf(string $column, ?string $objectKey, mixed $value
* Prepare the bindings for a "member of" statement.
*
* @param mixed $value
* @return array
* @return list<mixed>
*/
public function prepareBindingsForMemberOf(mixed $value): array
{
Expand Down
4 changes: 2 additions & 2 deletions src/Grammars/Traits/CompilesMySqlJsonQueries.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ trait CompilesMySqlJsonQueries
/**
* Compile a "JSON array" statement into SQL.
*
* @param string $column
* @param string|\Illuminate\Database\Query\Expression $column
* @return string
*/
public function compileJsonArray($column)
Expand Down Expand Up @@ -90,7 +90,7 @@ public function compileMemberOf(string $column, ?string $objectKey, mixed $value
* Prepare the bindings for a "member of" statement.
*
* @param mixed $value
* @return array
* @return list<mixed>
*/
public function prepareBindingsForMemberOf(mixed $value): array
{
Expand Down
3 changes: 3 additions & 0 deletions src/IdeHelper/JsonRelationsHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public function run(ModelsCommand $command, Model $model): void
}
}

/**
* @param \Illuminate\Database\Eloquent\Relations\Relation<*, *, *> $relationship
*/
protected function addRelationship(ModelsCommand $command, ReflectionMethod $method, Relation $relationship): void
{
$type = '\\' . Collection::class . '|\\' . $relationship->getRelated()::class . '[]';
Expand Down
7 changes: 5 additions & 2 deletions src/IdeHelperServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@ class IdeHelperServiceProvider extends ServiceProvider implements DeferrableProv
{
public function register(): void
{
/** @var \Illuminate\Contracts\Config\Repository $config */
/** @var \Illuminate\Config\Repository $config */
$config = $this->app->get('config');

$config->set(
'ide-helper.model_hooks',
array_merge(
[JsonRelationsHook::class],
$config->get('ide-helper.model_hooks', [])
$config->array('ide-helper.model_hooks', [])
)
);
}

/**
* @return list<class-string<\Illuminate\Console\Command>>
*/
public function provides(): array
{
return [
Expand Down
Loading

0 comments on commit 26e29fd

Please sign in to comment.