Skip to content

Commit

Permalink
[15.0] Replace types (#2945)
Browse files Browse the repository at this point in the history
* Replace types from doc in Layouts

* Replace types from doc in Layouts

* Replace types from doc in Fields and Actions

* Replace types from doc in Contracts

* Replace types from doc in Concerns

* Replace types from doc in Screen directory classes

* Fixed width (added float type)

* Added types in Sortable.php

* change self => static

* change Groupable => static
  • Loading branch information
bald-cat authored Jan 27, 2025
1 parent 3649762 commit c889e49
Show file tree
Hide file tree
Showing 92 changed files with 613 additions and 1,394 deletions.
4 changes: 4 additions & 0 deletions src/Attachment/Models/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Orchid\Attachment\Models;

use Exception;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
Expand All @@ -21,6 +22,9 @@

/**
* Class Attachment.
*
* @method static Builder|static whereIn(string $column, array $values)
* @method static static|null find(mixed $id, array $columns = ['*'])
*/
class Attachment extends Model
{
Expand Down
10 changes: 6 additions & 4 deletions src/Platform/Concerns/Sortable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Orchid\Platform\Concerns;

use Illuminate\Database\Eloquent\Builder;

trait Sortable
{
/**
Expand Down Expand Up @@ -43,12 +45,12 @@ public function setSortColumn(int $sortOrder): static
/**
* Scope a query to sort the results by the sort column.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $direction The sorting direction (ASC or DESC). Default is ASC.
* @param Builder $query
* @param string $direction The sorting direction (ASC or DESC). Default is ASC.
*
* @return \Illuminate\Database\Eloquent\Builder
* @return Builder
*/
public function scopeSorted($query, $direction = 'ASC')
public function scopeSorted(Builder $query, string $direction = 'ASC'): Builder
{
$column = $this->getSortColumnName();

Expand Down
2 changes: 1 addition & 1 deletion src/Platform/Http/Layouts/NotificationTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class NotificationTable extends Table
*
* @var string
*/
public $target = 'notifications';
public string $target = 'notifications';

/**
* @return TD[]
Expand Down
26 changes: 10 additions & 16 deletions src/Screen/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,22 @@

namespace Orchid\Screen;

use Illuminate\Contracts\View\View;
use Orchid\Screen\Contracts\Actionable;
use Orchid\Support\Color;
use Closure;

class Action extends Field implements Actionable
{
/**
* Override the form view.
*
* @var string
*/
protected $typeForm = 'platform::partials.fields.clear';
protected string|Closure|null $typeForm = 'platform::partials.fields.clear';

/**
* Attributes available for a particular tag.
*
* @var array
*/
protected $inlineAttributes = [
protected array $inlineAttributes = [
'type',
'autofocus',
'disabled',
Expand All @@ -31,10 +29,8 @@ class Action extends Field implements Actionable
/**
* A set of attributes for the assignment
* of which will automatically translate them.
*
* @var array
*/
protected $translations = [
protected array $translations = [
'name',
];

Expand All @@ -43,7 +39,7 @@ class Action extends Field implements Actionable
*
* @return self
*/
public function name(?string $name = null): self
public function name(?string $name = null): static
{
return $this->set('name', $name ?? '');
}
Expand All @@ -58,7 +54,7 @@ public function name(?string $name = null): self
*
* @return static
*/
public function type(Color $visual): self
public function type(Color $visual): static
{
$colors = array_map(static fn (Color $color) => 'btn-'.$color->name(), Color::cases());

Expand All @@ -71,10 +67,8 @@ public function type(Color $visual): self

/**
* @throws \Throwable
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|mixed
*/
public function build(?Repository $repository = null)
public function build(?Repository $repository = null): ?View
{
return $this->render();
}
Expand All @@ -89,7 +83,7 @@ public function build(?Repository $repository = null)
*
* @return static
*/
public function rawClick(bool $status = false): self
public function rawClick(bool $status = false): static
{
$this->set('turbo', $status);

Expand Down Expand Up @@ -118,7 +112,7 @@ protected function getId(): ?string
*
* @return self
*/
public function stretched(): self
public function stretched(): static
{
$this->attributes['class'] .= ' stretched-link';

Expand Down
42 changes: 9 additions & 33 deletions src/Screen/Actions/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,13 @@
*/
class Button extends Action
{
/**
* @var string
*/
protected $view = 'platform::actions.button';

protected string $view = 'platform::actions.button';

/**
* Default attributes value.
*
* @var array
*/
protected $attributes = [
protected array $attributes = [
'class' => 'btn btn-link icon-link',
'type' => 'submit',
'novalidate' => false,
Expand All @@ -45,10 +41,8 @@ class Button extends Action

/**
* Attributes available for a particular tag.
*
* @var array
*/
protected $inlineAttributes = [
protected array $inlineAttributes = [
'form',
'formaction',
'formenctype',
Expand All @@ -61,9 +55,6 @@ class Button extends Action
'tabindex',
];

/**
* Button constructor.
*/
public function __construct()
{
$this->addBeforeRender(function () {
Expand All @@ -89,18 +80,12 @@ public function __construct()
});
}

/**
* @return Button|\Orchid\Screen\Field
*/
public function novalidate(bool $novalidate = true)
public function novalidate(bool $novalidate = true): static
{
return $this->set('formnovalidate', var_export($novalidate, true));
}

/**
* @return $this
*/
public function method(string $name, array $parameters = []): self
public function method(string $name, array $parameters = []): static
{
return $this
->set('method', $name)
Expand All @@ -111,10 +96,8 @@ public function method(string $name, array $parameters = []): self
* Sets the parameters for the action.
*
* @param array|object $parameters The array or object containing the parameters.
*
* @return $this
*/
public function parameters(array|object $parameters): self
public function parameters(array|object $parameters): static
{
$parameters = is_array($parameters)
? collect($parameters)->filter(fn ($value) => filled($value))->all()
Expand All @@ -126,19 +109,12 @@ public function parameters(array|object $parameters): self
/**
* Method download serves as an alias for the `rawClick` method.
*/
public function download(bool $status = false): self
public function download(bool $status = false): static
{
return $this->rawClick($status);
}

/**
* @param array|string $name
* @param mixed $parameters
* @param bool $absolute
*
* @return $this
*/
public function route($name, $parameters = [], $absolute = true): self
public function route(string $name, mixed $parameters = [], bool $absolute = true): static
{
return $this->action(route($name, $parameters, $absolute));
}
Expand Down
17 changes: 6 additions & 11 deletions src/Screen/Actions/DropDown.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Orchid\Screen\Actions;

use Illuminate\Contracts\View\View;
use Orchid\Screen\Action;
use Orchid\Screen\Contracts\Actionable;
use Orchid\Screen\Repository;
Expand All @@ -18,17 +19,13 @@
*/
class DropDown extends Action
{
/**
* @var string
*/
protected $view = 'platform::actions.dropdown';

protected string $view = 'platform::actions.dropdown';

/**
* Default attributes value.
*
* @var array
*/
protected $attributes = [
protected array $attributes = [
'class' => 'btn btn-link icon-link',
'source' => null,
'icon' => null,
Expand All @@ -38,17 +35,15 @@ class DropDown extends Action
/**
* @param Actionable[] $list
*/
public function list(array $list): self
public function list(array $list): static
{
return $this->set('list', $list);
}

/**
* @throws \Throwable
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|mixed
*/
public function build(?Repository $repository = null)
public function build(?Repository $repository = null): ?View
{
$this->set('source', $repository);

Expand Down
30 changes: 6 additions & 24 deletions src/Screen/Actions/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@
*/
class Link extends Action
{
/**
* @var string
*/
protected $view = 'platform::actions.link';

protected string $view = 'platform::actions.link';

/**
* Default attributes value.
*
* @var array
*/
protected $attributes = [
protected array $attributes = [
'class' => 'btn btn-link icon-link',
'icon' => null,
'href' => '#!',
Expand All @@ -37,10 +33,8 @@ class Link extends Action

/**
* Attributes available for a particular tag.
*
* @var array
*/
public $inlineAttributes = [
public array $inlineAttributes = [
'autofocus',
'disabled',
'tabindex',
Expand All @@ -50,26 +44,14 @@ class Link extends Action
'download',
];

/**
* Set the link.
*
*
* @return $this
*/
public function href(string $link = ''): self
public function href(string $link = ''): static
{
$this->set('href', $link);

return $this;
}

/**
* @param array $parameters
* @param bool $absolute
*
* @return $this
*/
public function route(string $name, $parameters = [], $absolute = true): self
public function route(string $name, mixed $parameters = [], bool $absolute = true): static
{
$route = route($name, $parameters, $absolute);

Expand Down
Loading

0 comments on commit c889e49

Please sign in to comment.