Skip to content

Commit

Permalink
Type fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
adrolli committed Feb 10, 2025
1 parent 719300a commit 2014bf8
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 21 deletions.
5 changes: 5 additions & 0 deletions packages/core/src/Traits/Base/BaseInResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ trait BaseInResource
{
protected static function modifyEloquentQuery(Builder $query): Builder
{
/** @phpstan-ignore-next-line */
if (method_exists(static::class, 'addTaxonomyRelationsToQuery')) {
$query = static::addTaxonomyRelationsToQuery($query);
}
Expand All @@ -35,10 +36,12 @@ public static function getEloquentQuery(): Builder
$query->withoutGlobalScope(SoftDeletingScope::class);
}

/** @phpstan-ignore-next-line */
if (method_exists(static::class, 'applySoftDeleteQuery')) {
$query = static::applySoftDeleteQuery($query);
}

/** @phpstan-ignore-next-line */
if (($currentTab = request()->query('tab')) && method_exists(static::class, 'applyTabQuery')) {
$query = static::applyTabQuery($query, $currentTab);
}
Expand All @@ -65,10 +68,12 @@ public static function getTableQuery(): Builder
: static::getModel()::query();
}

/** @phpstan-ignore-next-line */
if (method_exists(static::class, 'applySoftDeleteQuery')) {
$query = static::applySoftDeleteQuery($query);
}

/** @phpstan-ignore-next-line */
if (($currentTab = request()->query('tab')) && method_exists(static::class, 'applyTabQuery')) {
$query = static::applyTabQuery($query, $currentTab);
}
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/Traits/Publish/SinglePublishInModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public static function getStatusOptions(): array

