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

Prepare PHPStan #165

Merged
merged 27 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9897377
Prepare PHPStan
szepeviktor Oct 15, 2023
27eaa63
Fix many problems
szepeviktor Oct 16, 2023
277d790
Fix CS
szepeviktor Oct 16, 2023
a9dddb9
Rebase
szepeviktor Oct 21, 2023
2ececb0
fix
szepeviktor Oct 21, 2023
f3886e1
fix
szepeviktor Oct 21, 2023
ef11498
fix
szepeviktor Oct 21, 2023
44f79d4
fix
szepeviktor Oct 21, 2023
355215f
fix
szepeviktor Oct 21, 2023
a7703fb
Prepare PHPStan
szepeviktor Oct 21, 2023
9b34faf
Merge branch 'master' into prepare-phpstan
szepeviktor Oct 25, 2023
99119d4
wip
szepeviktor Oct 25, 2023
fc372da
Merge branch 'master' into prepare-phpstan
szepeviktor Oct 25, 2023
0e5e5e1
fix
szepeviktor Oct 25, 2023
2e05b5b
Merge branch 'prepare-phpstan' of github.com:conedevelopment/root int…
szepeviktor Oct 25, 2023
391ff93
Fix CS
szepeviktor Oct 25, 2023
85330e1
fix
szepeviktor Oct 25, 2023
f1bfb8f
Remove TODO-s
szepeviktor Oct 25, 2023
72dc07b
comment out baseline
szepeviktor Oct 25, 2023
1d12b19
Merge branch 'master' into prepare-phpstan
szepeviktor Nov 4, 2023
0c9702d
Merge remote-tracking branch 'origin/master' into prepare-phpstan
szepeviktor Nov 11, 2023
5e9ef2d
Merge branch 'master' into prepare-phpstan
szepeviktor Nov 22, 2023
fffb555
Merge branch 'prepare-phpstan' of github.com:conedevelopment/root int…
szepeviktor Nov 22, 2023
c64d345
Merge branch 'master' into prepare-phpstan
szepeviktor Nov 29, 2023
ab0d023
Merge branch 'master' into prepare-phpstan
szepeviktor Dec 19, 2023
3802c02
Update phpstan.neon.dist
szepeviktor Dec 19, 2023
3b88305
Merge branch 'master' into prepare-phpstan
szepeviktor Jan 17, 2024
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
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/js-tests export-ignore
/phpstan.neon.dist export-ignore
/phpunit.xml.dist export-ignore
/public/build/assets/ linguist-generated
/public/build/assets/** linguist-generated
/tests export-ignore
/yarn.lock export-ignore linguist-generated
/vite.config.js export-ignore
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/back-end.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,12 @@ jobs:
name: "Search for $this->$this typo 🐌"
run: |
! git grep --line-number -e '\$this\s*->\s*\$this' -- ':!:*/back-end\.yml'
-
name: "Install orchestra/testbench"
run: "composer require --dev orchestra/testbench"
-
name: "Perform static analysis"
run: "true TODO || composer exec -- phpstan analyze --level=5 src/"
run: "composer exec -- phpstan || true 'Annotate only'"

