Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added phpstan #26

Merged
merged 2 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -11,7 +11,8 @@
},
"require-dev": {
"phpunit/phpunit": "^9.0",
"orchestra/testbench": "^6"
"orchestra/testbench": ">=6",
"nunomaduro/larastan": "^2.0"
},
"license": "MIT",
"authors": [
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/Exceptions/StationaryEventNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace EscolaLms\StationaryEvents\Exceptions;

use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
use Throwable;

class StationaryEventNotFoundException extends UnprocessableEntityHttpException
{
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Resources/StationaryEventAdminResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class StationaryEventAdminResource extends StationaryEventResource
public function toArray($request): array
{
return array_merge(parent::toArray($request), [
'users' => $this->users ? UserResource::collection($this->users) : [],
'users' => $this->resource->users ? UserResource::collection($this->resource->users) : [],
]);
}
}
40 changes: 20 additions & 20 deletions src/Http/Resources/StationaryEventResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ class StationaryEventResource extends JsonResource
public function toArray($request): array
{
$fields = [
'id' => $this->id,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
'name' => $this->name,
'description' => $this->description,
'short_desc' => $this->short_desc,
'started_at' => $this->started_at,
'finished_at' => $this->finished_at,
'max_participants' => $this->max_participants,
'place' => $this->place,
'program' => $this->program,
'categories' => $this->categories,
'status' => $this->status,
'authors' => $this->authors ? UserResource::collection($this->authors) : [],
'image_path' => $this->image_path,
'image_url' => $this->image_path ? Storage::url($this->image_path) : null,
'in_coming' => $this->in_coming,
'is_ended' => $this->is_ended,
'is_started' => $this->is_started,
'agenda' => $this->agenda,
'id' => $this->resource->id,
'created_at' => $this->resource->created_at,
'updated_at' => $this->resource->updated_at,
'name' => $this->resource->name,
'description' => $this->resource->description,
'short_desc' => $this->resource->short_desc,
'started_at' => $this->resource->started_at,
'finished_at' => $this->resource->finished_at,
'max_participants' => $this->resource->max_participants,
'place' => $this->resource->place,
'program' => $this->resource->program,
'categories' => $this->resource->categories,
'status' => $this->resource->status,
'authors' => $this->resource->authors ? UserResource::collection($this->resource->authors) : [],
'image_path' => $this->resource->image_path,
'image_url' => $this->resource->image_path ? Storage::url($this->resource->image_path) : null,
'in_coming' => $this->resource->in_coming,
'is_ended' => $this->resource->is_ended,
'is_started' => $this->resource->is_started,
'agenda' => $this->resource->agenda,
];

return self::apply($fields, $this);
Expand Down
8 changes: 4 additions & 4 deletions src/Http/Resources/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ class UserResource extends JsonResource
public function toArray($request): array
{
return [
'id' => $this->id,
'first_name' => $this->first_name,
'last_name' => $this->last_name,
'path_avatar' => $this->path_avatar,
'id' => $this->resource->id,
'first_name' => $this->resource->first_name,
'last_name' => $this->resource->last_name,
'path_avatar' => $this->resource->path_avatar,
];
}
}
14 changes: 14 additions & 0 deletions src/Models/StationaryEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@
* ),
* )
*
* @property int $id
* @property string $name
* @property string $description
* @property string $short_description
* @property Carbon|null $started_at
* @property Carbon|null $finished_at
* @property int $max_participants
* @property string $place
* @property string $program
* @property string $image_path
* @property Carbon $created_at
* @property Carbon $updated_at
* @property object $agenda
* @property string $status
*/
class StationaryEvent extends Model
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace EscolaLms\StationaryEvents\Repositories\Contracts;

use EscolaLms\Core\Repositories\Contracts\BaseRepositoryContract;
use Illuminate\Database\Eloquent\Builder;

