Psecio\Parse\Scanner::scan PHP Method

scan() public method

Execute the scan
public scan ( FileIterator $fileIterator ) : void
$fileIterator FileIterator Iterator with files to scan
return void
    public function scan(FileIterator $fileIterator)
    {
        $this->dispatcher->dispatch(self::SCAN_START);
        foreach ($fileIterator as $file) {
            $this->dispatcher->dispatch(self::FILE_OPEN, new Event\FileEvent($file));
            if ($file->isPathMatch('/\\.phps$/i')) {
                $this->dispatcher->dispatch(self::FILE_ERROR, new Event\ErrorEvent('You have a .phps file - REMOVE NOW', $file));
            }
            try {
                $this->visitor->setFile($file);
                $this->traverser->traverse($this->parser->parse($file->getContents()));
            } catch (\PhpParser\Error $e) {
                $this->dispatcher->dispatch(self::FILE_ERROR, new Event\ErrorEvent($e->getMessage(), $file));
            }
            $this->dispatcher->dispatch(self::FILE_CLOSE);
        }
        $this->dispatcher->dispatch(self::SCAN_COMPLETE);
    }

Usage Example

Ejemplo n.º 1
0
 public function testErrorOnParseException()
 {
     $file = m::mock('\\Psecio\\Parse\\File');
     $file->shouldReceive('isPathMatch')->once()->with('/\\.phps$/i')->andReturn(false);
     $file->shouldReceive('getContents')->once()->andReturn('');
     $dispatcher = $this->createErrorDispatcherMock();
     $scanner = new Scanner($dispatcher, m::mock('\\Psecio\\Parse\\CallbackVisitor')->shouldReceive('onNodeFailure', 'setFile')->mock(), m::mock('\\PhpParser\\Parser')->shouldReceive('parse')->andThrow(new \PhpParser\Error(''))->mock(), m::mock('\\PhpParser\\NodeTraverser')->shouldReceive('addVisitor')->mock());
     $scanner->scan(m::mock('\\Psecio\\Parse\\FileIterator')->shouldReceive('getIterator')->andReturn(new \ArrayIterator([$file]))->mock());
 }
All Usage Examples Of Psecio\Parse\Scanner::scan