coding_standards:
name: "4️⃣ Coding Standards"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/reusable-integrity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ jobs:
wget --secure-protocol=TLSv1_3 --max-redirect=1 --retry-on-host-error --retry-connrefused --tries=3 \
--no-verbose --output-document="${{ runner.temp }}/cloc/cloc" "${RELEASE_ASSET_URL}"
{
git ls-files -- ':!:LICENSE' ':!:package-lock.json' >"${{ runner.temp }}/cloc/include-list"
git ls-files -- ':!:LICENSE' ':!:yarn.lock' >"${{ runner.temp }}/cloc/include-list"
echo '```'
perl "${{ runner.temp }}/cloc/cloc" --hide-rate \
--list-file="${{ runner.temp }}/cloc/include-list" \
Expand Down
2 changes: 1 addition & 1 deletion database/factories/MediumFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MediumFactory extends Factory
/**
* The name of the factory's corresponding model.
*
* @var string
* @var class-string<\Cone\Root\Models\Medium>
*/
protected $model = Medium::class;

Expand Down
2 changes: 1 addition & 1 deletion database/factories/MetaFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class MetaFactory extends Factory
/**
* The name of the factory's corresponding model.
*
* @var string
* @var class-string<\Cone\Root\Models\Meta>
*/
protected $model = Meta::class;

Expand Down
2 changes: 1 addition & 1 deletion database/factories/NotificationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class NotificationFactory extends Factory
/**
* The name of the factory's corresponding model.
*
* @var string
* @var class-string<\Cone\Root\Models\Notification>
*/
protected $model = Notification::class;

Expand Down
18 changes: 18 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,29 @@ parameters:
databaseMigrationsPath:
- database/migrations/
- vendor/orchestra/testbench-core/laravel/migrations/
scanFiles:
- tests/phpstan/FieldWithRoute.php
- tests/phpstan/MetaDataModel.php
paths:
- src/
- config/
- database/
- routes/
level: 5
checkAlwaysTrueCheckTypeFunctionCall: true
checkAlwaysTrueInstanceof: true
checkAlwaysTrueStrictComparison: true
checkAlwaysTrueLooseComparison: true
checkClassCaseSensitivity: false
checkDynamicProperties: true
checkExplicitMixed: false
checkImplicitMixed: false
checkExplicitMixedMissingReturn: true
checkFunctionNameCase: true
checkInternalClassCaseSensitivity: true
ignoreErrors:
- '#^Unsafe usage of new static#'
# Illuminate\View\View vs. Illuminate\Contracts\View\View
- '#^Method Cone\\\S+::render\(\) should return Illuminate\\View\\View but returns Illuminate\\Contracts\\View\\View\.$#'
# SoftDeletes
- '#(\$forceDeleting|::withTrashed|::onlyTrashed|::trashed|::restore)#'
5 changes: 5 additions & 0 deletions src/Fields/BelongsTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
use Illuminate\Http\Request;
use Illuminate\Routing\Router;

/**
* @template TRelation of \Illuminate\Database\Eloquent\Relations\BelongsTo
*
* @extends \Cone\Root\Fields\Relation<TRelation>
*/
class BelongsTo extends Relation
{
/**
Expand Down
5 changes: 5 additions & 0 deletions src/Fields/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
use Illuminate\Routing\Router;
use Illuminate\Support\Arr;

/**
* @template TRelation of \Illuminate\Database\Eloquent\Relations\BelongsToMany
*
* @extends \Cone\Root\Fields\Relation<TRelation>
*/
class BelongsToMany extends Relation
{
/**
Expand Down Expand Up @@ -195,7 +200,7 @@
*/
public function resolveRouteBinding(Request $request, string $id): Model
{
$relation = $this->getRelation($request->route()->parentOfParameter($this->getRouteKeyName()));

Check failure on line 203 in src/Fields/BelongsToMany.php

View workflow job for this annotation

GitHub Actions / 3️⃣ Static Analysis

Parameter #1 $model of method Cone\Root\Fields\BelongsToMany<TRelation of Illuminate\Database\Eloquent\Relations\BelongsToMany>::getRelation() expects Illuminate\Database\Eloquent\Model, string given.

$related = $relation->wherePivot($relation->newPivot()->getQualifiedKeyName(), $id)->firstOrFail();

Expand Down
1 change: 1 addition & 0 deletions src/Fields/Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
*/
public function authorized(Request $request, ?Model $model = null): static
{
return $this->filter->authorized($request, $model)->values();

Check failure on line 43 in src/Fields/Fields.php

View workflow job for this annotation

GitHub Actions / 3️⃣ Static Analysis

Method Cone\Root\Fields\Fields::authorized() should return static(Cone\Root\Fields\Fields) but returns Cone\Root\Fields\Fields.
}

/**
Expand All @@ -48,7 +48,7 @@
*/
public function visible(string|array $context): static
{
return $this->filter->visible($context)->values();

Check failure on line 51 in src/Fields/Fields.php

View workflow job for this annotation

GitHub Actions / 3️⃣ Static Analysis

Method Cone\Root\Fields\Fields::visible() should return static(Cone\Root\Fields\Fields) but returns Cone\Root\Fields\Fields.
}

/**
Expand All @@ -56,7 +56,7 @@
*/
public function searchable(): static
{
return $this->filter->isSearchable();

Check failure on line 59 in src/Fields/Fields.php

View workflow job for this annotation

GitHub Actions / 3️⃣ Static Analysis

Method Cone\Root\Fields\Fields::searchable() should return static(Cone\Root\Fields\Fields) but returns Cone\Root\Fields\Fields.
}

/**
Expand All @@ -64,7 +64,7 @@
*/
public function sortable(): static
{
return $this->filter->isSortable();

Check failure on line 67 in src/Fields/Fields.php

View workflow job for this annotation

GitHub Actions / 3️⃣ Static Analysis

Method Cone\Root\Fields\Fields::sortable() should return static(Cone\Root\Fields\Fields) but returns Cone\Root\Fields\Fields.
}

/**
Expand Down Expand Up @@ -123,6 +123,7 @@
$router->prefix('fields')->group(function (Router $router) use ($request): void {
$this->each(static function (Field $field) use ($request, $router): void {
if (in_array(RegistersRoutes::class, class_uses_recursive($field))) {
/** @var \Tests\FieldWithRoute $field */
$field->registerRoutes($request, $router);
}
});
Expand Down
7 changes: 6 additions & 1 deletion src/Fields/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ protected function stored(Request $request, Model $model, string $path): array
call_user_func_array($this->storageResolver, [$request, $medium, $path]);
}

