create() public static method

public static create ( Symfony\Component\Finder\SplFileInfo $file ) : self
$file Symfony\Component\Finder\SplFileInfo
return self
    public function testVariableResolver()
    {
        $source = <<<'EOC'
<?php
namespace Foo;
class Bar
{
    function a() {
    }
    function b() {
        $this->a();
        $x = new Bar1();
        $x->a();
        $x->b();
        $c = new Bar2();
        $y = $c;
        $f = $y;
        $f->a();
    }
}
EOC;
        $fileInfo = PhpFileInfo::create($this->prophesize('Symfony\\Component\\Finder\\SplFileInfo')->reveal());
        $contents = $this->traverseSourceAndReturnContents($source, $fileInfo);
        $methodUsages = $contents->methodUsages();
        $this->assertCount(4, $methodUsages);
        $this->assertEquals(new MethodUsage('a', 'Foo\\Bar', 8, false), $methodUsages[0]);
        $this->assertEquals(new MethodUsage('a', 'Bar1', 10, false), $methodUsages[1]);
        $this->assertEquals(new MethodUsage('b', 'Bar1', 11, false), $methodUsages[2]);
        $this->assertEquals(new MethodUsage('a', 'Bar2', 15, false), $methodUsages[3]);
    }
 /**
  * @return \Iterator
  */
 public function getIterator()
 {
     $iterator = parent::getIterator();
     $files = new \ArrayIterator();
     foreach ($iterator as $file) {
         $file = PhpFileInfo::create($file);
         if (null !== $this->parser) {
             $this->parser->parseFile($file);
         }
         $files->append($file);
     }
     return $files;
 }
    public function testNoNewStatement()
    {
        $source = <<<'EOC'
<?php

$foo = 'hello';
$bar = Bar::bazinga();

EOC;
        $splFileInfo = $this->prophesize('Symfony\\Component\\Finder\\SplFileInfo');
        $usageCollection = $this->parsePhpFileFromStringAndTraverseWithVisitor($file = PhpFileInfo::create($splFileInfo->reveal()), $source, new FindClasses());
        $this->assertEquals(array(), $usageCollection->classUsages());
    }
    public function testClassWithoutInterface()
    {
        $source = <<<EOC
<?php
namespace Foo;

class Bar
{
}
EOC;
        $splFileInfo = $this->prophesize('Symfony\\Component\\Finder\\SplFileInfo');
        $phpFileInfo = $this->parsePhpFileFromStringAndTraverseWithVisitor($file = PhpFileInfo::create($splFileInfo->reveal()), $source, new FindInterfaces());
        $this->assertEquals(array(), $phpFileInfo->interfaceUsages());
    }
    public function testNoNewStatement()
    {
        $source = <<<'EOC'
<?php

$bar = Bar::bazinga();
Logger::log('hello world');

EOC;
        $splFileInfo = $this->prophesize('Symfony\\Component\\Finder\\SplFileInfo');
        $phpFileInfo = $this->parsePhpFileFromStringAndTraverseWithVisitor($file = PhpFileInfo::create($splFileInfo->reveal()), $source, new FindStaticMethodCalls());
        $usages = $phpFileInfo->methodUsages();
        $this->assertEquals(new MethodUsage('bazinga', 'Bar', 3, true), $usages[0]);
        $this->assertEquals(new MethodUsage('log', 'Logger', 4, true), $usages[1]);
    }
 /**
  * @return \Iterator
  */
 public function getIterator()
 {
     $iterator = parent::getIterator();
     $files = new \ArrayIterator();
     foreach ($iterator as $file) {
         $file = PhpFileInfo::create($file);
         if (null !== $this->parser) {
             try {
                 $this->parser->parseFile($file);
             } catch (\PhpParser\Error $ex) {
                 $raw = $ex->getRawMessage() . ' in file ' . $file;
                 $ex->setRawMessage($raw);
                 $this->parserErrors[] = $ex;
             }
         }
         $files->append($file);
     }
     return $files;
 }
    public function testLambdaInClass()
    {
        $source = <<<'EOC'
<?php
namespace Foo;

class Bar
{
    public static function method() {
        function(\A $a, A $a) {};
    }
}
EOC;
        $splFileInfo = $this->prophesize('Symfony\\Component\\Finder\\SplFileInfo');
        $usages = $this->parseFileAndReturnClassUsages($file = PhpFileInfo::create($splFileInfo->reveal()), $source);
        $this->assertCount(2, $usages);
        $this->assertContains('A::7', $usages);
        $this->assertContains('Foo\\A::7', $usages);
    }
 /**
  * @return \Iterator
  */
 public function getIterator()
 {
     $iterator = parent::getIterator();
     $files = new \ArrayIterator();
     $total = $this->count();
     $this->progressOutput->start($total);
     $i = 0;
     foreach ($iterator as $file) {
         $file = PhpFileInfo::create($file);
         try {
             $this->progressOutput->advance(++$i, $file);
             $this->parser->parseFile($file);
         } catch (\PhpParser\Error $ex) {
             $raw = $ex->getRawMessage() . ' in file ' . $file;
             $ex->setRawMessage($raw);
             $this->parserErrors[] = $ex;
         }
         $files->append($file);
     }
     $this->progressOutput->end();
     return $files;
 }
 /**
  * @param string $path
  *
  * @return Result
  */
 public function parsePhpFiles($path)
 {
     $files = $this->finderFactory->createFinder()->in($path);
     $parsedFiles = array();
     $parserErrors = array();
     $this->progressOutput->start($fileCount = $files->count());
     $i = 0;
     foreach ($files->getIterator() as $file) {
         $file = PhpFileInfo::create($file);
         try {
             $this->progressOutput->advance(++$i, $file);
             $this->parser->parseFile($file);
         } catch (Error $ex) {
             $raw = $ex->getRawMessage() . ' in file ' . $file;
             $ex->setRawMessage($raw);
             $parserErrors[] = $ex;
         }
         $parsedFiles[] = $file;
     }
     $this->progressOutput->end();
     return new Result($parsedFiles, $parserErrors, $fileCount);
 }
 public function testAddAndGetMethodDefinitions()
 {
     $fileInfo = PhpFileInfo::create($this->prophesize('Symfony\\Component\\Finder\\SplFileInfo')->reveal());
     $this->assertSame(array(), $fileInfo->methodDefinitions());
     $methodDefinition = $this->prophesize('SensioLabs\\DeprecationDetector\\FileInfo\\MethodDefinition')->reveal();
     $fileInfo->addMethodDefinition($methodDefinition);
     $this->assertSame(array($methodDefinition), $fileInfo->methodDefinitions());
 }
 /**
  * @param $name
  *
  * @return PhpFileInfo|null
  */
 protected function findDefinitionFileByName($name)
 {
     $namespaceParts = explode('\\', $name);
     $filename = array_pop($namespaceParts) . '.php';
     $namespace = implode('\\', $namespaceParts);
     $finder = new Finder();
     $finder->name($filename)->in($this->sourcePaths);
     $files = array();
     /** @var SplFileInfo $file */
     foreach ($finder as $file) {
         if (empty($namespace) || is_int(strpos($file->getContents(), $namespace))) {
             $baseFile = PhpFileInfo::create($file);
             $files[] = $this->container['parser.usage']->parseFile($baseFile);
         }
     }
     $file = current($files);
     if (!$file instanceof PhpFileInfo) {
         return;
     }
     return $file;
 }
 public function testAddAndGetDeprecatedLanguageUsage()
 {
     $fileInfo = PhpFileInfo::create($this->prophesize('Symfony\\Component\\Finder\\SplFileInfo')->reveal());
     $this->assertSame(array(), $fileInfo->getDeprecatedLanguageUsages());
     $deprecatedLanguageUsage = $this->prophesize('SensioLabs\\DeprecationDetector\\FileInfo\\Usage\\DeprecatedLanguageUsage')->reveal();
     $fileInfo->addDeprecatedLanguageUsage($deprecatedLanguageUsage);
     $this->assertSame(array($deprecatedLanguageUsage), $fileInfo->getDeprecatedLanguageUsages());
 }
 /**
  * @param $type
  * @param $name
  *
  * @return PhpFileInfo|null
  */
 protected function findDefinitionFileByRegex($type, $name)
 {
     $namespaceParts = explode('\\', $name);
     $definition = sprintf('%s %s[;\\{\\s]', $type, array_pop($namespaceParts));
     if (count($namespaceParts) > 0) {
         $namespace = sprintf('namespace %s', implode('\\\\', $namespaceParts));
     } else {
         $namespace = '';
     }
     $files = new Finder();
     $files->name('*.php')->contains(sprintf('/%s.*%s/s', $namespace, $definition))->in($this->sourcePaths);
     if (!$namespace) {
         $files->notContains('/namespace\\s[^;]+/');
     }
     $file = current(iterator_to_array($files));
     if (!$file instanceof SplFileInfo) {
         return;
     }
     $baseFile = PhpFileInfo::create($file);
     return $this->usageParser->parseFile($baseFile);
 }