/** * @return FileInfo */ public function current() { /** @var FileInfo $current */ $current = parent::current(); $path = $current->getRealPath(); $mageParts = $this->helper->getMagePathParts($path); $depth = count($mageParts); $info = array('path_parts' => $mageParts); if ($mageParts === false || !in_array('code', $mageParts)) { return new FileInfo(parent::current()->getPathname(), $this->getSubPath(), $this->getSubPathname(), $info); } if ($current->isFile() && $current->getExtension() === 'php') { return new PhpFileInfo(parent::current()->getPathname(), $this->getSubPath(), $this->getSubPathname(), $info); } switch ($depth) { case Helper::MODULE_DEPTH: if (!is_dir($path) || !is_file($path . DIRECTORY_SEPARATOR . 'etc' . DIRECTORY_SEPARATOR . 'config.xml')) { return new FileInfo(parent::current()->getPathname(), $this->getSubPath(), $this->getSubPathname(), $info); } return new ModuleInfo(parent::current()->getPathname(), $this->getSubPath(), $this->getSubPathname(), $info); case Helper::COMPONENT_DEPTH: return new FileInfo(parent::current()->getPathname(), $this->getSubPath(), $this->getSubPathname(), $info); default: return new FileInfo(parent::current()->getPathname(), $this->getSubPath(), $this->getSubPathname(), $info); } }
/** * @todo validate path * @param InputInterface $input * @param OutputInterface $output * @return int|null|void */ public function execute(InputInterface $input, OutputInterface $output) { $finder = new Finder(); $helper = new Helper(); $path = $input->getArgument('path'); $depth = Helper::MODULE_DEPTH - $helper->getCurrentDepth($path) - 1; if ($helper->getCurrentDepth($path) == Helper::MODULE_DEPTH) { $mageParts = $helper->getMagePathParts($path); $module = new ModuleInfo($path, '', '', array('path_parts' => $mageParts)); $finder->append(array($module)); $depth = 0; } $finder->modules()->in($path)->depth($depth); if ($input->getOption('list-modules')) { foreach ($finder as $module) { echo $module->getName(); echo ' (v' . $module->getVersion() . ')'; echo PHP_EOL; } return; } if ($input->getOption('code-metrics')) { foreach ($finder as $module) { echo $module->getName() . PHP_EOL; print_r($module->getCodeMetrics()); echo PHP_EOL . PHP_EOL; } return; } if ($input->getOption('rewrites')) { $globalRewrites = array(); $conflictArray = array(); foreach ($finder as $module) { $rewrites = $module->getRewrites(); if (count($rewrites)) { echo $module->getName() . PHP_EOL; $globalRewrites = array_merge_recursive($globalRewrites, $rewrites); print_r($rewrites); echo PHP_EOL . PHP_EOL; } } foreach ($globalRewrites as $k => $v) { if (count($v) > 1) { $conflictArray[] = array($k => $v); } foreach ($v as $inner) { echo $k . "\t" . $inner . "\n"; } } echo PHP_EOL . PHP_EOL; echo 'Detected conflicts ' . count($conflictArray); echo PHP_EOL; print_r($conflictArray); echo PHP_EOL . PHP_EOL; return; } if ($input->getOption('event-listeners')) { foreach ($finder as $module) { echo $module->getName() . PHP_EOL; print_r($module->getEventListeners()); echo PHP_EOL . PHP_EOL; } return; } if ($input->getOption('cron-jobs')) { foreach ($finder as $module) { echo $module->getName() . PHP_EOL; print_r($module->getCronJobs()); echo PHP_EOL . PHP_EOL; } return; } if ($input->getOption('layout-updates')) { foreach ($finder as $module) { echo $module->getName() . PHP_EOL; print_r($module->getLayoutUpdates()); echo PHP_EOL . PHP_EOL; } return; } if ($input->getOption('overrides')) { foreach ($finder as $module) { echo $module->getName() . PHP_EOL; print_r($module->getOverrides()); echo PHP_EOL . PHP_EOL; } return; } if ($input->getOption('copy-pastes')) { foreach ($finder as $module) { echo $module->getName() . PHP_EOL; print_r($module->getDuplicatedCode()); echo PHP_EOL . PHP_EOL; } return; } }