Skip to content

Commit

Permalink
Merge pull request #1269 from lee-to/stan
Browse files Browse the repository at this point in the history
Stan
  • Loading branch information
lee-to authored Sep 16, 2024
2 parents 166487a + b44cd4b commit 4658f9c
Show file tree
Hide file tree
Showing 238 changed files with 2,623 additions and 856 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/analyse.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: tests

on:
push:
pull_request:
types:
- opened
- ready_for_review
- reopened
- synchronize
schedule:
- cron: '0 0 * * *'

jobs:
moonshine-analyse:
if: ${{ github.event_name == 'push' || !github.event.pull_request.draft }}
runs-on: ubuntu-latest

steps:
- uses: shivammathur/setup-php@v2
with:
php-version: 8.2
tools: composer:v2
coverage: none
- uses: actions/checkout@v4

- name: Install Dependencies
run: composer install --dev

- name: Execute
run: composer analyse
15 changes: 14 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,23 @@ includes:
- ./vendor/larastan/larastan/extension.neon

parameters:
editorUrl: 'anything'
editorUrlTitle: "\nat packages/moonshine/%%relFile%%:%%line%%"
paths:
- src/
level: 1
level: 5
reportUnmatchedIgnoredErrors: false
checkMissingIterableValueType: false

ignoreErrors:
- '#Cannot cast Closure to string#'
- '#Cannot cast Closure\|null to string#'
- '#mixin contains invalid type Illuminate\\Support\\Traits\\Conditionable#'
- '#does not accept Illuminate\\View\\ComponentAttributeBag#'
- '#should return MoonShine\\Contracts\\UI\\ComponentAttributesBagContract but returns Illuminate\\View\\ComponentAttributeBag#'
- '#getResource\(\) should return#'
- '#getParentResource\(\) should return#'
- '#when\(\) expects#'
excludePaths:
- ./src/Support/src/Traits/Makeable.php
- ./src/Laravel/routes/moonshine.php
Expand Down
8 changes: 4 additions & 4 deletions src/AssetManager/src/AssetElements.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,28 @@ final class AssetElements extends Collection implements AssetElementsContract
public function js(): self
{
return $this->filter(
static fn (AssetElementContract $asset): int|bool => $asset instanceof Js
static fn (AssetElementContract $asset): bool => $asset instanceof Js
);
}

public function css(): self
{
return $this->filter(
static fn (AssetElementContract $asset): int|bool => $asset instanceof Css
static fn (AssetElementContract $asset): bool => $asset instanceof Css
);
}

public function inlineCss(): self
{
return $this->filter(
static fn (AssetElementContract $asset): int|bool => $asset instanceof InlineCss
static fn (AssetElementContract $asset): bool => $asset instanceof InlineCss
);
}

public function inlineJs(): self
{
return $this->filter(
static fn (AssetElementContract $asset): int|bool => $asset instanceof InlineJs
static fn (AssetElementContract $asset): bool => $asset instanceof InlineJs
);
}

Expand Down
5 changes: 3 additions & 2 deletions src/AssetManager/src/Css.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
use MoonShine\AssetManager\Traits\HasLink;
use MoonShine\AssetManager\Traits\WithVersion;
use MoonShine\Contracts\AssetManager\AssetElementContract;
use MoonShine\Contracts\UI\HasComponentAttributesContract;
use MoonShine\Support\Components\MoonShineComponentAttributeBag;
use MoonShine\Support\Traits\Makeable;
use MoonShine\Support\Traits\WithComponentAttributes;

/**
* @method static static make(string $link)
*/
final class Css implements AssetElementContract, HasLinkContact, HasVersionContact
final class Css implements AssetElementContract, HasComponentAttributesContract, HasLinkContact, HasVersionContact
{
use Makeable;
use WithVersion;
Expand Down Expand Up @@ -47,7 +48,7 @@ public function toHtml(): string
]);

return <<<HTML
<link {$this->getAttributes()}>
<link {$this->getAttributes()->toHtml()}>
HTML;
}

