Swagger\StaticAnalyser::fromFile PHP Method

fromFile() public method

Extract and process all doc-comments from a file.
public fromFile ( string $filename ) : Analysis
$filename string Path to a php file.
return Analysis
    public function fromFile($filename)
    {
        $tokens = token_get_all(file_get_contents($filename));
        return $this->fromTokens($tokens, new Context(['filename' => $filename]));
    }

Usage Example

Example #1
0
 public function testGetParentClasses()
 {
     $analyser = new StaticAnalyser();
     $analysis = $analyser->fromFile(__DIR__ . '/Fixtures/Child.php');
     $analysis->addAnalysis($analyser->fromFile(__DIR__ . '/Fixtures/GrandParent.php'));
     $analysis->addAnalysis($analyser->fromFile(__DIR__ . '/Fixtures/Parent.php'));
     $this->assertCount(3, $analysis->classes, '3 classes should\'ve been detected');
     $superclasses = $analysis->getSuperClasses('\\AnotherNamespace\\Child');
     $this->assertCount(2, $superclasses, 'Child has a chain of 2 super classes');
     $this->assertSame(['\\SwaggerFixtures\\Parent', '\\SwaggerFixtures\\GrandParent'], array_keys($superclasses));
     $this->assertSame(['\\SwaggerFixtures\\GrandParent'], array_keys($analysis->getSuperClasses('\\SwaggerFixtures\\Parent')));
 }
All Usage Examples Of Swagger\StaticAnalyser::fromFile