Compare commits

...
Sign in to create a new pull request.

1 commit

Author SHA1 Message Date
Jérémy Munsch
2299fbdca6
Introduce PHPstan 2024-01-19 12:21:15 +01:00
6 changed files with 275 additions and 13 deletions

View file

@ -10,11 +10,11 @@ use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Schema;
/**
* @property string $model Target model.
* @property string $model_id Id of the target model.
* @property string $event Event of this activity (ActivityLogsEventEnum).
* @property string $data Changes.
* @property-read \Illuminate\Support\Carbon $created_at Created date.
* @property string $model Target model.
* @property string $model_id Id of the target model.
* @property \App\Enums\ActivityLogs\ActivityLogsEventEnum $event Event of this activity (ActivityLogsEventEnum).
* @property array $data Changes.
* @property-read \Illuminate\Support\Carbon $created_at Created date.
*
* @property-read \App\Models\User $user User BelongsTo relation.
*/
@ -82,6 +82,7 @@ class ActivityLog extends Model
$activity->model_id = $model->getKey();
$activity->event = $eventEnum;
$activity->data = static::getChangedColumns($activity, $model, $eventEnum);
// @phpstan-ignore-next-line
$activity->created_at = Carbon::now();
$activity->saveOrFail();
}
@ -89,12 +90,12 @@ class ActivityLog extends Model
/**
* Get old, new columns that has changed.
*
* @param \self $activity
* @param self $activity
* @param \Illuminate\Database\Eloquent\Model $model
* @param \App\Enums\ActivityLogs\ActivityLogsEventEnum $eventEnum
* @return array|null
* @return array
*/
public static function getChangedColumns(self $activity, Model $model, ActivityLogsEventEnum $eventEnum): array|null
public static function getChangedColumns(self $activity, Model $model, ActivityLogsEventEnum $eventEnum): array
{
$modelClassName = $activity->model_class;
/** Get type of each fields of the target model */
@ -112,7 +113,7 @@ class ActivityLog extends Model
}
/** Return old, new and type of values changed */
return ($eventEnum === ActivityLogsEventEnum::updated) ?
array_intersect_key($targetModelTypes, $model->getChanges()) : null;
array_intersect_key($targetModelTypes, $model->getChanges()) : [];
}
// * RELATIONS

View file

@ -28,7 +28,7 @@ class InstantWin extends Model
/**
* The relations to eager load on every query.
*
* @var array
* @var array<string>
*/
protected $with = ['prize'];

View file

