Skip to content

Commit

Permalink
Quote default values in phpDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzalom committed Dec 31, 2019
1 parent 46f1162 commit 0c4f23d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ We do not give estimated times for completion on `Accepted` Proposals.

---

## [v6.0.13] - 2019-12-31

`Changed`

- Quote default values.

## [v6.0.12] - 2019-12-31

`Changed`
Expand Down Expand Up @@ -239,7 +245,8 @@ It can work with `nightly`, but is not compatible with `hhvm`, as it uses differ
[Accepted]: https://github.com/Triun/laravel-model-base/labels/Accepted
[Rejected]: https://github.com/Triun/laravel-model-base/labels/Rejected

[Unreleased]: https://github.com/Triun/laravel-model-base/compare/v6.0.12...HEAD
[Unreleased]: https://github.com/Triun/laravel-model-base/compare/v6.0.13...HEAD
[v6.0.13]: https://github.com/Triun/laravel-model-base/compare/v6.0.12...v6.0.13
[v6.0.12]: https://github.com/Triun/laravel-model-base/compare/v6.0.11...v6.0.12
[v6.0.11]: https://github.com/Triun/laravel-model-base/compare/v6.0.10...v6.0.11
[v6.0.10]: https://github.com/Triun/laravel-model-base/compare/v6.0.9...v6.0.10
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "triun/laravel-model-base",
"version": "6.0.12",
"version": "6.0.13",
"description": "Generate Eloquent Model Bases for Laravel",
"license": "MIT",
"homepage": "https://github.com/Triun",
Expand Down
29 changes: 27 additions & 2 deletions src/Modifiers/PhpDocModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Triun\ModelBase\Modifiers;

use Doctrine\DBAL\ParameterType;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Str;
use ReflectionClass;
Expand Down Expand Up @@ -100,8 +101,32 @@ private function columnsPhpDocCommentType(Column $column): string
$comment .= '|null';
}

if (null !== $column->getDefault()) {
$comment .= ' (default: ' . $column->getDefault() . ')';
if (null !== ($default = $column->getDefault())) {
if (null === $default) {
$default = 'null';
} else {
switch ($column->getType()->getBindingType()) {
case ParameterType::NULL:
$default = 'null';
break;
case ParameterType::STRING:
$default = '"' . $default . '"';
break;
case ParameterType::BOOLEAN:
$default = $default ? 'true' : 'false';
break;
case ParameterType::LARGE_OBJECT:
$default = 'large object';
break;
case ParameterType::BINARY:
$default = 'binary';
break;
case ParameterType::INTEGER:
default:
// As it is
}
}
$comment .= ' (default: ' . $default . ')';
}

return $comment;
Expand Down

0 comments on commit 0c4f23d

Please sign in to comment.