Expand Down
5 changes: 3 additions & 2 deletions src/AssetManager/src/InlineCss.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
namespace MoonShine\AssetManager;

use MoonShine\Contracts\AssetManager\AssetElementContract;
use MoonShine\Contracts\UI\HasComponentAttributesContract;
use MoonShine\Support\Components\MoonShineComponentAttributeBag;
use MoonShine\Support\Traits\Makeable;
use MoonShine\Support\Traits\WithComponentAttributes;

/**
* @method static static make(string $content)
*/
final class InlineCss implements AssetElementContract
final class InlineCss implements AssetElementContract, HasComponentAttributesContract
{
use Makeable;
use WithComponentAttributes;
Expand All @@ -31,7 +32,7 @@ public function getContent(): string
public function toHtml(): string
{
return <<<HTML
<style {$this->getAttributes()}>{$this->getContent()}</style>
<style {$this->getAttributes()->toHtml()}>{$this->getContent()}</style>
HTML;
}

Expand Down
5 changes: 3 additions & 2 deletions src/AssetManager/src/InlineJs.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@

use MoonShine\AssetManager\Traits\WithVersion;
use MoonShine\Contracts\AssetManager\AssetElementContract;
use MoonShine\Contracts\UI\HasComponentAttributesContract;
use MoonShine\Support\Components\MoonShineComponentAttributeBag;
use MoonShine\Support\Traits\Makeable;
use MoonShine\Support\Traits\WithComponentAttributes;

/**
* @method static static make(string $content)
*/
final class InlineJs implements AssetElementContract
final class InlineJs implements AssetElementContract, HasComponentAttributesContract
{
use Makeable;
use WithComponentAttributes;
Expand All @@ -33,7 +34,7 @@ public function getContent(): string
public function toHtml(): string
{
return <<<HTML
<script {$this->getAttributes()}>{$this->getContent()}</script>
<script {$this->getAttributes()->toHtml()}>{$this->getContent()}</script>
HTML;
}

Expand Down
5 changes: 3 additions & 2 deletions src/AssetManager/src/Js.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
use MoonShine\AssetManager\Traits\HasLink;
use MoonShine\AssetManager\Traits\WithVersion;
use MoonShine\Contracts\AssetManager\AssetElementContract;
use MoonShine\Contracts\UI\HasComponentAttributesContract;
use MoonShine\Support\Components\MoonShineComponentAttributeBag;
use MoonShine\Support\Traits\Makeable;
use MoonShine\Support\Traits\WithComponentAttributes;

/**
* @method static static make(string $link)
*/
final class Js implements AssetElementContract, HasLinkContact, HasVersionContact
final class Js implements AssetElementContract, HasComponentAttributesContract, HasLinkContact, HasVersionContact
{
use Makeable;
use WithVersion;
Expand Down Expand Up @@ -46,7 +47,7 @@ public function toHtml(): string
]);

return <<<HTML
<script {$this->getAttributes()}></script>
<script {$this->getAttributes()->toHtml()}></script>
HTML;
}

Expand Down
4 changes: 3 additions & 1 deletion src/Contracts/src/AssetManager/AssetElementContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Illuminate\Contracts\Support\Htmlable;
use Stringable;

interface AssetElementContract extends Htmlable, Stringable
interface AssetElementContract extends
Htmlable,
Stringable
{
}
11 changes: 10 additions & 1 deletion src/Contracts/src/AssetManager/AssetElementsContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@
namespace MoonShine\Contracts\AssetManager;

use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Support\Collection;
use Illuminate\Support\Enumerable;

interface AssetElementsContract extends Htmlable
/**
* @template-extends Enumerable<array-key, AssetElementContract>
*
* @mixin Collection
*/
interface AssetElementsContract extends Enumerable, Htmlable
{
public function resolveLinks(AssetResolverContract $resolver): self;

public function withVersion(int|string $version): self;
}
19 changes: 19 additions & 0 deletions src/Contracts/src/Core/CrudPageContract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace MoonShine\Contracts\Core;

use MoonShine\Contracts\Core\DependencyInjection\FieldsContract;
use MoonShine\Support\Enums\PageType;

