Skip to content

Commit

Permalink
Remove DataCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
antoine committed Jan 2, 2025
1 parent bcaded5 commit abad0a5
Show file tree
Hide file tree
Showing 27 changed files with 68 additions and 82 deletions.
4 changes: 2 additions & 2 deletions src/Data/BreadcrumbData.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
final class BreadcrumbData extends Data
{
public function __construct(
/** @var DataCollection<BreadcrumbItemData> */
public DataCollection $items,
/** @var BreadcrumbItemData[] */
public array $items,
) {}

public static function from(array $breadcrumb): self
Expand Down
5 changes: 2 additions & 3 deletions src/Data/Commands/CommandFormData.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Code16\Sharp\Data\Commands;

use Code16\Sharp\Data\Data;
use Code16\Sharp\Data\DataCollection;
use Code16\Sharp\Data\Form\Fields\FormFieldData;
use Code16\Sharp\Data\Form\FormLayoutData;
use Code16\Sharp\Data\PageAlertData;
Expand All @@ -18,8 +17,8 @@ public function __construct(
#[LiteralTypeScriptType('{ [key:string]: FormFieldData["value"] }')]
public ?array $data,
public CommandFormConfigData $config,
/** @var DataCollection<string,FormFieldData> */
public ?DataCollection $fields = null,
/** @var array<string,FormFieldData> */
public ?array $fields = null,
public ?FormLayoutData $layout = null,
/** @var array<string> */
public ?array $locales = null,
Expand Down
5 changes: 2 additions & 3 deletions src/Data/Dashboard/DashboardData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Code16\Sharp\Data\Dashboard\Widgets\WidgetData;
use Code16\Sharp\Data\Data;
use Code16\Sharp\Data\DataCollection;
use Code16\Sharp\Data\Filters\FilterValuesData;
use Code16\Sharp\Data\PageAlertData;

Expand All @@ -14,8 +13,8 @@
final class DashboardData extends Data
{
public function __construct(
/** @var DataCollection<WidgetData> */
public DataCollection $widgets,
/** @var WidgetData[] */
public array $widgets,
public DashboardConfigData $config,
public DashboardLayoutData $layout,
/** @var array<string,mixed> */
Expand Down
5 changes: 2 additions & 3 deletions src/Data/Dashboard/DashboardLayoutData.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
namespace Code16\Sharp\Data\Dashboard;

use Code16\Sharp\Data\Data;
use Code16\Sharp\Data\DataCollection;

/**
* @internal
*/
final class DashboardLayoutData extends Data
{
public function __construct(
/** @var DataCollection<DashboardLayoutSectionData> */
public DataCollection $sections,
/** @var DashboardLayoutSectionData[] */
public array $sections,
) {}

public static function from(array $layout): self
Expand Down
3 changes: 1 addition & 2 deletions src/Data/Dashboard/DashboardLayoutSectionData.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Code16\Sharp\Data\Dashboard;

use Code16\Sharp\Data\Data;
use Code16\Sharp\Data\DataCollection;

/**
* @internal
Expand All @@ -13,7 +12,7 @@ final class DashboardLayoutSectionData extends Data
public function __construct(
public ?string $key,
public string $title,
/** @var array<DataCollection<DashboardLayoutWidgetData>> */
/** @var array<DashboardLayoutWidgetData[]> */
public array $rows,
) {}

Expand Down
14 changes: 11 additions & 3 deletions src/Data/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
use ReflectionClass;
use ReflectionParameter;

/**
* @internal
*/
abstract class Data implements Arrayable
{
/** @var ReflectionParameter[][] */
protected static array $constructorParameterCache = [];

protected array $additionalAttributes = [];

public static function collection($payload): DataCollection
public static function collection($payload): array
{
return DataCollection::make($payload)
return collect($payload)
->map(function ($item) {
if (is_array($item)) {
if (method_exists(static::class, 'from')) {
Expand All @@ -26,7 +29,8 @@ public static function collection($payload): DataCollection
}

return $item;
});
})
->all();
}

public static function optional(mixed $payload): ?static
Expand Down Expand Up @@ -86,6 +90,10 @@ protected function transformValues(array $values): array
return $value->value;
}

if (is_array($value)) {
return collect($value)->toArray();
}

return $value;
})
->toArray();
Expand Down
7 changes: 0 additions & 7 deletions src/Data/DataCollection.php

This file was deleted.

5 changes: 2 additions & 3 deletions src/Data/Embeds/EmbedData.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Code16\Sharp\Data\Embeds;

use Code16\Sharp\Data\Data;
use Code16\Sharp\Data\DataCollection;
use Code16\Sharp\Data\Form\Fields\FormFieldData;
use Code16\Sharp\Data\IconData;
use Spatie\TypeScriptTransformer\Attributes\LiteralTypeScriptType;
Expand All @@ -25,8 +24,8 @@ public function __construct(
public ?IconData $icon,
/** @var string[] */
public array $attributes,
/** @var DataCollection<string,FormFieldData> */
public DataCollection $fields,
/** @var array<string,FormFieldData> */
public array $fields,
) {}

public static function from(array $embed): self
Expand Down
5 changes: 2 additions & 3 deletions src/Data/Embeds/EmbedFormData.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Code16\Sharp\Data\Embeds;

use Code16\Sharp\Data\Data;
use Code16\Sharp\Data\DataCollection;
use Code16\Sharp\Data\Form\Fields\FormFieldData;
use Code16\Sharp\Data\Form\FormLayoutData;
use Spatie\TypeScriptTransformer\Attributes\LiteralTypeScriptType;
Expand All @@ -16,8 +15,8 @@ final class EmbedFormData extends Data
public function __construct(
#[LiteralTypeScriptType('{ [key:string]: FormFieldData["value"] }')]
public ?array $data,
/** @var DataCollection<string,FormFieldData> */
public DataCollection $fields,
/** @var array<string,FormFieldData> */
public array $fields,
public ?FormLayoutData $layout,
) {}

Expand Down
9 changes: 4 additions & 5 deletions src/Data/EntityList/EntityListData.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Code16\Sharp\Data\EntityList;

use Code16\Sharp\Data\Data;
use Code16\Sharp\Data\DataCollection;
use Code16\Sharp\Data\EntityListAuthorizationsData;
use Code16\Sharp\Data\Filters\FilterValuesData;
use Code16\Sharp\Data\PageAlertData;
Expand All @@ -18,14 +17,14 @@ final class EntityListData extends Data
public function __construct(
public EntityListAuthorizationsData $authorizations,
public EntityListConfigData $config,
/** @var DataCollection<EntityListFieldData> */
public DataCollection $fields,
/** @var EntityListFieldData[] */
public array $fields,
#[LiteralTypeScriptType('Array<{ [key: string]: any }>')]
public array $data,
public FilterValuesData $filterValues,
public ?EntityListQueryParamsData $query,
/** @var DataCollection<string, EntityListMultiformData> */
public ?DataCollection $forms = null,
/** @var array<string, EntityListMultiformData>|null */
public ?array $forms = null,
public ?PaginatorMetaData $meta = null,
public ?PageAlertData $pageAlert = null,
) {}
Expand Down
4 changes: 2 additions & 2 deletions src/Data/EntityStateData.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ final class EntityStateData extends Data
{
public function __construct(
public string $attribute,
/** @var DataCollection<EntityStateValueData> */
public DataCollection $values,
/** @var EntityStateValueData[] */
public array $values,
/** @var bool|array<string|int> */
public mixed $authorization,
) {}
Expand Down
5 changes: 2 additions & 3 deletions src/Data/Form/Fields/FormAutocompleteLocalFieldData.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Code16\Sharp\Data\Form\Fields;

use Code16\Sharp\Data\Data;
use Code16\Sharp\Data\DataCollection;
use Code16\Sharp\Data\Form\Fields\Common\FormConditionalDisplayData;
use Code16\Sharp\Data\Form\Fields\Common\FormDynamicAttributeData;
use Code16\Sharp\Enums\FormFieldType;
Expand Down Expand Up @@ -36,8 +35,8 @@ public function __construct(
/** @var array<string> */
public ?array $searchKeys = null,
public ?bool $localized = null,
/** @var DataCollection<FormDynamicAttributeData> */
public ?DataCollection $dynamicAttributes = null,
/** @var FormDynamicAttributeData[]|null */
public ?array $dynamicAttributes = null,
public ?string $label = null,
public ?bool $readOnly = null,
public ?FormConditionalDisplayData $conditionalDisplay = null,
Expand Down
5 changes: 2 additions & 3 deletions src/Data/Form/Fields/FormAutocompleteRemoteFieldData.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Code16\Sharp\Data\Form\Fields;

use Code16\Sharp\Data\Data;
use Code16\Sharp\Data\DataCollection;
use Code16\Sharp\Data\Form\Fields\Common\FormConditionalDisplayData;
use Code16\Sharp\Data\Form\Fields\Common\FormDynamicAttributeData;
use Code16\Sharp\Enums\FormFieldType;
Expand Down Expand Up @@ -32,8 +31,8 @@ public function __construct(
/** @var string[]|null */
public ?array $callbackLinkedFields = null,
public ?string $placeholder = null,
/** @var DataCollection<FormDynamicAttributeData> */
public ?DataCollection $dynamicAttributes = null,
/** @var FormDynamicAttributeData[]|null */
public ?array $dynamicAttributes = null,
public ?string $label = null,
public ?bool $readOnly = null,
public ?FormConditionalDisplayData $conditionalDisplay = null,
Expand Down
5 changes: 2 additions & 3 deletions src/Data/Form/Fields/FormSelectFieldData.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Code16\Sharp\Data\Form\Fields;

use Code16\Sharp\Data\Data;
use Code16\Sharp\Data\DataCollection;
use Code16\Sharp\Data\Form\Fields\Common\FormConditionalDisplayData;
use Code16\Sharp\Data\Form\Fields\Common\FormDynamicAttributeData;
use Code16\Sharp\Enums\FormFieldType;
Expand Down Expand Up @@ -31,8 +30,8 @@ public function __construct(
#[LiteralTypeScriptType('"list" | "dropdown"')]
public string $display,
public bool $inline,
/** @var DataCollection<FormDynamicAttributeData> */
public ?DataCollection $dynamicAttributes = null,
/** @var FormDynamicAttributeData[]|null */
public ?array $dynamicAttributes = null,
public ?int $maxSelected = null,
public ?bool $localized = null,
public ?string $label = null,
Expand Down
5 changes: 2 additions & 3 deletions src/Data/Form/FormData.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Code16\Sharp\Data\Form;

use Code16\Sharp\Data\Data;
use Code16\Sharp\Data\DataCollection;
use Code16\Sharp\Data\Form\Fields\FormFieldData;
use Code16\Sharp\Data\InstanceAuthorizationsData;
use Code16\Sharp\Data\PageAlertData;
Expand All @@ -19,8 +18,8 @@ public function __construct(
public FormConfigData $config,
#[LiteralTypeScriptType('{ [key:string]: FormFieldData["value"] }')]
public ?array $data,
/** @var DataCollection<string,FormFieldData> */
public DataCollection $fields,
/** @var array<string,FormFieldData> */
public array $fields,
public FormLayoutData $layout,
/** @var array<string> */
public array $locales,
Expand Down
5 changes: 2 additions & 3 deletions src/Data/Form/FormLayoutData.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Code16\Sharp\Data\Form;

use Code16\Sharp\Data\Data;
use Code16\Sharp\Data\DataCollection;

/**
* @internal
Expand All @@ -12,8 +11,8 @@ final class FormLayoutData extends Data
{
public function __construct(
public bool $tabbed,
/** @var DataCollection<FormLayoutTabData> */
public DataCollection $tabs,
/** @var FormLayoutTabData[] */
public array $tabs,
) {}

public static function from(array $config): self
Expand Down
5 changes: 2 additions & 3 deletions src/Data/Form/FormLayoutTabData.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Code16\Sharp\Data\Form;

use Code16\Sharp\Data\Data;
use Code16\Sharp\Data\DataCollection;

/**
* @internal
Expand All @@ -12,8 +11,8 @@ final class FormLayoutTabData extends Data
{
public function __construct(
public string $title,
/** @var DataCollection<FormLayoutColumnData> */
public DataCollection $columns,
/** @var FormLayoutColumnData[] */
public array $columns,
) {}

public static function from(array $tab): self
Expand Down
4 changes: 2 additions & 2 deletions src/Data/MenuData.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
final class MenuData extends Data
{
public function __construct(
/** @var DataCollection<MenuItemData> */
public DataCollection $items,
/** @var MenuItemData[] */
public array $items,
public UserMenuData $userMenu,
public bool $isVisible,
) {}
Expand Down
4 changes: 2 additions & 2 deletions src/Data/MenuItemData.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public function __construct(
public ?string $entityKey = null,
public bool $isSeparator = false,
public bool $current = false,
/** @var DataCollection<MenuItemData> */
public ?DataCollection $children = null,
/** @var MenuItemData[]|null */
public ?array $children = null,
public bool $isCollapsible = false,
) {}

Expand Down
2 changes: 1 addition & 1 deletion src/Data/SearchResultSetData.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ final class SearchResultSetData extends Data
public function __construct(
public string $label,
/** @var SearchResultLinkData[] */
public DataCollection $resultLinks,
public array $resultLinks,
public ?IconData $icon,
public ?string $emptyStateLabel = null,
/** @var string[] */
Expand Down
5 changes: 2 additions & 3 deletions src/Data/Show/Fields/ShowListFieldData.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Code16\Sharp\Data\Show\Fields;

use Code16\Sharp\Data\Data;
use Code16\Sharp\Data\DataCollection;
use Code16\Sharp\Enums\ShowFieldType;
use Spatie\TypeScriptTransformer\Attributes\LiteralTypeScriptType;
use Spatie\TypeScriptTransformer\Attributes\Optional;
Expand All @@ -23,8 +22,8 @@ public function __construct(
public ShowFieldType $type,
public bool $emptyVisible,
public ?string $label,
/** @var DataCollection<string,ShowFieldData> */
public DataCollection $itemFields,
/** @var array<string,ShowFieldData> */
public array $itemFields,
) {}

public static function from(array $list): self
Expand Down
5 changes: 2 additions & 3 deletions src/Data/Show/Fields/ShowTextFieldData.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Code16\Sharp\Data\Show\Fields;

use Code16\Sharp\Data\Data;
use Code16\Sharp\Data\DataCollection;
use Code16\Sharp\Data\Embeds\EmbedData;
use Code16\Sharp\Data\Form\Fields\FormEditorFieldData;
use Code16\Sharp\Enums\ShowFieldType;
Expand All @@ -27,8 +26,8 @@ public function __construct(
public bool $html,
public ?bool $localized = null,
public ?int $collapseToWordCount = null,
/** @var DataCollection<string, EmbedData> */
public ?DataCollection $embeds = null,
/** @var array<string, EmbedData> */
public ?array $embeds = null,
public ?string $label = null,
) {}

Expand Down
Loading

0 comments on commit abad0a5

Please sign in to comment.