Beispiel #1
0
 /**
  * Execute command
  *
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @throws \Exception
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->_input = $input;
     $this->_output = $output;
     $this->detectMagento($output, true);
     $this->initMagento();
     $divUtil = new \Mpmd\Util\Div();
     $requestedModules = $this->_input->getArgument('module');
     $allModules = $divUtil->getAllModules();
     $matchCount = array();
     $modules = $divUtil->globArray($allModules, $requestedModules, $matchCount);
     foreach ($matchCount as $pattern => $count) {
         if ($count == 0) {
             throw new \Exception('No match found for pattern: ' . $pattern);
         }
     }
     $output = array();
     $output[] = 'digraph callgraph {';
     $output[] = '';
     $output[] = '    splines=false;';
     $output[] = '    rankdir=LR;';
     $output[] = '    edge[arrowhead=vee, arrowtail=inv, arrowsize=.7, color="#dddddd"];';
     $output[] = '    node [fontname="verdana", shape=plaintext, style="filled", fillcolor="#dddddd"];';
     $output[] = '    fontname="Verdana";';
     $output[] = '';
     foreach ($modules as $module) {
         $dependencies = $divUtil->getDeclaredDepenenciesForModule($module);
         foreach ($dependencies as $dependency) {
             $output[] = "    {$module} -> {$dependency};";
         }
     }
     $output[] = '}';
     echo implode("\n", $output) . "\n";
 }
Beispiel #2
0
 /**
  * Execute command
  *
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @throws \Exception
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->_input = $input;
     $this->_output = $output;
     $this->detectMagento($output, true);
     $this->initMagento();
     $collector = $this->collectData();
     // filter the Mage god class
     $collector->filter(array('Mage'));
     // filter the default classes that come with PHP
     $divUtil = new \Mpmd\Util\Div();
     $collector->filter($divUtil->getDefaultClasses());
     // filter library files
     $libDir = \Mage::getBaseDir('lib');
     $libraryFiles = $collector->filter(function ($className) use($libDir) {
         return !file_exists($libDir . DS . str_replace(' ', DS, ucwords(str_replace('_', ' ', $className))) . '.php');
     });
     $output = array();
     $output[] = 'digraph callgraph {';
     $output[] = '';
     $output[] = '    splines=false;';
     $output[] = '    rankdir=LR;';
     $output[] = '    edge[arrowhead=vee, arrowtail=inv, arrowsize=.7, color="#dddddd"];';
     $output[] = '    node [fontname="verdana", shape=plaintext, style="filled", fillcolor="#dddddd"];';
     $output[] = '    fontname="Verdana";';
     $output[] = '';
     foreach ($collector->getModuleRelations() as $sourceModule => $targetModules) {
         foreach ($targetModules as $targetModule) {
             $table[] = array($sourceModule, $targetModule);
             $output[] = "    {$sourceModule} -> {$targetModule};";
         }
     }
     $output[] = '}';
     echo implode("\n", $output) . "\n";
 }
Beispiel #3
0
 /**
  * Execute command
  *
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @throws \Exception
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->_input = $input;
     $this->_output = $output;
     $this->detectMagento($output, true);
     $this->initMagento();
     $divUtil = new \Mpmd\Util\Div();
     $requestedModules = $this->_input->getArgument('module');
     $allModules = $divUtil->getAllModules();
     $matchCount = array();
     $modules = $divUtil->globArray($allModules, $requestedModules, $matchCount);
     foreach ($matchCount as $pattern => $count) {
         if ($count == 0) {
             throw new \Exception('No match found for pattern: ' . $pattern);
         }
     }
     $table = array();
     foreach ($modules as $module) {
         $dependencies = $divUtil->getDeclaredDepenenciesForModule($module);
         if (count($dependencies) == 0) {
             $table[] = array($module, '[No dependency declared]');
         } else {
             foreach ($dependencies as $dependency) {
                 $table[] = array($module, $dependency);
             }
         }
         $table[] = new TableSeparator();
     }
     // Remove TableSeparator at the end of the table
     if (end($table) instanceof TableSeparator) {
         array_pop($table);
     }
     $this->getHelper('table')->setHeaders(array('Module', 'Dependency'))->renderByFormat($output, $table, $input->getOption('format'));
 }
Beispiel #4
0
 /**
  * Execute command
  *
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @throws \Exception
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->_input = $input;
     $this->_output = $output;
     $this->detectMagento($output, true);
     $this->initMagento();
     $collector = $this->collectData();
     // filter the Mage god class
     $collector->filter(array('Mage'));
     // filter the default classes that come with PHP
     $divUtil = new \Mpmd\Util\Div();
     $collector->filter($divUtil->getDefaultClasses());
     // filter library files except the user wants to include them
     if (!$this->_input->getOption('libraries')) {
         $libDir = \Mage::getBaseDir('lib');
         $libraryFiles = $collector->filter(function ($className) use($libDir) {
             return !file_exists($libDir . DS . str_replace(' ', DS, ucwords(str_replace('_', ' ', $className))) . '.php');
         });
     }
     // get class relations (before filtering)
     $relations = $collector->getClassRelations();
     $output = array();
     $output[] = 'digraph callgraph {';
     $output[] = '';
     $output[] = '    splines=false;';
     $output[] = '    rankdir=LR;';
     $output[] = '    edge[arrowhead=vee, arrowtail=inv, arrowsize=.7, color="#dddddd"];';
     $output[] = '    node [fontname="verdana", shape=plaintext, style="filled", fillcolor="#dddddd"];';
     $output[] = '    fontname="Verdana";';
     $output[] = '';
     if ($this->_input->getOption('group')) {
         foreach ($collector->getClassesByModule() as $module => $classes) {
             $output[] = "    subgraph cluster_{$module} {";
             $output[] = "        style=filled;";
             $output[] = "        color=\"#eeeeee\";";
             $output[] = "        label=\"{$module}\";";
             foreach ($classes as $class) {
                 $output[] = "        node [label=\"{$class}\"] {$class};";
             }
             $output[] = "    }";
             $output[] = '';
         }
     }
     foreach ($relations as $sourceClass => $targetClasses) {
         foreach ($targetClasses as $targetClass => $types) {
             $style = $this->getEdgeStyleForType($types);
             $output[] = "    {$sourceClass} -> {$targetClass} [style=\"{$style}\"];";
         }
     }
     $output[] = '}';
     echo implode("\n", $output) . "\n";
 }
Beispiel #5
0
 /**
  * Execute command
  *
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @throws \Exception
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->_input = $input;
     $this->_output = $output;
     $this->detectMagento($output, true);
     $this->initMagento();
     $moduleName = $this->_input->getOption('module');
     if (!\Mage::getConfig()->getNode('modules/' . $moduleName)) {
         throw new \InvalidArgumentException('Could not find module.');
     }
     $divUtil = new \Mpmd\Util\Div();
     $declaredDepenencies = $divUtil->getDeclaredDepenenciesForModule($moduleName);
     $collector = $this->collectData();
     // filter the Mage god class
     $collector->filter(array('Mage'));
     // filter the default classes that come with PHP
     $collector->filter($divUtil->getDefaultClasses());
     // filter library files
     $libDir = \Mage::getBaseDir('lib');
     $libraryFiles = $collector->filter(function ($className) use($libDir) {
         return !file_exists($libDir . DS . str_replace(' ', DS, ucwords(str_replace('_', ' ', $className))) . '.php');
     });
     $actualDependencies = $collector->getModules();
     $correctDepenencies = array_intersect($actualDependencies, $declaredDepenencies);
     $undeclaredDepenencies = array_diff($actualDependencies, $declaredDepenencies);
     $unusedDeclarations = array_diff($declaredDepenencies, $actualDependencies);
     $table = array();
     foreach ($correctDepenencies as $dependency) {
         $table[] = array($dependency, $dependency, '<info>OK</info>');
     }
     foreach ($unusedDeclarations as $dependency) {
         $table[] = array($dependency, '-', '<warning> Not used </warning>');
     }
     foreach ($undeclaredDepenencies as $dependency) {
         $table[] = array('-', $dependency, '<error> Undeclared </error>');
     }
     $this->getHelper('table')->setHeaders(array('Declared Dependency', 'Actual Dependency', 'Status'))->renderByFormat($output, $table, $input->getOption('format'));
 }
Beispiel #6
0
 /**
  * Get libraries
  *
  * @param array $files
  * @return array
  */
 public function getLibraries(array $files)
 {
     $divUtil = new \Mpmd\Util\Div();
     $libraries = array();
     foreach ($files as $class) {
         $lib = $divUtil->getModuleFromClass($class, 1);
         if (!in_array($lib, $libraries)) {
             $libraries[] = $lib;
         }
     }
     return $libraries;
 }
 /**
  * Execute command
  *
  * @param \Symfony\Component\Console\Input\InputInterface $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @throws \Exception
  * @return void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->_input = $input;
     $this->_output = $output;
     $this->detectMagento($output, true);
     $this->initMagento();
     if (!$this->_input->getOption('modules') && !$this->_input->getOption('libraries') && !$this->_input->getOption('classes') && !$this->_input->getOption('details')) {
         throw new \InvalidArgumentException('Please specify at least one of the following options: --modules, --libraries, --classes, --details');
     }
     $divUtil = new \Mpmd\Util\Div();
     $collector = $this->collectData();
     // filter the Mage god class
     $collector->filter(array('Mage'));
     // get class relations (before filtering)
     $relations = $collector->getClassRelations();
     // filter the default classes that come with PHP
     $collector->filter($divUtil->getDefaultClasses());
     // filter library files
     $libDir = \Mage::getBaseDir('lib');
     $libraryFiles = $collector->filter(function ($className) use($libDir) {
         return !file_exists($libDir . DS . str_replace(' ', DS, ucwords(str_replace('_', ' ', $className))) . '.php');
     });
     // Show dependent modules
     if ($this->_input->getOption('modules')) {
         $table = array();
         foreach ($collector->getModuleRelations() as $sourceModule => $targetModules) {
             foreach ($targetModules as $targetModule) {
                 $table[] = array($sourceModule, $targetModule);
             }
         }
         $this->getHelper('table')->setHeaders(array('Source Module', 'Target Module'))->renderByFormat($output, $table, $input->getOption('format'));
     }
     // Show dependent libraries
     if ($this->_input->getOption('libraries')) {
         $table = array();
         foreach ($collector->getLibraries($libraryFiles) as $lib) {
             $table[] = array($lib);
         }
         $this->getHelper('table')->setHeaders(array('Libraries'))->renderByFormat($output, $table, $input->getOption('format'));
     }
     // Show class to class relations
     if ($this->_input->getOption('classes')) {
         $table = array();
         foreach ($relations as $sourceClass => $targetClasses) {
             foreach ($targetClasses as $targetClass => $types) {
                 $table[] = array($sourceClass, $targetClass, implode(',', $types));
             }
         }
         $this->getHelper('table')->setHeaders(array('Source class', 'Target Class', 'Access Types'))->renderByFormat($output, $table, $input->getOption('format'));
     }
     // Show all details
     if ($this->_input->getOption('details')) {
         $table = array();
         foreach ($collector->getClasses() as $file => $data) {
             foreach ($data as $type => $classes) {
                 foreach ($classes as $class) {
                     $table[] = array($file, $type, $class);
                 }
             }
         }
         $this->getHelper('table')->setHeaders(array('File', 'Access Type', 'Class'))->renderByFormat($output, $table, $input->getOption('format'));
     }
 }