@ -35,7 +35,7 @@ class Prize extends Model
/**
* The attributes that are mass assignable.
*
* @var array
* @var array<string>
*/
protected $fillable = [
'label',
@ -112,7 +112,7 @@ class Prize extends Model
/**
* HasMany InstantWin relation
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function instantWins(): HasMany
{

View file

@ -34,6 +34,7 @@
"fakerphp/faker": "^1.9.1",
"kitloong/laravel-migrations-generator": "^6.8",
"krlove/eloquent-model-generator": "dev-l10-compatibility",
"larastan/larastan": "^2.8",
"laravel-lang/common": "^4.0",
"laravel/pint": "^1.0",
"laravel/sail": "^1.18",

252
composer.lock generated
View file

@ -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": "fb04367922e600ae7eeebd46aa7521bc",
"content-hash": "fdcb6ee707026003e47658769e512aaf",
"packages": [
{
"name": "axlon/laravel-postal-code-validation",
@ -9595,6 +9595,107 @@
},
"time": "2023-01-30T20:15:06+00:00"
},
{
"name": "larastan/larastan",
"version": "v2.8.1",
"source": {
"type": "git",
"url": "https://github.com/larastan/larastan.git",
"reference": "b7cc6a29c457a7d4f3de90466392ae9ad3e17022"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/larastan/larastan/zipball/b7cc6a29c457a7d4f3de90466392ae9ad3e17022",
"reference": "b7cc6a29c457a7d4f3de90466392ae9ad3e17022",
"shasum": ""
},
"require": {
"ext-json": "*",
"illuminate/console": "^9.52.16 || ^10.28.0 || ^11.0",
"illuminate/container": "^9.52.16 || ^10.28.0 || ^11.0",
"illuminate/contracts": "^9.52.16 || ^10.28.0 || ^11.0",
"illuminate/database": "^9.52.16 || ^10.28.0 || ^11.0",
"illuminate/http": "^9.52.16 || ^10.28.0 || ^11.0",
"illuminate/pipeline": "^9.52.16 || ^10.28.0 || ^11.0",
"illuminate/support": "^9.52.16 || ^10.28.0 || ^11.0",
"php": "^8.0.2",
"phpmyadmin/sql-parser": "^5.8.2",
"phpstan/phpstan": "^1.10.50"
},
"require-dev": {
"nikic/php-parser": "^4.17.1",
"orchestra/canvas": "^7.11.1 || ^8.11.0 || ^9.0.0",
"orchestra/testbench": "^7.33.0 || ^8.13.0 || ^9.0.0",
"phpunit/phpunit": "^9.6.13 || ^10.5"
},
"suggest": {
"orchestra/testbench": "Using Larastan for analysing a package needs Testbench"
},
"type": "phpstan-extension",
"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
},
"phpstan": {
"includes": [
"extension.neon"
]
}
},
"autoload": {
"psr-4": {
"Larastan\\Larastan\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Can Vural",
"email": "can9119@gmail.com"
},
{
"name": "Nuno Maduro",
"email": "enunomaduro@gmail.com"
}
],
"description": "Larastan - Discover bugs in your code without running it. A phpstan/phpstan wrapper 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/v2.8.1"
},
"funding": [
{
"url": "https://www.paypal.com/paypalme/enunomaduro",
"type": "custom"
},
{
"url": "https://github.com/canvural",
"type": "github"
},
{
"url": "https://github.com/nunomaduro",
"type": "github"
},
{
"url": "https://www.patreon.com/nunomaduro",
"type": "patreon"
}
],
"time": "2024-01-08T09:11:17+00:00"
},
{
"name": "laravel-lang/attributes",
"version": "2.5.1",
@ -10666,6 +10767,93 @@
},
"time": "2022-02-21T01:04:05+00:00"
},
{
"name": "phpmyadmin/sql-parser",
"version": "5.8.2",
"source": {
"type": "git",
"url": "https://github.com/phpmyadmin/sql-parser.git",
"reference": "f1720ae19abe6294cb5599594a8a57bc3c8cc287"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpmyadmin/sql-parser/zipball/f1720ae19abe6294cb5599594a8a57bc3c8cc287",
"reference": "f1720ae19abe6294cb5599594a8a57bc3c8cc287",
"shasum": ""
},
"require": {
"php": "^7.2 || ^8.0",
"symfony/polyfill-mbstring": "^1.3",
"symfony/polyfill-php80": "^1.16"
},
"conflict": {
"phpmyadmin/motranslator": "<3.0"
},
"require-dev": {
"phpbench/phpbench": "^1.1",
"phpmyadmin/coding-standard": "^3.0",
"phpmyadmin/motranslator": "^4.0 || ^5.0",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^1.9.12",
"phpstan/phpstan-phpunit": "^1.3.3",
"phpunit/php-code-coverage": "*",
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.5",
"psalm/plugin-phpunit": "^0.16.1",
"vimeo/psalm": "^4.11",
"zumba/json-serializer": "~3.0.2"
},
"suggest": {
"ext-mbstring": "For best performance",
"phpmyadmin/motranslator": "Translate messages to your favorite locale"
},
"bin": [
"bin/highlight-query",
"bin/lint-query",
"bin/tokenize-query"
],
"type": "library",
"autoload": {
"psr-4": {
"PhpMyAdmin\\SqlParser\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"GPL-2.0-or-later"
],
"authors": [
{
"name": "The phpMyAdmin Team",
"email": "developers@phpmyadmin.net",
"homepage": "https://www.phpmyadmin.net/team/"
}
],
"description": "A validating SQL lexer and parser with a focus on MySQL dialect.",
"homepage": "https://github.com/phpmyadmin/sql-parser",
"keywords": [
"analysis",
"lexer",
"parser",
"query linter",
"sql",
"sql lexer",
"sql linter",
"sql parser",
"sql syntax highlighter",
"sql tokenizer"
],
"support": {
"issues": "https://github.com/phpmyadmin/sql-parser/issues",
"source": "https://github.com/phpmyadmin/sql-parser"
},
"funding": [
{
"url": "https://www.phpmyadmin.net/donate/",
"type": "other"
}
],
"time": "2023-09-19T12:34:29+00:00"
},
{
"name": "phpstan/phpdoc-parser",
"version": "1.24.3",
@ -10713,6 +10901,68 @@
},
"time": "2023-11-18T20:15:32+00:00"
},
{
"name": "phpstan/phpstan",
"version": "1.10.56",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan.git",
"reference": "27816a01aea996191ee14d010f325434c0ee76fa"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/27816a01aea996191ee14d010f325434c0ee76fa",
"reference": "27816a01aea996191ee14d010f325434c0ee76fa",
"shasum": ""
},
"require": {
"php": "^7.2|^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"
},
{
"url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan",
"type": "tidelift"
}
],
"time": "2024-01-15T10:43:00+00:00"
},
{
"name": "phpunit/php-code-coverage",
"version": "10.1.8",

10
phpstan.neon Normal file
View file

@ -0,0 +1,10 @@
includes:
- vendor/larastan/larastan/extension.neon
parameters:
paths:
- app/
# Level 9 is the highest level
level: 5