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 3, 2024
1 parent 9e2323e commit fbd9edd
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/.docker export-ignore
/.github export-ignore
/tests export-ignore
/types export-ignore
.gitattributes export-ignore
.gitignore export-ignore
docker-compose.ci.yml export-ignore
Expand Down
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,8 +18,8 @@
},
"require-dev": {
"barryvdh/laravel-ide-helper": "^3.0",
"larastan/larastan": "^2.9",
"orchestra/testbench": "^9.0",
"phpstan/phpstan": "^1.12",
"phpunit/phpunit": "^11.0"
},
"autoload": {
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
11 changes: 11 additions & 0 deletions types/Models/Comment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Staudenmeir\BelongsToThrough\Types\Models;

use Illuminate\Database\Eloquent\Model;
use Znck\Eloquent\Traits\BelongsToThrough;

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

namespace Staudenmeir\BelongsToThrough\Types\Models;

use Illuminate\Database\Eloquent\Model;

class Country extends Model
{
//
}
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\BelongsToThrough\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\BelongsToThrough\Types\Models;

use Illuminate\Database\Eloquent\Model;

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

namespace Staudenmeir\BelongsToThrough\Types;

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

use function PHPStan\Testing\assertType;

function test(Comment $comment): void
{
assertType(
'Znck\Eloquent\Relations\BelongsToThrough<Staudenmeir\BelongsToThrough\Types\Models\Country, Staudenmeir\BelongsToThrough\Types\Models\Comment>',
$comment->belongsToThrough(Country::class, [User::class, Post::class])
);
}

0 comments on commit fbd9edd

Please sign in to comment.