/** * @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 \Symfony\Component\Console\Helper\Table($output); $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())); 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(); return $output->fetch(); }
function run() { $this->dmx = new \DmxHttp\Controller\DMXPost(); $this->dmx->addDevice(new Spot(6)); $this->dmx->addDevice(new Spot(12)); $this->dmx->addDevice(new Spot(18)); $this->dmx->addDevice(new Spot(24)); $this->dmx->addDevice(new Spot(30)); $this->dmx->addDevice(new Spot(36)); $this->dmx->addDevice(new Spot(42)); $this->dmx->addDevice(new Spot(48)); $this->dmx->addDevice(new Scanner(300)); $this->dmx->addDevice(new Scanner(305)); $this->dmx->addDevice(new Scanner(310)); $this->dmx->addDevice(new Scanner(314)); $console = new \Symfony\Component\Console\Application(); $console->register("ls")->setDefinition(array())->setDescription("list devices")->setCode(function (\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output) { $table = new \Symfony\Component\Console\Helper\Table($output); $table->setHeaders(array('Start Channel', 'Type', 'status')); foreach ($this->dmx->getDevices() as $device) { $table->addRow([$device->getStartChannel(), get_class($device), '[' . implode(',', $device->getChannels()) . ']']); } $table->render(); }); $console->register("run")->setDefinition(array(new InputArgument('device', InputArgument::REQUIRED, 'start channel of a device'), new InputArgument('method', InputArgument::REQUIRED, 'method'), new InputArgument('args', InputArgument::IS_ARRAY, 'arguments')))->setDescription("set command")->setCode(function (InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output) { $device = null; foreach ($this->dmx->getDevices() as $_device) { if ($_device->getStartChannel() == $input->getArgument("device")) { $device = $_device; break; } } if ($device === null) { $output->writeln("<error>can't find device</error>"); return 1; } $method = $input->getArgument("method"); $args = $input->getArgument("args"); call_user_func_array([$device, $method], $args); $this->dmx->send(); }); $console->run(); }
/** * @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(); }
} return $post; } $serializer = \Kcs\Serializer\SerializerBuilder::create()->setEventDispatcher(new \Symfony\Component\EventDispatcher\EventDispatcher())->build(); $collection = createCollection(); $metrics = []; $f = function ($format) use($serializer, $collection) { $serializer->serialize($collection, $format); }; // Load all necessary classes into memory. $f('array'); $table = new \Symfony\Component\Console\Helper\Table($output); $table->setHeaders(['Format', 'Direction', 'Time']); $progressBar = new \Symfony\Component\Console\Helper\ProgressBar($output, 8); $progressBar->start(); foreach (['array', 'json', 'yml', 'xml'] as $format) { $table->addRow([$format, 'serialize', benchmark($f, $format)]); $progressBar->advance(); } $serialized = ['array' => $serializer->serialize($collection, 'array'), 'json' => $serializer->serialize($collection, 'json'), 'yml' => $serializer->serialize($collection, 'yml'), 'xml' => $serializer->serialize($collection, 'xml')]; $type = new \Kcs\Serializer\Type\Type('array', [\Kcs\Serializer\Type\Type::from(\Kcs\Serializer\Tests\Fixtures\BlogPost::class)]); $d = function ($format) use($serializer, $serialized, $type) { $serializer->deserialize($serialized[$format], $type, $format); }; foreach (['array', 'json', 'yml', 'xml'] as $format) { $table->addRow([$format, 'deserialize', benchmark($d, $format)]); $progressBar->advance(); } $progressBar->finish(); $progressBar->clear(); $table->render();