Skip to content

Improvements for #9 #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 2, 2015
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
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure which PHP version you'd like coverage of, so I used 5.6 which is as good as any ^_^


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