Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\BetterPhpDocParser\PhpDocNode\Doctrine\Property_;

use Nette\Utils\Strings;
use Rector\BetterPhpDocParser\PhpDocNode\Doctrine\AbstractDoctrineTagValueNode;

final class ColumnTagValueNode extends AbstractDoctrineTagValueNode
Expand Down Expand Up @@ -58,6 +59,11 @@ final class ColumnTagValueNode extends AbstractDoctrineTagValueNode
*/
private $options;

/**
* @var bool
*/
private $isNullableUppercase = false;

/**
* @param mixed[] $options
* @param mixed|null $length
Expand Down Expand Up @@ -86,6 +92,11 @@ public function __construct(

if ($originalContent !== null) {
$this->resolveOriginalContentSpacingAndOrder($originalContent);

$matchIsNullable = Strings::match($originalContent, '#nullable(\s+)?=(\s+)?(?<value>false|true)#si');
if ($matchIsNullable) {
$this->isNullableUppercase = ctype_upper($matchIsNullable['value']);
}
}
}

Expand Down Expand Up @@ -126,7 +137,12 @@ public function __toString(): string
}

if ($this->nullable !== null) {
$contentItems['nullable'] = sprintf('nullable=%s', $this->nullable ? 'true' : 'false');
$nullableValue = $this->nullable ? 'true' : 'false';
if ($this->isNullableUppercase) {
$nullableValue = strtoupper($nullableValue);
}

$contentItems['nullable'] = sprintf('nullable=%s', $nullableValue);
}

return $this->printContentItems($contentItems);
Expand Down
9 changes: 3 additions & 6 deletions src/PhpParser/Printer/BetterStandardPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,12 +362,9 @@ private function detectTabOrSpaceIndentCharacter(array $stmts): void
continue;
}

$whitespacesChars = Strings::matchAll($fileInfo->getContents(), '#^( |\t)#m');
foreach ($whitespacesChars as $whitespacesChar) {
// let the first win
$this->tabOrSpaceIndentCharacter = $whitespacesChar[0];
break;
}
// tab vs space
$tabIndentChars = Strings::match($fileInfo->getContents(), '#^\t#m');
$this->tabOrSpaceIndentCharacter = $tabIndentChars[0] ?? ' ';
}
}

Expand Down