Skip to content

Commit

Permalink
Merge pull request #10 from asgrim/improvements-for-pr9
Browse files Browse the repository at this point in the history
Improvements for #9
  • Loading branch information
mvriel committed Dec 2, 2015
2 parents 83e3125 + b802985 commit 60fe236
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ before_script:
- composer install --no-interaction

after_script:
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover
- 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

notifications:
irc: "irc.freenode.org#phpdocumentor"
Expand Down
4 changes: 3 additions & 1 deletion src/Types/ContextFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ public function createForNamespace($namespace, $fileContents)
$braceLevel = 0;
$firstBraceFound = false;
while ($tokens->valid() && ($braceLevel > 0 || !$firstBraceFound)) {
if ($tokens->current() === '{') {
if ($tokens->current() === '{'
|| $tokens->current()[0] === T_CURLY_OPEN
|| $tokens->current()[0] === T_DOLLAR_OPEN_CURLY_BRACES) {
if (!$firstBraceFound) {
$firstBraceFound = true;
}
Expand Down
45 changes: 43 additions & 2 deletions tests/unit/Types/ContextFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,12 @@ public function testReadsAliasesFromProvidedNamespaceAndContent()
$this->assertSame($expected, $context->getNamespaceAliases());
}

/**
* @covers ::createForNamespace
* @uses phpDocumentor\Reflection\Types\Context
*/
public function testTraitUseIsNotDetectedAsNamespaceUse()
{
$fixture = new ContextFactory();

$php = "<?php
namespace Foo;
Expand All @@ -108,6 +110,45 @@ class FooClass {

$this->assertSame([], $context->getNamespaceAliases());
}

/**
* @covers ::createForNamespace
* @uses phpDocumentor\Reflection\Types\Context
*/
public function testAllOpeningBracesAreCheckedWhenSearchingForEndOfClass()
{
$php = '<?php
namespace Foo;
trait FooTrait {}
trait BarTrait {}
class FooClass {
use FooTrait;
public function bar()
{
echo "{$baz}";
echo "${baz}";
}
}
class BarClass {
use BarTrait;
public function bar()
{
echo "{$baz}";
echo "${baz}";
}
}
';

$fixture = new ContextFactory();
$context = $fixture->createForNamespace('Foo', $php);

$this->assertSame([], $context->getNamespaceAliases());
}
}
}

Expand Down

0 comments on commit 60fe236

Please sign in to comment.