Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
szepeviktor committed Oct 25, 2023
1 parent fc372da commit 0e5e5e1
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 6 deletions.
4 changes: 1 addition & 3 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ parameters:
- database/migrations/
- vendor/orchestra/testbench-core/laravel/migrations/
scanFiles:
- tests/phpstan/FieldWithRoute.php
- tests/phpstan/MetaDataModel.php
paths:
- src/
Expand All @@ -28,9 +29,6 @@ parameters:
ignoreErrors:
- '#^Unsafe usage of new static#'
# --- TODO-s ---
# Tricky readonlys
- '#Assign it in the constructor\.$#'
- '#is assigned outside of the constructor\.$#'
# X vs. X contract
- '#but returns Illuminate\\Contracts\\#'
# SoftDeletes
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
2 changes: 1 addition & 1 deletion src/Fields/Meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Meta extends MorphOne
public function __construct(string $label, string $modelAttribute = null, Closure|string $relation = null)
{
$relation ??= function (Model $model): EloquentRelation {
/** @phpstan-var \App\Models\MetaDataModel $model */
/** @phpstan-var \Tests\MetaDataModel $model */

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

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;
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 @@ 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');

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

// 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
6 changes: 6 additions & 0 deletions src/Models/Medium.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,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 @@ -184,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 @@ -204,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
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
2 changes: 2 additions & 0 deletions src/Traits/AsRootUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public function rootNotifications(): MorphMany

/**
* Get the avatar attribute.
*
* @return \Illuminate\Database\Eloquent\Casts\Attribute<string|null, never>
*/
protected function avatar(): Attribute
{
Expand Down
16 changes: 16 additions & 0 deletions tests/phpstan/FieldWithRoute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Tests;

use Cone\Root\Fields\Field;
use Cone\Root\Traits\RegistersRoutes;

class FieldWithRoute extends Field
{
use RegistersRoutes;

/**
* The Blade template.
*/
protected string $template = 'field.with.route';
}
2 changes: 1 addition & 1 deletion tests/phpstan/MetaDataModel.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Models;
namespace Tests;

use Cone\Root\Traits\HasMetaData;
use Illuminate\Database\Eloquent\Model;
Expand Down

0 comments on commit 0e5e5e1

Please sign in to comment.