$request->user()->uploads()->save($medium);
/** @var \Illuminate\Foundation\Auth\User&\Cone\Root\Interfaces\Models\User $user */
$user = $request->user();
$user->uploads()->save($medium);

MoveFile::withChain($medium->convertible() ? [new PerformConversions($medium)] : [])
->dispatch($medium, $path, false);
Expand Down Expand Up @@ -234,6 +236,7 @@ public function prune(Request $request, Model $model, array $keys): int
*/
public function toOption(Request $request, Model $model, Model $related): array
{
/** @var \Cone\Root\Models\Medium $related */
$option = parent::toOption($request, $model, $related);

$name = sprintf(
Expand All @@ -245,6 +248,8 @@ public function toOption(Request $request, Model $model, Model $related): array

$option['attrs']->merge(['name' => $name]);

/** @var \Cone\Root\Models\Medium $related */

return array_merge($option, [
'fileName' => $related->file_name,
'isImage' => $related->isImage,
Expand Down
3 changes: 3 additions & 0 deletions src/Fields/HasMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany as EloquentRelation;

/**
* @extends \Cone\Root\Fields\HasOneOrMany<\Illuminate\Database\Eloquent\Relations\HasMany>
*/
class HasMany extends HasOneOrMany
{
/**
Expand Down
3 changes: 3 additions & 0 deletions src/Fields/HasOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasOne as EloquentRelation;

/**
* @extends \Cone\Root\Fields\HasOneOrMany<\Illuminate\Database\Eloquent\Relations\HasOne>
*/
class HasOne extends HasOneOrMany
{
/**
Expand Down
5 changes: 5 additions & 0 deletions src/Fields/HasOneOrMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
use Illuminate\Http\Request;
use Illuminate\Support\Arr;

/**
* @template TRelation of \Illuminate\Database\Eloquent\Relations\HasOneOrMany
*
* @extends \Cone\Root\Fields\Relation<TRelation>
*/
abstract class HasOneOrMany extends Relation
{
/**
Expand Down
4 changes: 4 additions & 0 deletions src/Fields/Meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Illuminate\Database\Eloquent\Relations\MorphOne as EloquentRelation;
use Illuminate\Http\Request;

/**
* @extends \Cone\Root\Fields\MorphOne<\Illuminate\Database\Eloquent\Relations\MorphOne>
*/
class Meta extends MorphOne
{
/**
Expand All @@ -21,6 +24,7 @@ class Meta extends MorphOne
public function __construct(string $label, Closure|string|null $modelAttribute = null, Closure|string|null $relation = null)
{
$relation ??= function (Model $model): EloquentRelation {
/** @phpstan-var \Tests\MetaDataModel $model */
$related = $model->metaData()->make();

return $model->metaData()
Expand Down
3 changes: 3 additions & 0 deletions src/Fields/MorphMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphMany as EloquentRelation;

/**
* @extends \Cone\Root\Fields\MorphOneOrMany<\Illuminate\Database\Eloquent\Relations\MorphMany>
*/
class MorphMany extends MorphOneOrMany
{
/**
Expand Down
5 changes: 5 additions & 0 deletions src/Fields/MorphOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphOne as EloquentRelation;

/**
* @template TRelation of \Illuminate\Database\Eloquent\Relations\MorphOne
*
* @extends \Cone\Root\Fields\MorphOneOrMany<TRelation>
*/
class MorphOne extends MorphOneOrMany
{
/**
Expand Down
5 changes: 5 additions & 0 deletions src/Fields/MorphOneOrMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphOneOrMany as EloquentRelation;

/**
* @template TRelation of \Illuminate\Database\Eloquent\Relations\MorphOneOrMany
*
* @extends \Cone\Root\Fields\HasOneOrMany<TRelation>
*/
abstract class MorphOneOrMany extends HasOneOrMany
{
/**
Expand Down
3 changes: 3 additions & 0 deletions src/Fields/MorphTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
use Illuminate\Routing\Router;
use Illuminate\Support\Str;

/**
* @extends \Cone\Root\Fields\BelongsTo<\Illuminate\Database\Eloquent\Relations\MorphTo>
*/
class MorphTo extends BelongsTo
{
/**
Expand Down
3 changes: 3 additions & 0 deletions src/Fields/MorphToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use Illuminate\Database\Eloquent\Relations\MorphToMany as EloquentRelation;
use Illuminate\Http\Request;

/**
* @extends \Cone\Root\Fields\BelongsToMany<\Illuminate\Database\Eloquent\Relations\MorphToMany>
*/
class MorphToMany extends BelongsToMany
{
/**
Expand Down
5 changes: 5 additions & 0 deletions src/Fields/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
use Illuminate\Support\MessageBag;
use Illuminate\Support\Str;

/**
* @template TRelation of \Illuminate\Database\Eloquent\Relations\Relation
*/
abstract class Relation extends Field implements Form
{
use AsForm;
Expand Down Expand Up @@ -118,6 +121,8 @@

/**
* Get the relation instance.
*
* @phpstan-return TRelation
*/
public function getRelation(Model $model): EloquentRelation
{
Expand Down Expand Up @@ -358,7 +363,7 @@
{
if ($this->isSubResource()) {
$field->setAttribute('form', $this->modelAttribute);
$field->resolveErrorsUsing(fn (Request $request): MessageBag => $this->errors($request));

Check failure on line 366 in src/Fields/Relation.php

View workflow job for this annotation

GitHub Actions / 3️⃣ Static Analysis

Anonymous function should return Illuminate\Support\MessageBag but returns Illuminate\Contracts\Support\MessageBag.
} else {
$field->setAttribute('form', $this->getAttribute('form'));
$field->resolveErrorsUsing($this->errorsResolver);
Expand Down Expand Up @@ -555,7 +560,7 @@
*/
public function resolveRouteBinding(Request $request, string $id): Model
{
return $this->getRelation($request->route()->parentOfParameter($this->getRouteKeyName()))->findOrFail($id);

Check failure on line 563 in src/Fields/Relation.php

View workflow job for this annotation

GitHub Actions / 3️⃣ Static Analysis

Call to an undefined method TRelation of Illuminate\Database\Eloquent\Relations\Relation::findOrFail().
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Http/Controllers/ActionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ActionController extends Controller
*/
public function __invoke(Request $request): Response
{
/** @var \Cone\Root\Actions\Action $action */
$action = $request->route('action');

Gate::allowIf($action->authorized($request));
Expand Down
2 changes: 2 additions & 0 deletions src/Http/Controllers/MediaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ class MediaController extends Controller
*/
public function __invoke(Request $request): JsonResponse
{
/** @var \Cone\Root\Resources\Resource $resource */
$resource = $request->route('_resource');

/** @var \Cone\Root\Fields\Media $field */
$field = $request->route('field');

$model = $request->filled('model')
Expand Down
2 changes: 2 additions & 0 deletions src/Http/Controllers/RepeaterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ class RepeaterController extends Controller
*/
public function __invoke(Request $request): JsonResponse
{
/** @var \Cone\Root\Resources\Resource $resource */
$resource = $request->route('_resource');

/** @var \Cone\Root\Fields\Repeater $field */
$field = $request->route('field');

$model = $request->filled('model')
Expand Down
1 change: 1 addition & 0 deletions src/Http/Controllers/WidgetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class WidgetController extends Controller
*/
public function __invoke(Request $request): Response
{
/** @var \Cone\Root\Widgets\Widget $widget */
$widget = $request->route('widget');

$data = $widget->data($request);
Expand Down
8 changes: 8 additions & 0 deletions src/Models/Medium.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ public function user(): BelongsTo

/**
* Determine if the file is image.
*
* @return \Illuminate\Database\Eloquent\Casts\Attribute<bool, never>
*/
protected function isImage(): Attribute
{
Expand All @@ -172,6 +174,8 @@ protected function isImage(): Attribute

/**
* Get the conversion URLs.
*
* @return \Illuminate\Database\Eloquent\Casts\Attribute<array<string, string>, never>
*/
protected function urls(): Attribute
{
Expand All @@ -190,6 +194,8 @@ function (array $urls, string $conversion): array {

/**
* Get the formatted size attribute.
*
* @return \Illuminate\Database\Eloquent\Casts\Attribute<string, never>
*/
protected function formattedSize(): Attribute
{
Expand All @@ -210,6 +216,8 @@ protected function formattedSize(): Attribute

/**
* Get the dimensions attribute.
*
* @return \Illuminate\Database\Eloquent\Casts\Attribute<string|null, never>
*/
protected function dimensions(): Attribute
{
Expand Down
8 changes: 8 additions & 0 deletions src/Models/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public function getMorphClass(): string

/**
* Get the subject attribute.
*
* @return \Illuminate\Database\Eloquent\Casts\Attribute<string|null, never>
*/
protected function subject(): Attribute
{
Expand All @@ -72,6 +74,8 @@ protected function subject(): Attribute

/**
* Get the formatted created at attribute.
*
* @return \Illuminate\Database\Eloquent\Casts\Attribute<string|null, never>
*/
protected function formattedCreatedAt(): Attribute
{
Expand All @@ -82,6 +86,8 @@ protected function formattedCreatedAt(): Attribute

/**
* Get the formatted created at attribute.
*
* @return \Illuminate\Database\Eloquent\Casts\Attribute<bool, never>
*/
protected function isRead(): Attribute
{
Expand All @@ -92,6 +98,8 @@ protected function isRead(): Attribute

/**
* Get the URL attribute.
*
* @return \Illuminate\Database\Eloquent\Casts\Attribute<string|null, never>
*/
protected function url(): Attribute
{
Expand Down
6 changes: 6 additions & 0 deletions src/Navigation/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
use Cone\Root\Traits\Makeable;
use Illuminate\Support\Facades\URL;

/**
* @property string $url
* @property string $label
* @property string $icon
* @property string $group
*/
class Item
{
use HasAttributes;
Expand Down
Loading
Loading