/**
* @template TFields of FieldsContract
*/
interface CrudPageContract extends PageContract
{
/**
* @return TFields
*/
public function getFields(): FieldsContract;
}
77 changes: 73 additions & 4 deletions src/Contracts/src/Core/CrudResourceContract.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,29 @@

namespace MoonShine\Contracts\Core;

use Illuminate\Support\Collection;
use MoonShine\Contracts\Core\DependencyInjection\FieldsContract;
use MoonShine\Contracts\Core\TypeCasts\DataCasterContract;
use MoonShine\Contracts\Core\TypeCasts\DataWrapperContract;
use Traversable;

/**
* @template TData
* @template-covariant TIndexPage of PageContract
* @template-covariant TFormPage of PageContract
* @template-covariant TDetailPage of PageContract
* @template-covariant TIndexPage of CrudPageContract
* @template-covariant TFormPage of CrudPageContract
* @template-covariant TDetailPage of CrudPageContract
* @template TFields of FieldsContract
* @template-covariant TItems of Traversable
*
*/
interface CrudResourceContract
interface CrudResourceContract extends ResourceContract
{
public function getRoute(
string $name = null,
DataWrapperContract|int|string|null $key = null,
array $query = []
): string;

/**
* @return DataCasterContract<TData>
*/
Expand Down Expand Up @@ -49,11 +57,33 @@ public function getFormPage(): ?PageContract;
*/
public function getDetailPage(): ?PageContract;

/**
* @return TFields
*/
public function getIndexFields(): FieldsContract;

/**
* @return TFields
*/
public function getFormFields(bool $withOutside = false): FieldsContract;

/**
* @return TFields
*/
public function getDetailFields(bool $withOutside = false, bool $onlyOutside = false): FieldsContract;

/**
* @return ?TData
*/
public function getItem(): mixed;

public function getItemID(): int|string|null;

/**
* @return TData
*/
public function getItemOrInstance(): mixed;

/**
* @return TItems
*/
Expand Down Expand Up @@ -83,4 +113,43 @@ public function delete(mixed $item, ?FieldsContract $fields = null): bool;
* @return TData
*/
public function save(mixed $item, ?FieldsContract $fields = null): mixed;


public function getIndexPageUrl(array $params = [], ?string $fragment = null): string;

/**
* @param DataWrapperContract<TData>|int|string|null $key
*/
public function getFormPageUrl(
DataWrapperContract|int|string|null $key = null,
array $params = [],
?string $fragment = null
): string;

/**
* @param DataWrapperContract<TData>|int|string $key
*/
public function getDetailPageUrl(
DataWrapperContract|int|string $key,
array $params = [],
?string $fragment = null
): string;

public function setQueryParams(iterable $params): static;

public function getQueryParams(): Collection;

public function getQueryParamsKeys(): array;

public function hasSearch(): bool;

/**
* @param TData $item
*/
public function modifyResponse(mixed $item): mixed;

/**
* @param iterable<TData> $items
*/
public function modifyCollectionResponse(mixed $items): mixed;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use MoonShine\Contracts\UI\ApplyContract;
use MoonShine\Contracts\UI\FieldContract;
use MoonShine\Contracts\UI\FormElementContract;

/**
* @template-covariant I
Expand All @@ -24,7 +25,7 @@ public function defaultFor(string $for): static;
public function getDefaultFor(): string;

public function findByField(
FieldContract $field,
FormElementContract $field,
string $type = 'fields',
?string $for = null
): ?ApplyContract;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public function getForm(string $name, string $default, mixed ...$parameters): Fo
/**
* @template T of PageContract
* @param class-string<T> $default
*
* @return T
*/
public function getPage(string $name, string $default, mixed ...$parameters): PageContract;

Expand All @@ -40,6 +42,8 @@ public function getPage(string $name, string $default, mixed ...$parameters): Pa
*/
public function getLocales(): array;

public function getLocale(): string;

public function getDisk(): string;

/**
Expand Down
Loading

0 comments on commit 4658f9c

Please sign in to comment.