Skip to content

Commit

Permalink
improve Static_ strong types
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Jan 11, 2025
1 parent afd31ee commit 87a10f3
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Persistence/Static_.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
class Static_ extends Array_
{
/** @var string This will be the title field for the model. */
public $titleFieldForModel;
public ?string $titleFieldForModel = null;

/** @var array<string, array<mixed>> Populate the following fields for the model. */
public $fieldsForModel = [];
public array $fieldsForModel;

/**
* @param array<int|string, mixed> $data
Expand Down Expand Up @@ -88,7 +88,7 @@ public function __construct(array $data = [])
}

// if title is not set, use first key
if (!$this->titleFieldForModel) {
if ($this->titleFieldForModel === null) {
if (is_int($k)) {
$keyOverride[$k] = 'name';
$this->titleFieldForModel = 'name';
Expand Down Expand Up @@ -162,7 +162,7 @@ public function add(Model $model, array $defaults = []): void
*/
protected function addMissingFieldsToModel(Model $model): void
{
if ($this->titleFieldForModel) {
if ($this->titleFieldForModel !== null) {
$model->titleField = $this->titleFieldForModel;
}

Expand Down

0 comments on commit 87a10f3

Please sign in to comment.