interface StationaryEventRepositoryContract
interface StationaryEventRepositoryContract extends BaseRepositoryContract
{
public function forCurrentUser(array $criteria = []): Builder;
public function allQueryBuilder(array $criteria = []): Builder;
}
14 changes: 14 additions & 0 deletions src/Repositories/Criteria/Primitives/OrderCriterion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace EscolaLms\StationaryEvents\Repositories\Criteria\Primitives;

use EscolaLms\Core\Repositories\Criteria\Criterion;
use Illuminate\Database\Eloquent\Builder;

class OrderCriterion extends Criterion
{
public function apply(Builder $query): Builder
{
return $query->orderBy($this->key, $this->value);
}
}
5 changes: 4 additions & 1 deletion src/Services/StationaryEventService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use EscolaLms\Core\Repositories\Criteria\Primitives\InCriterion;
use EscolaLms\Core\Repositories\Criteria\Primitives\LikeCriterion;
use EscolaLms\Core\Repositories\Criteria\Primitives\WhereCriterion;
use EscolaLms\Courses\Repositories\Criteria\Primitives\OrderCriterion;
use EscolaLms\Files\Helpers\FileHelper;
use EscolaLms\StationaryEvents\Enum\ConstantEnum;
use EscolaLms\StationaryEvents\Enum\StationaryEventStatusEnum;
Expand All @@ -20,6 +19,7 @@
use EscolaLms\StationaryEvents\Events\StationaryEventUnassigned;
use EscolaLms\StationaryEvents\Models\StationaryEvent;
use EscolaLms\StationaryEvents\Repositories\Contracts\StationaryEventRepositoryContract;
use EscolaLms\StationaryEvents\Repositories\Criteria\Primitives\OrderCriterion;
use EscolaLms\StationaryEvents\Services\Contracts\StationaryEventServiceContract;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\UploadedFile;
Expand Down Expand Up @@ -59,6 +59,7 @@ public function getStationaryEventListForCurrentUser(OrderDto $orderDto, array $

public function create(array $data): StationaryEvent
{
/** @var StationaryEvent $stationaryEvent */
$stationaryEvent = $this->stationaryEventRepository->create($data);
$this->syncAuthors($stationaryEvent, $data['authors'] ?? []);

Expand All @@ -80,6 +81,7 @@ public function update(StationaryEvent $stationaryEvent, array $data): Stationar
$data['image_path'] = FileHelper::getFilePath($data['image'], ConstantEnum::DIRECTORY . '/' . $stationaryEvent->getKey() . '/images');
}

/** @var StationaryEvent $stationaryEvent */
$stationaryEvent = $this->stationaryEventRepository->update($data, $stationaryEvent->getKey());
$this->syncAuthors($stationaryEvent, $data['authors'] ?? []);

Expand Down Expand Up @@ -122,6 +124,7 @@ private function dispatchEventForUsersAttachedToStationaryEvent(StationaryEvent
}
}

// @phpstan-ignore-next-line
private function dispatchEventForUsersDetachedToStationaryEvent(StationaryEvent $stationaryEvent, array $users = []): void
{
foreach ($users as $detached) {
Expand Down
6 changes: 3 additions & 3 deletions src/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

// admin endpoints
Route::group(['middleware' => ['auth:api'], 'prefix' => 'api/admin/stationary-events'], function () {
Route::get(null, [StationaryEventAdminApiController::class, 'index']);
Route::post(null, [StationaryEventAdminApiController::class, 'store']);
Route::get('', [StationaryEventAdminApiController::class, 'index']);
Route::post('', [StationaryEventAdminApiController::class, 'store']);
Route::put('{id}', [StationaryEventAdminApiController::class, 'update']);
Route::get('{id}', [StationaryEventAdminApiController::class, 'show']);
Route::delete('{id}', [StationaryEventAdminApiController::class, 'delete']);
Expand All @@ -20,6 +20,6 @@

// public routes
Route::group(['prefix' => 'api/stationary-events'], function () {
Route::get(null, [StationaryEventApiController::class, 'index']);
Route::get('', [StationaryEventApiController::class, 'index']);
Route::get('{id}', [StationaryEventApiController::class, 'show']);
});
Loading