Skip to content

Commit 60fe236

Browse files
committed
Merge pull request #10 from asgrim/improvements-for-pr9
Improvements for #9
2 parents 83e3125 + b802985 commit 60fe236

File tree

3 files changed

+47
-5
lines changed

3 files changed

+47
-5
lines changed

.travis.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ before_script:
2222
- composer install --no-interaction
2323

2424
after_script:
25-
- wget https://scrutinizer-ci.com/ocular.phar
26-
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover
25+
- if [ $TRAVIS_PHP_VERSION = '5.6' ]; then wget https://scrutinizer-ci.com/ocular.phar; php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi
2726

2827
notifications:
2928
irc: "irc.freenode.org#phpdocumentor"

src/Types/ContextFactory.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ public function createForNamespace($namespace, $fileContents)
7777
$braceLevel = 0;
7878
$firstBraceFound = false;
7979
while ($tokens->valid() && ($braceLevel > 0 || !$firstBraceFound)) {
80-
if ($tokens->current() === '{') {
80+
if ($tokens->current() === '{'
81+
|| $tokens->current()[0] === T_CURLY_OPEN
82+
|| $tokens->current()[0] === T_DOLLAR_OPEN_CURLY_BRACES) {
8183
if (!$firstBraceFound) {
8284
$firstBraceFound = true;
8385
}

tests/unit/Types/ContextFactoryTest.php

+43-2
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,12 @@ public function testReadsAliasesFromProvidedNamespaceAndContent()
8989
$this->assertSame($expected, $context->getNamespaceAliases());
9090
}
9191

92+
/**
93+
* @covers ::createForNamespace
94+
* @uses phpDocumentor\Reflection\Types\Context
95+
*/
9296
public function testTraitUseIsNotDetectedAsNamespaceUse()
9397
{
94-
$fixture = new ContextFactory();
95-
9698
$php = "<?php
9799
namespace Foo;
98100
@@ -108,6 +110,45 @@ class FooClass {
108110

109111
$this->assertSame([], $context->getNamespaceAliases());
110112
}
113+
114+
/**
115+
* @covers ::createForNamespace
116+
* @uses phpDocumentor\Reflection\Types\Context
117+
*/
118+
public function testAllOpeningBracesAreCheckedWhenSearchingForEndOfClass()
119+
{
120+
$php = '<?php
121+
namespace Foo;
122+
123+
trait FooTrait {}
124+
trait BarTrait {}
125+
126+
class FooClass {
127+
use FooTrait;
128+
129+
public function bar()
130+
{
131+
echo "{$baz}";
132+
echo "${baz}";
133+
}
134+
}
135+
136+
class BarClass {
137+
use BarTrait;
138+
139+
public function bar()
140+
{
141+
echo "{$baz}";
142+
echo "${baz}";
143+
}
144+
}
145+
';
146+
147+
$fixture = new ContextFactory();
148+
$context = $fixture->createForNamespace('Foo', $php);
149+
150+
$this->assertSame([], $context->getNamespaceAliases());
151+
}
111152
}
112153
}
113154

0 commit comments

Comments
 (0)