Skip to content

Commit

Permalink
Added phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
daVitekPL authored Jul 22, 2024
1 parent c86a678 commit 9085040
Show file tree
Hide file tree
Showing 41 changed files with 215 additions and 135 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Tests PHPStan in environments

on: [pull_request]

jobs:
php82-laravel-latest-phpstan-postgres:
runs-on: ubuntu-latest
container:
image: escolalms/php:8.2

services:
postgres:
image: postgres:12
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: test
TZ: Europe/Warsaw
ports:
- 5432:5432

steps:
- name: Instantiate package
uses: actions/checkout@v2

- name: Setup environment
run: cp env/postgres/* .

- name: Update composer
run: COMPOSER_ROOT_VERSION=0.9.9 composer update

- name: Clear config
run: vendor/bin/testbench config:clear

- name: Publish things
run: vendor/bin/testbench migrate:fresh

- name: Run tests
run: vendor/bin/phpstan analyse
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"require-dev": {
"phpunit/phpunit": "^9.0",
"orchestra/testbench": ">=5.0",
"escolalms/courses-import-export": "^0"
"escolalms/courses-import-export": "^0",
"nunomaduro/larastan": "^2.0"
},
"suggest": {
"escolalms/courses": "Topic types is a package related to escolalms/courses without which it may not work properly.",
Expand Down
10 changes: 10 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
includes:
- ./vendor/nunomaduro/larastan/extension.neon

parameters:

paths:
- src/

# The level 9 is the highest level
level: 5
1 change: 1 addition & 0 deletions src/Helpers/Markdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function ($match) use ($destinationPrefix, &$results) {
str_contains($filepath, 'api/images/img') => $results[] = $this->convertFilePathByApiPattern($destinationPrefix, $filepath, $destination),
str_contains($filepath, 'storage') => $results[] = $this->convertFilePathByStorage($filepath, $destination),
str_contains($filepath, 'http') => $results[] = $this->convertFilePathByHttp($destinationPrefix, $filepath, $destination),
default => $results[] = null,
};

return str_replace($match[3], $destination, $match[0]);
Expand Down
12 changes: 6 additions & 6 deletions src/Http/Resources/TopicType/Admin/AudioResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ class AudioResource extends JsonResource implements TopicTypeResourceContract
public function toArray($request)
{
return [
'id' => $this->id,
'value' => $this->value,
'url' => Storage::url($this->value),
'length' => $this->length,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
'id' => $this->resource->id,
'value' => $this->resource->value,
'url' => Storage::url($this->resource->value),
'length' => $this->resource->length,
'created_at' => $this->resource->created_at,
'updated_at' => $this->resource->updated_at,
];
}
}
8 changes: 4 additions & 4 deletions src/Http/Resources/TopicType/Admin/Cmi5AuResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ class Cmi5AuResource extends JsonResource implements TopicTypeResourceContract
public function toArray($request)
{
return [
'id' => $this->id,
'value' => $this->value,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
'id' => $this->resource->id,
'value' => $this->resource->value,
'created_at' => $this->resource->created_at,
'updated_at' => $this->resource->updated_at,
];
}
}
10 changes: 5 additions & 5 deletions src/Http/Resources/TopicType/Admin/H5PResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ class H5PResource extends JsonResource implements TopicTypeResourceContract
public function toArray($request)
{
return [
'id' => $this->id,
'value' => $this->value,
'content' => isset($this->value) ? app(HeadlessH5PServiceContract::class)->getContentSettings($this->value) : null,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
'id' => $this->resource->id,
'value' => $this->resource->value,
'content' => isset($this->resource->value) ? app(HeadlessH5PServiceContract::class)->getContentSettings($this->resource->value) : null,
'created_at' => $this->resource->created_at,
'updated_at' => $this->resource->updated_at,
];
}
}
14 changes: 7 additions & 7 deletions src/Http/Resources/TopicType/Admin/ImageResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ class ImageResource extends JsonResource implements TopicTypeResourceContract
public function toArray($request)
{
return [
'id' => $this->id,
'value' => $this->value,
'url' => $this->value ? Storage::url($this->value) : null,
'width' => $this->width,
'height' => $this->height,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
'id' => $this->resource->id,
'value' => $this->resource->value,
'url' => $this->resource->value ? Storage::url($this->resource->value) : null,
'width' => $this->resource->width,
'height' => $this->resource->height,
'created_at' => $this->resource->created_at,
'updated_at' => $this->resource->updated_at,
];
}
}
8 changes: 4 additions & 4 deletions src/Http/Resources/TopicType/Admin/OEmbedResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ class OEmbedResource extends JsonResource implements TopicTypeResourceContract
public function toArray($request)
{
return [
'id' => $this->id,
'value' => $this->value,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
'id' => $this->resource->id,
'value' => $this->resource->value,
'created_at' => $this->resource->created_at,
'updated_at' => $this->resource->updated_at,
];
}
}
14 changes: 7 additions & 7 deletions src/Http/Resources/TopicType/Admin/PDFResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ class PDFResource extends JsonResource implements TopicTypeResourceContract
public function toArray($request)
{
return [
'id' => $this->id,
'value' => $this->value,
'length' => $this->length,
'page_count' => $this->page_count,
'url' => Storage::url($this->value),
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
'id' => $this->resource->id,
'value' => $this->resource->value,
'length' => $this->resource->length,
'page_count' => $this->resource->page_count,
'url' => Storage::url($this->resource->value),
'created_at' => $this->resource->created_at,
'updated_at' => $this->resource->updated_at,
];
}
}
10 changes: 5 additions & 5 deletions src/Http/Resources/TopicType/Admin/RichTextResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ class RichTextResource extends JsonResource implements TopicTypeResourceContract
public function toArray($request)
{
return [
'id' => $this->id,
'value' => $this->value,
'length' => $this->length,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
'id' => $this->resource->id,
'value' => $this->resource->value,
'length' => $this->resource->length,
'created_at' => $this->resource->created_at,
'updated_at' => $this->resource->updated_at,
];
}
}
11 changes: 6 additions & 5 deletions src/Http/Resources/TopicType/Admin/ScormScoResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ class ScormScoResource extends JsonResource implements TopicTypeResourceContract
{
public function toArray($request)
{
$scormSco = ScormScoModel::find($this->value);
$scormSco = ScormScoModel::find($this->resource->value);

return [
'id' => $this->id,
'value' => $this->value,
'id' => $this->resource->id,
'value' => $this->resource->value,
// @phpstan-ignore-next-line
'uuid' => $scormSco ? $scormSco->uuid : null,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
'created_at' => $this->resource->created_at,
'updated_at' => $this->resource->updated_at,
];
}
}
20 changes: 10 additions & 10 deletions src/Http/Resources/TopicType/Admin/VideoResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ class VideoResource extends JsonResource implements TopicTypeResourceContract
public function toArray($request)
{
$fields = [
'id' => $this->id,
'value' => $this->value,
'url' => $this->value ? Storage::url($this->value) : null,
'poster' => $this->poster,
'poster_url' => $this->poster ? Storage::url($this->poster) : null,
'width' => $this->width,
'height' => $this->height,
'length' => $this->length,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
'id' => $this->resource->id,
'value' => $this->resource->value,
'url' => $this->resource->value ? Storage::url($this->resource->value) : null,
'poster' => $this->resource->poster,
'poster_url' => $this->resource->poster ? Storage::url($this->resource->poster) : null,
'width' => $this->resource->width,
'height' => $this->resource->height,
'length' => $this->resource->length,
'created_at' => $this->resource->created_at,
'updated_at' => $this->resource->updated_at,
];

return self::apply($fields, $this);
Expand Down
8 changes: 4 additions & 4 deletions src/Http/Resources/TopicType/Client/AudioResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ class AudioResource extends JsonResource implements TopicTypeResourceContract
public function toArray($request)
{
return [
'id' => $this->id,
'value' => $this->value,
'url' => Storage::url($this->value),
'length' => $this->length,
'id' => $this->resource->id,
'value' => $this->resource->value,
'url' => Storage::url($this->resource->value),
'length' => $this->resource->length,
];
}
}
4 changes: 2 additions & 2 deletions src/Http/Resources/TopicType/Client/Cmi5AuResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class Cmi5AuResource extends JsonResource implements TopicTypeResourceContract
public function toArray($request)
{
return [
'id' => $this->id,
'value' => $this->value,
'id' => $this->resource->id,
'value' => $this->resource->value,
];
}
}
6 changes: 3 additions & 3 deletions src/Http/Resources/TopicType/Client/H5PResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class H5PResource extends JsonResource implements TopicTypeResourceContract
public function toArray($request)
{
return [
'id' => $this->id,
'value' => $this->value,
'content' => isset($this->value) ? app(HeadlessH5PServiceContract::class)->getContentSettings($this->value) : null,
'id' => $this->resource->id,
'value' => $this->resource->value,
'content' => isset($this->resource->value) ? app(HeadlessH5PServiceContract::class)->getContentSettings($this->resource->value) : null,
];
}
}
10 changes: 5 additions & 5 deletions src/Http/Resources/TopicType/Client/ImageResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ class ImageResource extends JsonResource implements TopicTypeResourceContract
public function toArray($request)
{
return [
'id' => $this->id,
'value' => $this->value,
'url' => $this->value ? Storage::url($this->value) : null,
'width' => $this->width,
'height' => $this->height,
'id' => $this->resource->id,
'value' => $this->resource->value,
'url' => $this->resource->value ? Storage::url($this->resource->value) : null,
'width' => $this->resource->width,
'height' => $this->resource->height,
];
}
}
4 changes: 2 additions & 2 deletions src/Http/Resources/TopicType/Client/OEmbedResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class OEmbedResource extends JsonResource implements TopicTypeResourceContract
public function toArray($request)
{
return [
'id' => $this->id,
'value' => $this->value,
'id' => $this->resource->id,
'value' => $this->resource->value,
];
}
}
10 changes: 5 additions & 5 deletions src/Http/Resources/TopicType/Client/PDFResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ class PDFResource extends JsonResource implements TopicTypeResourceContract
public function toArray($request)
{
return [
'id' => $this->id,
'value' => $this->value,
'length' => $this->length,
'page_count' => $this->page_count,
'url' => Storage::url($this->value),
'id' => $this->resource->id,
'value' => $this->resource->value,
'length' => $this->resource->length,
'page_count' => $this->resource->page_count,
'url' => Storage::url($this->resource->value),
];
}
}
6 changes: 3 additions & 3 deletions src/Http/Resources/TopicType/Client/RichTextResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class RichTextResource extends JsonResource implements TopicTypeResourceContract
public function toArray($request)
{
return [
'id' => $this->id,
'value' => $this->value,
'length' => $this->length,
'id' => $this->resource->id,
'value' => $this->resource->value,
'length' => $this->resource->length,
];
}
}
7 changes: 4 additions & 3 deletions src/Http/Resources/TopicType/Client/ScormScoResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ class ScormScoResource extends JsonResource implements TopicTypeResourceContract
{
public function toArray($request)
{
$scormSco = ScormScoModel::find($this->value);
$scormSco = ScormScoModel::find($this->resource->value);

return [
'id' => $this->id,
'value' => $this->value,
'id' => $this->resource->id,
'value' => $this->resource->value,
// @phpstan-ignore-next-line
'uuid' => $scormSco ? $scormSco->uuid : null,
];
}
Expand Down
16 changes: 8 additions & 8 deletions src/Http/Resources/TopicType/Client/VideoResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ class VideoResource extends JsonResource implements TopicTypeResourceContract
public function toArray($request)
{
$fields = [
'id' => $this->id,
'value' => $this->value,
'url' => $this->value ? Storage::url($this->value) : null,
'poster' => $this->poster,
'poster_url' => $this->poster ? Storage::url($this->poster) : null,
'width' => $this->width,
'height' => $this->height,
'length' => $this->length,
'id' => $this->resource->id,
'value' => $this->resource->value,
'url' => $this->resource->value ? Storage::url($this->resource->value) : null,
'poster' => $this->resource->poster,
'poster_url' => $this->resource->poster ? Storage::url($this->resource->poster) : null,
'width' => $this->resource->width,
'height' => $this->resource->height,
'length' => $this->resource->length,
];

return self::apply($fields, $this);
Expand Down
8 changes: 4 additions & 4 deletions src/Http/Resources/TopicType/Export/AudioResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ class AudioResource extends JsonResource implements TopicTypeResourceContract
public function toArray($request)
{
return [
'value' => TopicTypeService::sanitizePath($this->value),
'length' => $this->length,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
'value' => TopicTypeService::sanitizePath($this->resource->value),
'length' => $this->resource->length,
'created_at' => $this->resource->created_at,
'updated_at' => $this->resource->updated_at,
];
}
}
Loading

0 comments on commit 9085040

Please sign in to comment.