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 94fbc24 commit 65533e3
Show file tree
Hide file tree
Showing 9 changed files with 80 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 @@ -15,8 +15,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",
"staudenmeir/eloquent-has-many-deep": "^1.20"
},
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/Project.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Staudenmeir\EloquentJsonRelations\Types\Models;

use Illuminate\Database\Eloquent\Model;
use Staudenmeir\EloquentJsonRelations\HasJsonRelationships;

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

namespace Staudenmeir\EloquentJsonRelations\Types\Models;

use Illuminate\Database\Eloquent\Model;
use Staudenmeir\EloquentJsonRelations\HasJsonRelationships;

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

namespace Staudenmeir\EloquentJsonRelations\Types\Models;

use Illuminate\Database\Eloquent\Model;
use Staudenmeir\EloquentJsonRelations\HasJsonRelationships;

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

namespace Staudenmeir\EloquentJsonRelations\Types;

use Staudenmeir\EloquentJsonRelations\JsonKey;
use Staudenmeir\EloquentJsonRelations\Types\Models\Project;
use Staudenmeir\EloquentJsonRelations\Types\Models\Role;
use Staudenmeir\EloquentJsonRelations\Types\Models\User;

use function PHPStan\Testing\assertType;

function test(Role $role, User $user): void
{
assertType(
'Staudenmeir\EloquentJsonRelations\Relations\BelongsToJson<Staudenmeir\EloquentJsonRelations\Types\Models\Role, Staudenmeir\EloquentJsonRelations\Types\Models\User>',
$user->belongsToJson(Role::class, 'role_ids')
);

assertType(
'Staudenmeir\EloquentJsonRelations\Relations\HasManyJson<Staudenmeir\EloquentJsonRelations\Types\Models\User, Staudenmeir\EloquentJsonRelations\Types\Models\Role>',
$role->hasManyJson(User::class, 'role_ids')
);

assertType(
'Staudenmeir\EloquentJsonRelations\Relations\HasOneJson<Staudenmeir\EloquentJsonRelations\Types\Models\User, Staudenmeir\EloquentJsonRelations\Types\Models\Role>',
$role->hasOneJson(User::class, 'role_ids')
);

assertType(
'Staudenmeir\EloquentHasManyDeep\HasManyDeep<Staudenmeir\EloquentJsonRelations\Types\Models\Project, Staudenmeir\EloquentJsonRelations\Types\Models\Role>',
$role->hasManyThroughJson(Project::class, User::class, new JsonKey('role_ids'))
);
}

0 comments on commit 65533e3

Please sign in to comment.