Пример #1
0
 /**
  *
  * @TODO: refactor (nearly the same as \MageCompability\Extension::addMethods)
  *
  * @param string $path
  * @return array array of potential performance issues
  */
 protected function _scanForPerformanceLeaks($path)
 {
     $possiblePerformanceLeaks = array();
     $parser = new \PHPParser_Parser(new \PHPParser_Lexer());
     foreach (glob($path . '/*') as $item) {
         if (is_dir($item)) {
             $possiblePerformanceLeaks = array_merge($possiblePerformanceLeaks, $this->_scanForPerformanceLeaks($item));
         }
         if (is_file($item) && is_readable($item)) {
             if ($this->_isUnitTestFile($item)) {
                 continue;
             }
             /* we assume that there are only php files */
             if (substr($item, -6) == '.stmts.xml') {
                 unlink($item);
                 continue;
             }
             $fileNameParts = explode('.', basename($item));
             $extension = end($fileNameParts);
             if (false === in_array($extension, array('php', 'phtml'))) {
                 continue;
             }
             try {
                 $stmts = $parser->parse(file_get_contents($item));
                 $serializer = new \PHPParser_Serializer_XML();
                 $xml = $serializer->serialize($stmts);
                 //                    file_put_contents($item . '.stmts.xml', var_export($xml, true));
                 $leaks = $this->_collectPerformanceKillers(simplexml_load_string($xml), $item);
                 $possiblePerformanceLeaks = array_merge($possiblePerformanceLeaks, $leaks);
             } catch (\PHPParser_Error $e) {
                 // no valid php
                 continue;
             }
         }
     }
     return $possiblePerformanceLeaks;
 }
Пример #2
0
 /**
  * @expectedException        InvalidArgumentException
  * @expectedExceptionMessage Unexpected node type
  */
 public function testError()
 {
     $serializer = new PHPParser_Serializer_XML();
     $serializer->serialize(array(new stdClass()));
 }
Пример #3
0
 protected function _addMethods($path)
 {
     $parser = new \PHPParser_Parser(new \PHPParser_Lexer());
     foreach (glob($path . '/*') as $item) {
         if (is_dir($item)) {
             $this->_addMethods($item);
         }
         if (is_file($item) && is_readable($item)) {
             if ($this->_isUnitTestFile($item)) {
                 continue;
             }
             /* we assume that there are only php files */
             if (substr($item, -6) == '.stmts.xml') {
                 unlink($item);
                 continue;
             }
             $fileNameParts = explode('.', basename($item));
             $extension = end($fileNameParts);
             if (false === in_array($extension, array('php', 'phtml'))) {
                 continue;
             }
             try {
                 $stmts = $parser->parse(file_get_contents($item));
                 //echo $item . PHP_EOL;
                 $serializer = new \PHPParser_Serializer_XML();
                 $xml = $serializer->serialize($stmts);
                 if (@simplexml_load_string($xml) === false) {
                     continue;
                 } else {
                     //                        file_put_contents($item . '.stmts.xml', var_export($xml, true));
                     $numberOfMethodCalls = $this->_collectMethodCalls($stmts, simplexml_load_string($xml));
                 }
                 //echo PHP_EOL;
             } catch (\PHPParser_Error $e) {
                 // no valid php
                 continue;
             }
         }
     }
 }