/** * @param array $rows */ private function printBody(array $rows) { if (!count($rows)) { $this->output->writeln('<info>No violations.</info>'); return; } $this->printRows($rows); }
public function postInstall(Request $request, Installer $installer, Dispatcher $dispatcher) { $output = new BufferedOutput(); $installer->setFieldValues($request->all()); $versions = $installer->getVersions(); foreach ($versions as $version) { $tasks = $installer->getTasksForVersion($version); foreach ($tasks as $task) { $output->writeln('<span class="text-info">Running ' . $task->getTitle() . ' Task...</span>'); try { $task->setInput($installer->getFieldValues()); $task->run($output); } catch (TaskRunException $e) { $output->writeln('<span class="text-danger">' . $e->getMessage() . '</span>'); return new JsonResponse(['output' => $output, 'status' => 'error'], 200); } $output->writeln('<span class="text-info">Task ' . $task->getTitle() . ' Completed!</span>'); } } $dispatcher->fire(new AfterInstallEvent($installer, $output)); $installer->saveCompleted(); $output->writeln('<span class="text-success">Installation Completed!</span>'); $output = array_filter(explode("\n", $output->fetch())); return new JsonResponse(['output' => $output, 'status' => 'success'], 200); }
public function onKernelException(GetResponseForExceptionEvent $event) { $request = $event->getRequest(); if ($this->isRequestAcceptsJson($request)) { $exception = $event->getException(); $response = new JsonResponse(['message' => $exception->getMessage(), 'trace' => $exception->getTrace(), 'code' => $exception->getCode()]); $event->setResponse($response); } if ($this->isRequestFromTests($request)) { $exception = $event->getException(); $output = new BufferedOutput(OutputInterface::VERBOSITY_VERBOSE, true); $output->writeln($exception->getMessage()); $output->writeln($exception->getCode()); $output->writeln($exception->getTraceAsString()); $response = new Response($output->fetch()); $event->setResponse($response); } }
/** * Test if overriding a parameter works. * * @param string $script The script to run. * * @param string $definition The argument to pass. * * @param string $expectedValue The expected output value. * * @return bool */ private function testOverride($script, $definition, $expectedValue) { $output = $this->testCliRuntime($script, $definition); if ($expectedValue !== $output) { $this->log->writeln('Could not override via ' . $definition); return false; } return true; }
/** * @inheritdoc */ public function terminate(ResultCollection $collection, ResultCollection $groupedResults) { $output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true); // $output->write(str_pad("\x0D", 80, "\x20")); // $output->writeln(''); // overview $total = $this->bound->calculate($collection); $output->writeln(sprintf('<info>%d</info> files have been analyzed. Read and understand these <info>%s</info> lines of code will take around <info>%s</info>.', sizeof($collection, COUNT_NORMAL), $total->getSum('loc'), $this->formatTime($total->getSum('time')))); $output->writeln('<info>Average for each module:</info>'); $output->writeln(''); $hasOOP = null !== $total->getSum('instability'); $table = new TableHelper(); $table->setHeaders(array_merge(array('Name', 'Complexity', 'Myer Distance', 'Maintainability', 'LLOC', 'Comment weight', 'Vocabulary', 'Volume', 'Bugs', 'Difficulty'), $hasOOP ? array('lcom', 'SysComplexity', 'Instability', 'Abstractness', 'ce', 'ca') : array()))->setLayout(TableHelper::LAYOUT_DEFAULT); foreach ($groupedResults as $result) { $table->addRow(array_merge(array(str_repeat(' ', $result->getDepth()) . $result->getName(), $this->getRow($result->getBounds(), 'cyclomaticComplexity', 'average', 0), $this->getRow($result->getBounds(), 'myerDistance', 'average', 0), $this->getRow($result->getBounds(), 'maintainabilityIndex', 'average', 0), $this->getRow($result->getBounds(), 'logicalLoc', 'sum', 0), $this->getRow($result->getBounds(), 'commentWeight', 'average', 0), $this->getRow($result->getBounds(), 'vocabulary', 'average', 0), $this->getRow($result->getBounds(), 'volume', 'average', 0), $this->getRow($result->getBounds(), 'bugs', 'sum', 2), $this->getRow($result->getBounds(), 'difficulty', 'average', 0)), $hasOOP ? array($this->getRow($result->getBounds(), 'lcom', 'average', 2), $this->getRow($result->getBounds(), 'rsysc', 'average', 2), $result->getInstability()->getInstability(), $result->getAbstractness()->getAbstractness(), $this->getRow($result->getBounds(), 'efferentCoupling', 'average', 2), $this->getRow($result->getBounds(), 'afferentCoupling', 'average', 2)) : array())); } $table->render($output); return $output->fetch(); }
protected function execute(InputInterface $input, OutputInterface $output) { $componentName = $input->getOption('component'); if (!$componentName) { $output->writeln('<error>Component name must be given</error>'); $output->writeln('<comment>Use -c option to specify component name</comment>'); return 1; // set error status code } $component = new BitrixComponent($componentName); if (!$component->exists()) { $output->writeln("<error>Component {$componentName} not found </error>"); return 1; } $templateName = $input->getArgument('template'); if (!$templateName) { $templateName = ''; } $buff = new BufferedOutput(); $buff->writeln(sprintf('<?$APPLICATION->IncludeComponent("%s", "%s", array(', $component->getFullName(), $templateName)); $parameters = $component->getParameters()['PARAMETERS']; if ($input->getOption('sort')) { ksort($parameters); } foreach ($parameters as $name => $settings) { // TODO: Добавить вывод комментария с именем параметра. $defaultValue = $settings['DEFAULT'] ? $settings['DEFAULT'] : ''; $buff->writeln(sprintf(' "%s" => %s,', $name, var_export($defaultValue, true))); } $buff->writeln(' ),'); $buff->writeln(' false'); $buff->writeln(');/*' . $componentName . "*/?>"); $code = $buff->fetch(); if ($input->getOption('xclip')) { $clip = new ClipboardStream(); $clip->write($code); $output->writeln('<comment>Generated code was copied to clipboard</comment>'); } else { $output->write("<info>{$code}</info>"); } }
/** * Test the passed binaries. * * @param string[] $binaries The binaries to test. * * @return bool */ private function isAnyBinaryValid($binaries) { foreach ($binaries as $binary) { if ($version = $this->testCliRuntime($binary)) { if (version_compare($version, '5.4', '<')) { $this->log->writeln(sprintf('%s version is too low (%s)', $binary, $version)); return false; } $this->markSuccess('Found ' . $binary . ' (Version: ' . $version . ')'); $this->getAutoConfig()->setPhpCliBinary($binary); return true; } } return false; }
/** * @inheritdoc */ public function terminate(ResultCollection $collection, ResultCollection $groupedResults) { $output = new BufferedOutput(OutputInterface::VERBOSITY_NORMAL, true); // $output->write(str_pad("\x0D", 80, "\x20")); // $output->writeln(''); // overview $total = $this->bound->calculate($collection); $output->writeln(sprintf('<info>%d</info> files have been analyzed. Read and understand these <info>%s</info> lines of code will take around <info>%s</info>.', sizeof($collection, COUNT_NORMAL), $total->getSum('loc'), $this->formatTime($total->getSum('time')))); $output->writeln('<info>Average for each module:</info>'); $output->writeln(''); $hasOOP = null !== $total->getSum('instability'); $output->writeln('1 - Complexity'); $output->writeln('2 - Myer Distance: derivated from Cyclomatic complexity'); $output->writeln('3 - Maintainability'); $output->writeln('4 - LLOC: Number of logical lines of code'); $output->writeln('5 - Comment weight: measure the ratio between logical code and comments'); $output->writeln('6 - Vocabulary used in code'); $output->writeln('7 - Volume'); $output->writeln('8 - Bugs: Number of estimated bugs by file'); $output->writeln('9 - Difficulty of the code'); $output->writeln('A - LCOM: Lack of cohesion of methods measures the cohesiveness of a class'); $output->writeln('B - System complexity'); $output->writeln('C - Instability: Indicates the class is resilience to change'); $output->writeln('D - Abstractness: Number of abstract classes'); $output->writeln('E - Efferent coupling (CE): Number of classes that the class depend'); $output->writeln('F - Afferent coupling (CA): Number of classes affected by this class'); $output->writeln(''); $output->writeln('More details about metrics: http://www.phpmetrics.org/documentation/index.html'); $table = new \Symfony\Component\Console\Helper\Table($output); $table->setHeaders(array_merge(array('1', '2', '3', '4', '5', '6', '7', '8', '9'), $hasOOP ? array('A', 'B', 'C', 'D', 'E', 'F') : array())); foreach ($groupedResults as $key => $result) { if ($result->getDepth() > 1) { $table->addRow(new TableSeparator()); } $table->addRow(array(new TableCell($result->getName(), array('colspan' => 15)))); $table->addRow(new TableSeparator()); $table->addRow(array_merge(array($this->getRow($result->getBounds(), 'cyclomaticComplexity', 'average', 0), $this->getRow($result->getBounds(), 'myerDistance', 'average', 0), $this->getRow($result->getBounds(), 'maintainabilityIndex', 'average', 0), $this->getRow($result->getBounds(), 'logicalLoc', 'sum', 0), $this->getRow($result->getBounds(), 'commentWeight', 'average', 0), $this->getRow($result->getBounds(), 'vocabulary', 'average', 0), $this->getRow($result->getBounds(), 'volume', 'average', 0), $this->getRow($result->getBounds(), 'bugs', 'sum', 2), $this->getRow($result->getBounds(), 'difficulty', 'average', 0)), $hasOOP ? array($this->getRow($result->getBounds(), 'lcom', 'average', 2), $this->getRow($result->getBounds(), 'rsysc', 'average', 2), $result->getInstability()->getInstability(), $result->getAbstractness()->getAbstractness(), $this->getRow($result->getBounds(), 'efferentCoupling', 'average', 2), $this->getRow($result->getBounds(), 'afferentCoupling', 'average', 2)) : array())); } $table->render(); return $output->fetch(); }
/** * {@inheritdoc} */ public function writeln($messages, $type = self::OUTPUT_NORMAL) { parent::writeln($messages, $type); $this->outputBuffered->writeln($this->reduceBuffer($messages), $type); }