diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..8aee1ef --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,30 @@ +name: Fix Code Style + +on: [push] + +jobs: + lint: + runs-on: ubuntu-latest + strategy: + fail-fast: true + matrix: + php: [8.4] + + steps: + - name: Checkout code + uses: actions/checkout@v5 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + tools: pint + + - name: Run Pint + run: pint + + - name: Commit linted files + uses: stefanzweifel/git-auto-commit-action@v6 + + - name: Run Larastan + run: ./vendor/bin/phpstan analyse diff --git a/app/Http/Controllers/V1/SuggestionController.php b/app/Http/Controllers/V1/SuggestionController.php index 4fbc8ef..4cbbf58 100644 --- a/app/Http/Controllers/V1/SuggestionController.php +++ b/app/Http/Controllers/V1/SuggestionController.php @@ -28,11 +28,6 @@ public function store(Trip $trip, SuggestionRequest $suggestionRequest): Redirec return redirect()->route('trips.show', ['trip' => $trip]); } - /** - * @param Suggestion $suggestion - * @param Request $request - * @return RedirectResponse - */ public function vote(Suggestion $suggestion, Request $request): RedirectResponse { $validated = $request->validate([ diff --git a/app/Http/Controllers/V1/TripController.php b/app/Http/Controllers/V1/TripController.php index c3090ea..e10b3ab 100644 --- a/app/Http/Controllers/V1/TripController.php +++ b/app/Http/Controllers/V1/TripController.php @@ -18,20 +18,17 @@ class TripController extends Controller /** * Display a listing of the resource. */ - public function index() + public function index(): View { - $user = auth()->user()->load(['owns', 'trips']); $trips = [ 'owns' => $user->owns, - 'invited' => $user->trips + 'invited' => $user->trips, ]; return view('trips.index', compact('trips')); - // trips im associated with - } /** @@ -40,9 +37,10 @@ public function index() public function create(): View { // - $users = Cache::remember('listableUsers',3600 , function () { - return User::get(['id','name']); + $users = Cache::remember('listableUsers', 3600, function () { + return User::get(['id', 'name']); }); + return view('trips.create', compact('users')); } @@ -51,7 +49,6 @@ public function create(): View */ public function store(TripRequest $tripRequest): RedirectResponse { - // $trip = auth()->user()->owns()->create($tripRequest->validated()); $trip->users()->attach($tripRequest->users); @@ -88,8 +85,8 @@ public function edit(Trip $trip): View // Gate::authorize('update', $trip); $trip = $trip->load('users:id,name'); - $users = Cache::remember('listableUsers',3600 , function () { - return User::get(['id','name']); + $users = Cache::remember('listableUsers', 3600, function () { + return User::get(['id', 'name']); }); return view('trips.edit', compact('trip', 'users')); diff --git a/app/Models/Suggestion.php b/app/Models/Suggestion.php index 7902ead..7aadbb5 100644 --- a/app/Models/Suggestion.php +++ b/app/Models/Suggestion.php @@ -14,16 +14,25 @@ class Suggestion extends Model protected $fillable = ['description', 'status', 'user_id']; + /** + * @return BelongsTo + */ public function User(): BelongsTo { return $this->belongsTo(User::class); } + /** + * @return BelongsTo + */ public function Trip(): BelongsTo { return $this->belongsTo(Trip::class); } + /** + * @return HasMany + */ public function Vote(): HasMany { return $this->hasMany(Vote::class); diff --git a/app/Models/Trip.php b/app/Models/Trip.php index 58bfc75..b681ec0 100644 --- a/app/Models/Trip.php +++ b/app/Models/Trip.php @@ -20,6 +20,8 @@ class Trip extends Model /** * A trip belongs to its creator + * + * @return BelongsTo */ public function owner(): BelongsTo { @@ -27,7 +29,9 @@ public function owner(): BelongsTo } /** - * @return HasMany + * A trip belongs to its creator + * + * @return HasMany */ public function suggestions(): HasMany { @@ -35,7 +39,7 @@ public function suggestions(): HasMany } /** - * @return BelongsToMany + * @return BelongsToMany */ public function users(): BelongsToMany { diff --git a/app/Models/User.php b/app/Models/User.php index c08cc7f..8725299 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -52,24 +52,32 @@ protected function casts(): array /** * Creator can own many trips + * + * @return HasMany */ public function owns(): HasMany { return $this->hasMany(Trip::class, 'owner_id'); } + /** + * @return HasMany + */ public function suggestions(): HasMany { return $this->hasMany(Suggestion::class); } + /** + * @return HasMany + */ public function votes(): HasMany { return $this->hasMany(Vote::class); } /** - * @return BelongsToMany + * @return BelongsToMany */ public function trips(): BelongsToMany { diff --git a/app/Models/Vote.php b/app/Models/Vote.php index a568bb0..26a8990 100644 --- a/app/Models/Vote.php +++ b/app/Models/Vote.php @@ -10,11 +10,17 @@ class Vote extends Model // protected $fillable = ['type', 'user_id']; + /** + * @return BelongsTo + */ public function User(): BelongsTo { return $this->belongsTo(User::class); } + /** + * @return BelongsTo + */ public function Suggestion(): BelongsTo { return $this->belongsTo(Suggestion::class); diff --git a/composer.json b/composer.json index 97ede1d..0103a7f 100644 --- a/composer.json +++ b/composer.json @@ -17,6 +17,7 @@ "require-dev": { "barryvdh/laravel-debugbar": "^3.16", "fakerphp/faker": "^1.23", + "larastan/larastan": "^3.7", "laravel/pail": "^1.2.2", "laravel/pint": "^1.25", "laravel/sail": "^1.41", diff --git a/composer.lock b/composer.lock index d140ea0..7ef2e7b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "0c9a1edcf832e39a979cf7c73bc7e962", + "content-hash": "7ef754c0d5d29d962af1332e759084f9", "packages": [ { "name": "brick/math", @@ -6633,6 +6633,47 @@ }, "time": "2025-04-30T06:54:44+00:00" }, + { + "name": "iamcal/sql-parser", + "version": "v0.6", + "source": { + "type": "git", + "url": "https://github.com/iamcal/SQLParser.git", + "reference": "947083e2dca211a6f12fb1beb67a01e387de9b62" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/iamcal/SQLParser/zipball/947083e2dca211a6f12fb1beb67a01e387de9b62", + "reference": "947083e2dca211a6f12fb1beb67a01e387de9b62", + "shasum": "" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^1.0", + "phpunit/phpunit": "^5|^6|^7|^8|^9" + }, + "type": "library", + "autoload": { + "psr-4": { + "iamcal\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Cal Henderson", + "email": "cal@iamcal.com" + } + ], + "description": "MySQL schema parser", + "support": { + "issues": "https://github.com/iamcal/SQLParser/issues", + "source": "https://github.com/iamcal/SQLParser/tree/v0.6" + }, + "time": "2025-03-17T16:59:46+00:00" + }, { "name": "jean85/pretty-package-versions", "version": "2.1.1", @@ -6693,6 +6734,95 @@ }, "time": "2025-03-19T14:43:43+00:00" }, + { + "name": "larastan/larastan", + "version": "v3.7.2", + "source": { + "type": "git", + "url": "https://github.com/larastan/larastan.git", + "reference": "a761859a7487bd7d0cb8b662a7538a234d5bb5ae" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/larastan/larastan/zipball/a761859a7487bd7d0cb8b662a7538a234d5bb5ae", + "reference": "a761859a7487bd7d0cb8b662a7538a234d5bb5ae", + "shasum": "" + }, + "require": { + "ext-json": "*", + "iamcal/sql-parser": "^0.6.0", + "illuminate/console": "^11.44.2 || ^12.4.1", + "illuminate/container": "^11.44.2 || ^12.4.1", + "illuminate/contracts": "^11.44.2 || ^12.4.1", + "illuminate/database": "^11.44.2 || ^12.4.1", + "illuminate/http": "^11.44.2 || ^12.4.1", + "illuminate/pipeline": "^11.44.2 || ^12.4.1", + "illuminate/support": "^11.44.2 || ^12.4.1", + "php": "^8.2", + "phpstan/phpstan": "^2.1.28" + }, + "require-dev": { + "doctrine/coding-standard": "^13", + "laravel/framework": "^11.44.2 || ^12.7.2", + "mockery/mockery": "^1.6.12", + "nikic/php-parser": "^5.4", + "orchestra/canvas": "^v9.2.2 || ^10.0.1", + "orchestra/testbench-core": "^9.12.0 || ^10.1", + "phpstan/phpstan-deprecation-rules": "^2.0.1", + "phpunit/phpunit": "^10.5.35 || ^11.5.15" + }, + "suggest": { + "orchestra/testbench": "Using Larastan for analysing a package needs Testbench" + }, + "type": "phpstan-extension", + "extra": { + "phpstan": { + "includes": [ + "extension.neon" + ] + }, + "branch-alias": { + "dev-master": "3.0-dev" + } + }, + "autoload": { + "psr-4": { + "Larastan\\Larastan\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Can Vural", + "email": "can9119@gmail.com" + } + ], + "description": "Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel", + "keywords": [ + "PHPStan", + "code analyse", + "code analysis", + "larastan", + "laravel", + "package", + "php", + "static analysis" + ], + "support": { + "issues": "https://github.com/larastan/larastan/issues", + "source": "https://github.com/larastan/larastan/tree/v3.7.2" + }, + "funding": [ + { + "url": "https://github.com/canvural", + "type": "github" + } + ], + "time": "2025-09-19T09:03:05+00:00" + }, { "name": "laravel/pail", "version": "v1.2.3", @@ -8018,6 +8148,64 @@ }, "time": "2025-08-30T15:50:23+00:00" }, + { + "name": "phpstan/phpstan", + "version": "2.1.29", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan-phar-composer-source.git", + "reference": "git" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/d618573eed4a1b6b75e37b2e0b65ac65c885d88e", + "reference": "d618573eed4a1b6b75e37b2e0b65ac65c885d88e", + "shasum": "" + }, + "require": { + "php": "^7.4|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", + "issues": "https://github.com/phpstan/phpstan/issues", + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + } + ], + "time": "2025-09-25T06:58:18+00:00" + }, { "name": "phpunit/php-code-coverage", "version": "12.4.0", diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..e7748c3 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,17 @@ +includes: + - vendor/larastan/larastan/extension.neon + - vendor/nesbot/carbon/extension.neon + +parameters: + + paths: + - app/ + + # Level 10 is the highest level + level: 6 + +# ignoreErrors: +# - '#PHPDoc tag @var#' +# + excludePaths: + - app/Http/Controllers/Auth