Skip to content

Commit

Permalink
Add type checks
Browse files Browse the repository at this point in the history
  • Loading branch information
staudenmeir committed Oct 6, 2024
1 parent 0d649c1 commit dcf545e
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/.docker export-ignore
/.github export-ignore
/tests export-ignore
/types export-ignore
.gitattributes export-ignore
.gitignore export-ignore
docker-compose.ci.yml export-ignore
docker-compose.yml export-ignore
phpstan.neon.dist export-ignore
phpstan.types.neon.dist export-ignore
phpunit.xml.dist export-ignore
1 change: 1 addition & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ We accept contributions via Pull Requests on [GitHub](https://github.com/stauden
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
docker compose run --rm php8.3 vendor/bin/phpstan analyse --configuration=phpstan.types.neon.dist --memory-limit=-1
```
4 changes: 4 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ jobs:
run: |
docker compose -f docker-compose.yml -f docker-compose.ci.yml run --rm php${{ matrix.php }} \
vendor/bin/phpstan analyse --error-format=github --memory-limit=-1
- name: Analyse types
run: |
docker compose -f docker-compose.yml -f docker-compose.ci.yml run --rm php${{ matrix.php }} \
vendor/bin/phpstan analyse --configuration=phpstan.types.neon.dist --error-format=github --memory-limit=-1
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
"barryvdh/laravel-ide-helper": "^3.0",
"illuminate/pagination": "^11.0",
"korridor/laravel-has-many-merged": "^1.1",
"larastan/larastan": "^2.9",
"mockery/mockery": "^1.6",
"orchestra/testbench": "^9.0",
"phpstan/phpstan": "^1.12",
"phpunit/phpunit": "^11.0",
"staudenmeir/eloquent-json-relations": "^1.11",
"staudenmeir/laravel-adjacency-list": "^1.21"
Expand Down
6 changes: 6 additions & 0 deletions phpstan.types.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
includes:
- ./vendor/larastan/larastan/extension.neon
parameters:
level: 9
paths:
- types
10 changes: 10 additions & 0 deletions types/Models/Comment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Staudenmeir\EloquentHasManyDeep\Types\Models;

use Illuminate\Database\Eloquent\Model;

class Comment extends Model
{
//
}
11 changes: 11 additions & 0 deletions types/Models/Country.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Staudenmeir\EloquentHasManyDeep\Types\Models;

use Illuminate\Database\Eloquent\Model;
use Staudenmeir\EloquentHasManyDeep\HasRelationships;

class Country extends Model
{
use HasRelationships;
}
10 changes: 10 additions & 0 deletions types/Models/Post.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Staudenmeir\EloquentHasManyDeep\Types\Models;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
//
}
10 changes: 10 additions & 0 deletions types/Models/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Staudenmeir\EloquentHasManyDeep\Types\Models;

use Illuminate\Database\Eloquent\Model;

class User extends Model
{
//
}
49 changes: 49 additions & 0 deletions types/Relationships.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Staudenmeir\EloquentHasManyDeep\Types;

use Staudenmeir\EloquentHasManyDeep\Types\Models\Comment;
use Staudenmeir\EloquentHasManyDeep\Types\Models\Country;
use Staudenmeir\EloquentHasManyDeep\Types\Models\Post;
use Staudenmeir\EloquentHasManyDeep\Types\Models\User;

use function PHPStan\Testing\assertType;

function test(Country $country): void
{
assertType(
'Staudenmeir\EloquentHasManyDeep\HasManyDeep<Staudenmeir\EloquentHasManyDeep\Types\Models\Comment, Staudenmeir\EloquentHasManyDeep\Types\Models\Country>',
$country->hasManyDeep(Comment::class, [User::class, Post::class])
);

assertType(
'Staudenmeir\EloquentHasManyDeep\HasOneDeep<Staudenmeir\EloquentHasManyDeep\Types\Models\Comment, Staudenmeir\EloquentHasManyDeep\Types\Models\Country>',
$country->hasOneDeep(Comment::class, [User::class, Post::class])
);

assertType(
'Staudenmeir\EloquentHasManyDeep\HasManyDeep<Illuminate\Database\Eloquent\Model, Staudenmeir\EloquentHasManyDeep\Types\Models\Country>',
$country->hasManyDeepFromRelations(
(new Country())->hasManyThrough(Post::class, User::class),
(new Post())->hasMany(Comment::class)
)
);

assertType(
'Staudenmeir\EloquentHasManyDeep\HasOneDeep<Illuminate\Database\Eloquent\Model, Staudenmeir\EloquentHasManyDeep\Types\Models\Country>',
$country->hasOneDeepFromRelations(
(new Country())->hasManyThrough(Post::class, User::class),
(new Post())->hasMany(Comment::class)
)
);

assertType(
'Staudenmeir\EloquentHasManyDeep\HasManyDeep<Staudenmeir\EloquentHasManyDeep\Types\Models\Country, Staudenmeir\EloquentHasManyDeep\Types\Models\Comment>',
$country->hasManyDeepFromReverse((new Country())->hasManyDeep(Comment::class, [User::class, Post::class]))
);

assertType(
'Staudenmeir\EloquentHasManyDeep\HasOneDeep<Staudenmeir\EloquentHasManyDeep\Types\Models\Country, Staudenmeir\EloquentHasManyDeep\Types\Models\Comment>',
$country->hasOneDeepFromReverse((new Country())->hasManyDeep(Comment::class, [User::class, Post::class]))
);
}

0 comments on commit dcf545e

Please sign in to comment.