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 15 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
23 changes: 22 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
includes:
- vendor/nunomaduro/larastan/extension.neon
# - phpstan-baseline.neon
parameters:
databaseMigrationsPath:
- database/migrations/
- vendor/orchestra/testbench-core/laravel/migrations/
scanFiles:
- tests/phpstan/FieldWithRoute.php
- tests/phpstan/MetaDataModel.php
paths:
- src/
- config/
- database/
# TODO
# - 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#'
# --- TODO-s ---
# X vs. X contract
- '#but returns Illuminate\\Contracts\\#'
# 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 @@ -6,6 +6,11 @@
use Illuminate\Database\Eloquent\Relations\BelongsTo as EloquentRelation;
use Illuminate\Http\Request;

/**
* @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 @@ -9,6 +9,11 @@
use Illuminate\Http\Request;
use Illuminate\Support\Arr;

/**
* @template TRelation of \Illuminate\Database\Eloquent\Relations\BelongsToMany
*
* @extends \Cone\Root\Fields\Relation<TRelation>
*/
class BelongsToMany extends Relation
{
use ResolvesFields;
Expand Down
1 change: 1 addition & 0 deletions src/Fields/Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function registerRoutes(Request $request, Router $router): void
$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
8 changes: 7 additions & 1 deletion src/Fields/File.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php

Check warning on line 1 in src/Fields/File.php

View workflow job for this annotation

GitHub Actions / 4️⃣ Coding Standards

Found violation(s) of type: unary_operator_spaces

Check warning on line 1 in src/Fields/File.php

View workflow job for this annotation

GitHub Actions / 4️⃣ Coding Standards

Found violation(s) of type: not_operator_with_successor_space

Check warning on line 1 in src/Fields/File.php

View workflow job for this annotation

GitHub Actions / 4️⃣ Coding Standards

Found violation(s) of type: no_blank_lines_after_phpdoc

namespace Cone\Root\Fields;

Expand Down Expand Up @@ -158,7 +158,9 @@
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 @@ -224,6 +226,8 @@
*/
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 @@ -235,6 +239,8 @@

$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 @@ -7,6 +7,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
5 changes: 5 additions & 0 deletions src/Fields/Meta.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php

Check warning on line 1 in src/Fields/Meta.php

View workflow job for this annotation

GitHub Actions / 4️⃣ Coding Standards

Found violation(s) of type: unary_operator_spaces

Check warning on line 1 in src/Fields/Meta.php

View workflow job for this annotation

GitHub Actions / 4️⃣ Coding Standards

Found violation(s) of type: not_operator_with_successor_space

Check warning on line 1 in src/Fields/Meta.php

View workflow job for this annotation

GitHub Actions / 4️⃣ Coding Standards

Found violation(s) of type: no_blank_lines_after_phpdoc

namespace Cone\Root\Fields;

Expand All @@ -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,8 @@
public function __construct(string $label, string $modelAttribute = null, Closure|string $relation = null)
{
$relation ??= function (Model $model): EloquentRelation {
/** @phpstan-var \Tests\MetaDataModel $model */

$related = $model->metaData()->getRelated();

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 @@ -5,6 +5,9 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphTo as EloquentRelation;

/**
* @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 @@ -5,6 +5,9 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphToMany as EloquentRelation;

/**
* @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 @@ -10,6 +10,9 @@
use Illuminate\Support\Collection;
use Illuminate\Support\Str;

/**
* @template TRelation of \Illuminate\Database\Eloquent\Relations\Relation
*/
abstract class Relation extends Field
{
/**
Expand Down Expand Up @@ -67,6 +70,8 @@ public static function scopeQuery(Closure $callback): void

/**
* Get the relation instance.
*
* @phpstan-return TRelation
*/
public function getRelation(Model $model): EloquentRelation
{
Expand Down
1 change: 1 addition & 0 deletions src/Fields/Slug.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Closure;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
szepeviktor marked this conversation as resolved.
Show resolved Hide resolved
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Illuminate\Validation\Rule;
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 @@
*/
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');

// Gate::allowIf($field->authorized($request, $model));
Expand All @@ -23,10 +25,10 @@
? $resource->resolveRouteBinding($request, $request->input('model'))
: $resource->getModelInstance();

return match ($request->method()) {

Check failure on line 28 in src/Http/Controllers/MediaController.php

View workflow job for this annotation

GitHub Actions / 3️⃣ Static Analysis

Match expression does not handle remaining value: string
'GET' => new JsonResponse($field->paginate($request, $model)),
'POST' => new JsonResponse($field->upload($request, $model), JsonResponse::HTTP_CREATED),
'DELETE' => new JsonResponse(['deleted' => $field->prune($request, $model, $request->input('ids', []))]),

Check failure on line 31 in src/Http/Controllers/MediaController.php

View workflow job for this annotation

GitHub Actions / 3️⃣ Static Analysis

Call to protected method prune() of class Cone\Root\Fields\File.
};
}
}
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');

// Gate::allowIf($field->authorized($request, $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('rootWidget');

Gate::allowIf($widget->authorized($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 @@ -152,6 +152,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 @@ -164,6 +166,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 @@ -182,6 +186,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 @@ -202,6 +208,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 @@ -54,6 +54,8 @@ public static function getProxiedInterface(): string

/**
* Get the subject attribute.
*
* @return \Illuminate\Database\Eloquent\Casts\Attribute<string|null, never>
*/
protected function subject(): Attribute
{
Expand All @@ -64,6 +66,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 @@ -74,6 +78,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 @@ -84,6 +90,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
5 changes: 4 additions & 1 deletion src/RootServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ protected function registerRoutes(): void
});

$this->app['router']->bind('resourceModel', function (string $id, Route $route): Model {
return $route->parameter('resource')->resolveRouteBinding($this->app['request'], $id);
/** @var \Cone\Root\Resources\Resource $resource */
$resource = $route->parameter('resource');

return $resource->resolveRouteBinding($this->app['request'], $id);
});

$this->app['router']
Expand Down
Loading
Loading