示例#1
0
    public function testStripNodes()
    {
        $reader = new Reader(<<<EOF
<?php
namespace {
    class ClassName
    {
        public function foobar()
        {
            include "somefile.php";
            echo 'foobar';
        }
    }
}
EOF
);
        $expected = <<<EOF
namespace  {
    class ClassName
    {
        public function foobar()
        {
            echo 'foobar';
        }
    }
}
EOF;
        $writer = new Writer();
        $writer->apply(new NodeStripper('Expr_Include'));
        $this->assertEquals($expected, $writer->write($reader->read('ClassName')));
    }
    public function testStripComments()
    {
        $reader = new Reader(<<<EOF
<?php
/**
 * File docblock comment
 */

/**
 * Class docblock
 */
class ClassName
{
    /**
     * @var string Some desc
     */
    private \$var;

    /**
     * Some docblock here too
     */
    public function test()
    {
        // inline comment
        return true; // comment at end of line
        /*
            Comment
        */
        # Comment...
    }
}
EOF
);
        $expected = <<<EOF
namespace  {
    class ClassName
    {
        private \$var;
        public function test()
        {
            return true;
        }
    }
}
EOF;
        $writer = new Writer();
        $writer->apply(new CommentStripper());
        $this->assertEquals($expected, $writer->write($reader->read('ClassName')));
    }
示例#3
0
 /**
  * Load minimizing translations at construct
  *
  * @param NodeTraverser $traverser
  */
 public function __construct(NodeTraverser $traverser = null)
 {
     parent::__construct($traverser);
     $this->apply(new CommentStripper());
     $this->apply(new NameResolver());
     $this->apply(new NodeStripper('Stmt_Use'));
 }
示例#4
0
 public function __construct(NodeTraverser $traverser = null)
 {
     parent::__construct($traverser);
     $this->apply(new NodeStripper('Expr_Include'));
     $this->apply(new CommentStripper());
     $this->apply(new NamespaceWrapper('fpdi'));
     $this->apply(new NameResolver());
     $this->apply(new NamespaceCrawler(['', '\\fpdf'], ['\\fpdi']));
     $this->apply(new TcpdfResolver());
 }
    public function testWhitelistNamespace()
    {
        $reader = new Reader(<<<EOF
<?php
class ClassName
{
    public function foobar()
    {
        new \\whitelist\\NonExistingClass();
    }
}
EOF
);
        $writer = new Writer();
        $writer->apply(new NameResolver());
        $writer->apply(new NamespaceCrawler([''], ['whitelist']));
        // NonExistingClass does not resolve, but no exception is thrown
        $this->assertTrue(is_string($writer->write($reader->read('ClassName'))));
    }
    public function testIgnoreExtendedEmptyNamespace()
    {
        $reader = new Reader(<<<EOF
<?php
namespace foobar {
    class ClassName
    {
    }
}
EOF
);
        $expected = <<<EOF
namespace foobar {
    class ClassName
    {
    }
}
EOF;
        $writer = new Writer();
        // Assert that a empty second wrapper makes no difference
        $writer->apply(new NamespaceWrapper(''));
        $this->assertEquals($expected, $writer->write($reader->read('foobar\\ClassName')));
    }
示例#7
0
 /**
  * Transform found classes
  *
  * @param  Writer $writer
  * @return string
  */
 public function transform(Writer $writer)
 {
     $code = '';
     /** @var SplFileInfo $fileInfo */
     foreach ($this->getClassMap() as $name => $fileInfo) {
         $code .= $writer->write($fileInfo->getReader()->read($name)) . "\n";
     }
     return "<?php {$code}";
 }