public function getStatusAttribute(): string
{
/** @phpstan-ignore-next-line */
if (method_exists($this, 'trashed') && $this->trashed()) {
return 'deleted';
}
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/Traits/Taxonomy/TaxonomyInPages.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ protected function refreshTaxonomyFormData(): void

public function refreshFormData(array $attributes = []): void
{
/** @phpstan-ignore-next-line */
if (method_exists($this, 'fillForm')) {
$this->fillForm();
}
Expand Down
1 change: 1 addition & 0 deletions packages/jobs/src/Traits/JobProgress.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function setProgress(int $progress): void
*/
protected function getJobMonitor(): ?JobManager
{
/** @phpstan-ignore-next-line */
if (! property_exists($this, 'job')) {
return null;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/login-link/src/Mail/LoginLinkEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public function __construct(LoginLink $loginLink)

public function build()
{
/** @phpstan-ignore-next-line */
$userId = urlencode(encrypt($this->loginLink->user_id));
/** @phpstan-ignore-next-line */
$url = url(sprintf('/login-link/%s-%s', $userId, $this->loginLink->token));

return $this->subject('Your Login Link')
Expand Down
1 change: 1 addition & 0 deletions packages/press/src/Models/WpBasePost.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ protected function getMeta($key)
$this->load('postMeta');
}

/** @var ?WpPostMeta $meta */
$meta = $this->postMeta->where('meta_key', $key)->first();

return $meta ? $meta->meta_value : null;
Expand Down
14 changes: 9 additions & 5 deletions packages/press/src/Models/WpMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
use Illuminate\Database\Eloquent\Relations\HasMany;
use Override;

/**
* @property string $image_url
* @property mixed $attachment
* @property array $image_sizes
* @property string $asset
*/
class WpMedia extends WpBasePost
{
use HasFactory;
Expand Down Expand Up @@ -52,17 +58,15 @@ public function getAssetAttribute()
$wpslug = config('press.wordpress_slug');
$wpslug = ltrim((string) $wpslug, $wpslug[0]);

// TODO: Check if the file is an image
// TODO: Read wp-config.php to get the upload path

return $file ? asset($wpslug.'/wp-content/uploads/'.$file) : '';
}

public function getImageSizesAttribute()
{
$sizes = $this->postMeta()->where('meta_key', '_wp_attachment_metadata')->first()->meta_value;
/** @var ?WpPostMeta $metadata */
$metadata = $this->postMeta()->where('meta_key', '_wp_attachment_metadata')->first();

return $sizes ? unserialize($sizes)['sizes'] : [];
return $metadata ? unserialize($metadata->meta_value)['sizes'] : [];
}

public function setImageUrlAttribute($value): void
Expand Down
5 changes: 4 additions & 1 deletion packages/press/src/Models/WpUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,10 @@ public function getMeta($key)
$this->load('userMeta');
}

$meta = $this->userMeta->where('meta_key', $key)->first();
/** @var \Illuminate\Database\Eloquent\Collection<\Moox\Press\Models\WpUserMeta> $userMeta */
$userMeta = $this->userMeta;
/** @var ?\Moox\Press\Models\WpUserMeta $meta */
$meta = $userMeta->where('meta_key', $key)->first();

return $meta ? $meta->meta_value : null;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/press/src/Models/WpUserMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* @property int $user_id
* @property string $meta_key
* @property string $meta_value
* @property mixed $meta_value
*/
class WpUserMeta extends Model
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ protected function mutateFormDataBeforeFill(array $data): array

if ($user) {
foreach ($user->userMeta as $meta) {
/** @var \Moox\Press\Models\WpUserMeta $meta */
$data[$meta->meta_key] = $meta->meta_value;
}
}

if ($user->attachment) {
/** @var \Moox\Press\Models\WpMedia $user->attachment */
$data['image_url'] = $user->attachment->image_url;
}

Expand Down Expand Up @@ -79,7 +81,9 @@ protected function afterSave(): void
Log::error('User record is not an instance of WpUser in EditWpUser::afterSave');
}

Event::dispatch('eloquent.updated: '.($this->record !== null ? $this->record::class : self::class), $this->record);
/** @var \Illuminate\Database\Eloquent\Model $record */
$record = $this->record;
Event::dispatch('eloquent.updated: '.$record::class, $record);
}

protected function handleAvatarUpload(WpUser $user, ?string $userAvatarMetaKey): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ protected function mutateFormDataBeforeFill(array $data): array

if ($user) {
foreach ($user->userMeta as $meta) {
/** @var \Moox\Press\Models\WpUserMeta $meta */
$data[$meta->meta_key] = $meta->meta_value;
}
}

if ($user->attachment) {
/** @var \Moox\Press\Models\WpMedia $user->attachment */
$data['image_url'] = $user->attachment->image_url;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ protected function setUp(): void

$token = app('auth.password.broker')->createToken($user);

if (! method_exists($user, 'notify')) {
$userClass = $user::class;

throw new Exception(sprintf('Model [%s] does not have a [notify()] method.', $userClass));
}

$notification = new PasswordResetNotification($token);

$user->notify($notification);
Expand Down
7 changes: 0 additions & 7 deletions packages/security/src/Services/RequestPasswordReset.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use DanHarrin\LivewireRateLimiting\Exceptions\TooManyRequestsException;
use DanHarrin\LivewireRateLimiting\WithRateLimiting;
use Exception;
use Filament\Actions\Action;
use Filament\Actions\ActionGroup;
use Filament\Facades\Filament;
Expand Down Expand Up @@ -73,12 +72,6 @@ public function request(): void
$status = Password::broker(Filament::getAuthPasswordBroker())->sendResetLink(
$data,
function (CanResetPassword $user, string $token): void {
if (! method_exists($user, 'notify')) {
$userClass = $user::class;

throw new Exception(sprintf('Model [%s] does not have a [notify()] method.', $userClass));
}

$notification = new PasswordResetNotification($token);

$user->notify($notification);
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ parameters:
tmpDir: build/phpstan
ignoreErrors:
- "#Called 'env' outside of the config directory which returns null when the config is cached, use 'config'#"
- "#Trait .+ is used zero times and is not analysed.#"

0 comments on commit 2014bf8

Please sign in to comment.