From bb1927d23dcccda70a494ab2cc347d588209d7fc Mon Sep 17 00:00:00 2001 From: Rolf van de Krol Date: Tue, 2 Jul 2024 14:34:20 +0200 Subject: [PATCH 1/2] fix: don't specify morphTo name for lti environment, so the correct name is inferred --- src/Models/Traits/HasLtiEnvironment.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Models/Traits/HasLtiEnvironment.php b/src/Models/Traits/HasLtiEnvironment.php index fb912ba..fbf4c69 100644 --- a/src/Models/Traits/HasLtiEnvironment.php +++ b/src/Models/Traits/HasLtiEnvironment.php @@ -22,6 +22,6 @@ trait HasLtiEnvironment public function ltiEnvironment(): MorphTo { /** @phpstan-ignore-next-line */ - return $this->morphTo('lti_environment'); + return $this->morphTo(); } } From ff373e16c33221ea61bc7e4a1c1f6b5a6915257d Mon Sep 17 00:00:00 2001 From: Rolf van de Krol Date: Tue, 2 Jul 2024 14:49:03 +0200 Subject: [PATCH 2/2] chore: fix code style and phpstan errors --- phpstan.neon.dist | 1 - src/ModelDataConnector.php | 2 +- src/Models/AccessToken.php | 8 +++---- src/Models/Context.php | 14 +++++------ src/Models/Contracts/Client.php | 4 ++-- src/Models/Nonce.php | 6 ++--- src/Models/ResourceLink.php | 16 ++++++------- src/Models/SimpleClient.php | 24 +++++++++---------- src/Models/Traits/HasClient.php | 2 +- src/Models/Traits/HasLtiEnvironment.php | 4 ++-- src/Models/UserResult.php | 12 +++++----- .../ModelDataConnectorTests.php | 2 +- workbench/app/Models/SimpleLtiEnvironment.php | 4 ++-- workbench/app/OverrideModels/Client.php | 24 +++++++++---------- .../OverrideModels/SimpleLtiEnvironment.php | 4 ++-- 15 files changed, 63 insertions(+), 64 deletions(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 372793f..64f6d88 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -7,4 +7,3 @@ parameters: - tests - workbench tmpDir: build/phpstan - checkMissingIterableValueType: false diff --git a/src/ModelDataConnector.php b/src/ModelDataConnector.php index 2fe4fd8..cb10d15 100644 --- a/src/ModelDataConnector.php +++ b/src/ModelDataConnector.php @@ -133,7 +133,7 @@ public function savePlatform(CelticPlatform $platform): bool return false; } - $platform->updated = $clientModel->updated_at->getTimestamp(); + $platform->updated = $clientModel->getAttribute($clientModel->getUpdatedAtColumn())->getTimestamp(); return true; } diff --git a/src/Models/AccessToken.php b/src/Models/AccessToken.php index c2fc14e..d9daae5 100644 --- a/src/Models/AccessToken.php +++ b/src/Models/AccessToken.php @@ -11,10 +11,10 @@ use Swis\Laravel\LtiProvider\Models\Traits\HasLtiEnvironment; /** - * @property string $id - * @property string $access_token - * @property array $scopes - * @property \Illuminate\Support\Carbon $expires_at + * @property string $id + * @property string $access_token + * @property array $scopes + * @property \Illuminate\Support\Carbon $expires_at * @property \Illuminate\Support\Carbon|null $created_at * @property \Illuminate\Support\Carbon|null $updated_at * diff --git a/src/Models/Context.php b/src/Models/Context.php index 41aaffc..b59f9f0 100644 --- a/src/Models/Context.php +++ b/src/Models/Context.php @@ -13,14 +13,14 @@ use Swis\Laravel\LtiProvider\Models\Traits\HasLtiEnvironment; /** - * @property int $id - * @property string|null $title - * @property string $external_context_id - * @property \Illuminate\Database\Eloquent\Casts\ArrayObject $settings - * @property \Illuminate\Support\Carbon|null $created_at - * @property \Illuminate\Support\Carbon|null $updated_at + * @property int $id + * @property string|null $title + * @property string $external_context_id + * @property \Illuminate\Database\Eloquent\Casts\ArrayObject $settings + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at * @property \Illuminate\Database\Eloquent\Collection $resourceLinks - * @property int|null $resource_links_count + * @property int|null $resource_links_count * * @method static \Illuminate\Database\Eloquent\Builder|Context newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Context newQuery() diff --git a/src/Models/Contracts/Client.php b/src/Models/Contracts/Client.php index d5614aa..b344ddf 100644 --- a/src/Models/Contracts/Client.php +++ b/src/Models/Contracts/Client.php @@ -8,8 +8,8 @@ use Illuminate\Database\Eloquent\Relations\HasMany; /** - * @property int $nr - * @property string $name + * @property int $nr + * @property string $name * @property \DateTime $updated_at */ interface Client diff --git a/src/Models/Nonce.php b/src/Models/Nonce.php index 11579ea..db83541 100644 --- a/src/Models/Nonce.php +++ b/src/Models/Nonce.php @@ -11,9 +11,9 @@ use Swis\Laravel\LtiProvider\Models\Traits\HasLtiEnvironment; /** - * @property string $id - * @property string $nonce - * @property \Illuminate\Support\Carbon $expires_at + * @property string $id + * @property string $nonce + * @property \Illuminate\Support\Carbon $expires_at * @property \Illuminate\Support\Carbon|null $created_at * @property \Illuminate\Support\Carbon|null $updated_at * diff --git a/src/Models/ResourceLink.php b/src/Models/ResourceLink.php index 7ea3fbc..8a09dfc 100644 --- a/src/Models/ResourceLink.php +++ b/src/Models/ResourceLink.php @@ -14,15 +14,15 @@ use Swis\Laravel\LtiProvider\Models\Traits\HasLtiEnvironment; /** - * @property int $id - * @property int|null $lti_context_id - * @property string|null $title - * @property string $external_resource_link_id - * @property \Illuminate\Database\Eloquent\Casts\ArrayObject $settings - * @property \Illuminate\Support\Carbon|null $created_at - * @property \Illuminate\Support\Carbon|null $updated_at + * @property int $id + * @property int|null $lti_context_id + * @property string|null $title + * @property string $external_resource_link_id + * @property \Illuminate\Database\Eloquent\Casts\ArrayObject $settings + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at * @property \Swis\Laravel\LtiProvider\Models\Context|null $context - * @property int|null $user_results_count + * @property int|null $user_results_count * * @method static \Illuminate\Database\Eloquent\Builder|ResourceLink newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|ResourceLink newQuery() diff --git a/src/Models/SimpleClient.php b/src/Models/SimpleClient.php index 0b127ec..df5df59 100644 --- a/src/Models/SimpleClient.php +++ b/src/Models/SimpleClient.php @@ -11,20 +11,20 @@ use Swis\Laravel\LtiProvider\Models\Traits\HasClientCapabilities; /** - * @property int $id - * @property string $name - * @property string $key - * @property string|null $secret - * @property string|null $public_key - * @property string|null $lti_platform_id - * @property string|null $lti_client_id - * @property string|null $lti_deployment_id - * @property string|null $lti_version - * @property string $lti_signature_method + * @property int $id + * @property string $name + * @property string $key + * @property string|null $secret + * @property string|null $public_key + * @property string|null $lti_platform_id + * @property string|null $lti_client_id + * @property string|null $lti_deployment_id + * @property string|null $lti_version + * @property string $lti_signature_method * @property \Illuminate\Database\Eloquent\Casts\ArrayObject $lti_profile * @property \Illuminate\Database\Eloquent\Casts\ArrayObject $lti_settings - * @property \Illuminate\Support\Carbon|null $created_at - * @property \Illuminate\Support\Carbon|null $updated_at + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at * * @method static \Illuminate\Database\Eloquent\Builder|SimpleClient newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|SimpleClient newQuery() diff --git a/src/Models/Traits/HasClient.php b/src/Models/Traits/HasClient.php index a2b6714..0287d68 100644 --- a/src/Models/Traits/HasClient.php +++ b/src/Models/Traits/HasClient.php @@ -5,7 +5,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; /** - * @property string|int $client_id + * @property string|int $client_id * @property \Illuminate\Database\Eloquent\Model&\Swis\Laravel\LtiProvider\Models\Contracts\Client $client * * @method static \Illuminate\Database\Eloquent\Builder|static whereClientId($value) diff --git a/src/Models/Traits/HasLtiEnvironment.php b/src/Models/Traits/HasLtiEnvironment.php index fbf4c69..6ba462d 100644 --- a/src/Models/Traits/HasLtiEnvironment.php +++ b/src/Models/Traits/HasLtiEnvironment.php @@ -7,8 +7,8 @@ use Illuminate\Database\Eloquent\Relations\MorphTo; /** - * @property string $lti_environment_type - * @property string $lti_environment_id + * @property string $lti_environment_type + * @property string $lti_environment_id * @property \Illuminate\Database\Eloquent\Model&\Swis\Laravel\LtiProvider\Models\Contracts\LtiEnvironment $ltiEnvironment * * @method static \Illuminate\Database\Eloquent\Builder|static whereLtiEnvironmentId($value) diff --git a/src/Models/UserResult.php b/src/Models/UserResult.php index eab3ca3..1e5fb3c 100644 --- a/src/Models/UserResult.php +++ b/src/Models/UserResult.php @@ -11,12 +11,12 @@ use Swis\Laravel\LtiProvider\Models\Traits\HasLtiEnvironment; /** - * @property int $id - * @property int $lti_resource_link_id - * @property string $external_user_id - * @property string $external_user_result_id - * @property \Illuminate\Support\Carbon|null $created_at - * @property \Illuminate\Support\Carbon|null $updated_at + * @property int $id + * @property int $lti_resource_link_id + * @property string $external_user_id + * @property string $external_user_result_id + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at * @property \Swis\Laravel\LtiProvider\Models\ResourceLink $resourceLink * * @method static \Illuminate\Database\Eloquent\Builder|UserResult newModelQuery() diff --git a/tests/ModelDataConnector/ModelDataConnectorTests.php b/tests/ModelDataConnector/ModelDataConnectorTests.php index 65bc1ae..11c5963 100644 --- a/tests/ModelDataConnector/ModelDataConnectorTests.php +++ b/tests/ModelDataConnector/ModelDataConnectorTests.php @@ -40,7 +40,7 @@ public function it_should_load_platform(): void $platform = Platform::fromRecordId($client->getLtiRecordId(), $this->connector); // Assert - $this->assertEquals($client->name, $platform->name); + $this->assertEquals($client->getAttribute('name'), $platform->name); } /** @test */ diff --git a/workbench/app/Models/SimpleLtiEnvironment.php b/workbench/app/Models/SimpleLtiEnvironment.php index 39176d3..b227571 100644 --- a/workbench/app/Models/SimpleLtiEnvironment.php +++ b/workbench/app/Models/SimpleLtiEnvironment.php @@ -8,8 +8,8 @@ use Swis\Laravel\LtiProvider\Models\Traits\IsLtiEnvironment; /** - * @property int $id - * @property string $name + * @property int $id + * @property string $name * @property \Illuminate\Support\Carbon|null $created_at * @property \Illuminate\Support\Carbon|null $updated_at * diff --git a/workbench/app/OverrideModels/Client.php b/workbench/app/OverrideModels/Client.php index 07643a7..f7a8fe0 100644 --- a/workbench/app/OverrideModels/Client.php +++ b/workbench/app/OverrideModels/Client.php @@ -12,20 +12,20 @@ use Swis\Laravel\LtiProvider\Models\Traits\HasClientCapabilities; /** - * @property string $id - * @property int $nr - * @property string $name - * @property string|null $secret - * @property string|null $public_key - * @property string|null $lti_platform_id - * @property string|null $lti_client_id - * @property string|null $lti_deployment_id - * @property string|null $lti_version - * @property string $lti_signature_method + * @property string $id + * @property int $nr + * @property string $name + * @property string|null $secret + * @property string|null $public_key + * @property string|null $lti_platform_id + * @property string|null $lti_client_id + * @property string|null $lti_deployment_id + * @property string|null $lti_version + * @property string $lti_signature_method * @property \Illuminate\Database\Eloquent\Casts\ArrayObject $lti_profile * @property \Illuminate\Database\Eloquent\Casts\ArrayObject $lti_settings - * @property \Illuminate\Support\Carbon|null $created_at - * @property \Illuminate\Support\Carbon|null $updated_at + * @property \Illuminate\Support\Carbon|null $created_at + * @property \Illuminate\Support\Carbon|null $updated_at * * @method static \Illuminate\Database\Eloquent\Builder|Client newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Client newQuery() diff --git a/workbench/app/OverrideModels/SimpleLtiEnvironment.php b/workbench/app/OverrideModels/SimpleLtiEnvironment.php index 1a550e6..bc1ea26 100644 --- a/workbench/app/OverrideModels/SimpleLtiEnvironment.php +++ b/workbench/app/OverrideModels/SimpleLtiEnvironment.php @@ -10,8 +10,8 @@ use Swis\Laravel\LtiProvider\Models\Traits\IsLtiEnvironment; /** - * @property string $id - * @property string $name + * @property string $id + * @property string $name * @property \Illuminate\Support\Carbon|null $created_at * @property \Illuminate\Support\Carbon|null $updated_at *