Skip to content

Commit

Permalink
Set default value for booleans to "false"
Browse files Browse the repository at this point in the history
  • Loading branch information
rougin committed Oct 12, 2024
1 parent 305b366 commit 3899dc4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
20 changes: 17 additions & 3 deletions src/Template/Wildfire/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ protected function setInputMethod()
$type = $type . '|null';
}

if ($col->isNull() || $type === 'boolean')
if ($col->isNull())
{
$lines[] = 'if (array_key_exists(\'' . $name . '\', $data))';
$lines[] = '{';
Expand All @@ -149,8 +149,22 @@ protected function setInputMethod()
}
else
{
$lines[] = '/** @var ' . $type . ' */';
$lines[] = '$' . $name . ' = $data[\'' . $name . '\'];';

if ($type === 'boolean')
{
$lines[] = '$' . $name . ' = false;';
$lines[] = 'if (array_key_exists(\'' . $name . '\', $data))';
$lines[] = '{';
$lines[] = ' /** @var ' . $type . ' */';
$lines[] = ' $' . $name . ' = $data[\'' . $name . '\'];';
$lines[] = '}';
}
else
{
$lines[] = '/** @var ' . $type . ' */';
$lines[] = '$' . $name . ' = $data[\'' . $name . '\'];';
}

$lines[] = '$load[\'' . $name . '\'] = $' . $name . ';';
}

Expand Down
3 changes: 2 additions & 1 deletion tests/Fixture/Plates/Wildfire/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,13 @@ protected function input($data, $id = null)
$year = $data['year'];
$load['year'] = $year;

$admin = false;
if (array_key_exists('admin', $data))
{
/** @var boolean */
$admin = $data['admin'];
$load['admin'] = $admin;
}
$load['admin'] = $admin;

if (array_key_exists('remarks', $data))
{
Expand Down

0 comments on commit 3899dc4

Please sign in to comment.