Skip to content

Commit 843396e

Browse files
committed
Merge pull request #18 from castamir/phpfile
PhpFile::__toString(): Brackets fix when generating from global namespace only
2 parents eef9df8 + 19356e1 commit 843396e

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

src/PhpGenerator/PhpFile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function addNamespace($name)
114114
public function __toString()
115115
{
116116
foreach ($this->namespaces as $namespace) {
117-
$namespace->setBracketedSyntax(isset($this->namespaces[NULL]));
117+
$namespace->setBracketedSyntax(count($this->namespaces) > 1 && isset($this->namespaces[NULL]));
118118
}
119119

120120
return Strings::normalize(
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?php
2+
class A
3+
{
4+
}

tests/PhpGenerator/PhpFile.phpt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,8 @@ $file->addClass('H');
7373
$file->addClass('FooBar\\I');
7474

7575
Assert::matchFile(__DIR__ . '/PhpFile.bracketed.expect', (string) $file);
76+
77+
$file = new PhpFile;
78+
$file->addClass('A');
79+
80+
Assert::matchFile(__DIR__ . '/PhpFile.globalNamespace.expect', (string) $file);

0 commit comments

Comments
 (0)