/** * @param array $args */ public function handle(array $args) { $this->cli->out(sprintf('PHPAssumptions analyser v%s by @rskuipers', Cli::VERSION))->br(); try { $this->cli->arguments->parse($args); } catch (\Exception $e) { $this->cli->usage($args); return; } switch ($this->cli->arguments->get('format')) { case 'xml': $output = new XmlOutput($this->cli, $this->cli->arguments->get('output')); break; default: $output = new PrettyOutput($this->cli); break; } $nodeTraverser = new NodeTraverser(); $analyser = new Analyser($this->parser, $nodeTraverser); $nodeTraverser->addVisitor(new NodeVisitor($analyser, new Detector())); $target = $this->cli->arguments->get('path'); $targets = []; if (is_file($target)) { $targets[] = $target; } else { $directory = new \RecursiveDirectoryIterator($target); $iterator = new \RecursiveIteratorIterator($directory); $regex = new \RegexIterator($iterator, '/^.+\\.php$/i', \RecursiveRegexIterator::GET_MATCH); foreach ($regex as $file) { $targets[] = $file[0]; } } $result = $analyser->analyse($targets); $output->output($result); }
/** * @param Result $result */ public function output(Result $result) { if ($result->getAssumptionsCount() > 0) { $this->cli->table($result->getAssumptions())->br(); } $this->cli->out(sprintf('%d out of %d boolean expressions are assumptions (%d%%)', $result->getAssumptionsCount(), $result->getBoolExpressionsCount(), $result->getPercentage())); }
/** * {@inheritdoc} */ public function load($path, array $arguments = []) { $content = $this->loader->load($path, $arguments); $this->cli->out($content); $bufferWriter = $this->output->get('buffer'); return $bufferWriter->get(); }
/** * @param Result $result */ public function output(Result $result) { $assumptions = $result->getAssumptions(); foreach ($assumptions as $assumption) { $fileElements = $this->xpath->query('/phpa/files/file[@name="' . $assumption['file'] . '"]'); if ($fileElements->length === 0) { $files = $this->xpath->query('/phpa/files')->item(0); $fileElement = $this->document->createElement('file'); $fileElement->setAttribute('name', $assumption['file']); $files->appendChild($fileElement); } else { $fileElement = $fileElements->item(0); } $lineElement = $this->document->createElement('line'); $lineElement->setAttribute('number', $assumption['line']); $lineElement->setAttribute('message', $assumption['message']); $fileElement->appendChild($lineElement); } $this->document->documentElement->setAttribute('assumptions', $result->getAssumptionsCount()); $this->document->documentElement->setAttribute('bool-expressions', $result->getBoolExpressionsCount()); $this->document->documentElement->setAttribute('percentage', $result->getPercentage()); $this->document->preserveWhiteSpace = false; $this->document->formatOutput = true; $this->document->save($this->file); $this->cli->out(sprintf('Written %d assumption(s) to file %s', $result->getAssumptionsCount(), $this->file)); }
/** * Finish testing of a particular class * @param string $exerciseErrorMessage Formatted error message related to what failed * @throws Exception Throws an exception to pass control back up a level */ private function finishChapter($exerciseErrorMessage) { $terminal = new Terminal(); $terminal->bold()->out(" Chapter " . $this->chapter->number . ": " . $this->chapter->name . "\n"); $terminal->out($exerciseErrorMessage); $terminal->br(); $terminal->out(' Chapter ' . $this->chapter->number . ' is ' . $this->percentComplete() . '% complete.'); $terminal->br(); throw new \Exception(); }
/** * @test */ public function itShouldAnalyseTargetFileAndOutputXml() { $path = fixture('MyClass.php'); $output = tempnam(sys_get_temp_dir(), 'xml'); $this->argumentManager->get('format')->shouldBeCalled()->willReturn('xml'); $this->argumentManager->get('path')->shouldBeCalled()->willReturn($path); $this->argumentManager->get('output')->shouldBeCalled()->willReturn($output); $this->climate->out('Written 1 assumption(s) to file ' . $output)->shouldBeCalled(); $this->cli->handle(['phpa', $path]); $this->assertTrue(is_file($output)); }
/** * Output the full summary for the program */ public function output() { // Print the description if it's defined. if ($this->description) { $this->climate->out($this->description)->br(); } // Print the usage statement with the arguments without a prefix at the end. $this->climate->out("Usage: {$this->command} " . $this->short($this->getOrderedArguments())); // Print argument details. foreach (['required', 'optional'] as $type) { $this->outputArguments($this->filter->{$type}(), $type); } }
public function run($args) { $cli = new CLImate(); $backup_dir = Setting::getSetting('consh:db_backup_folder'); if (!file_exists($backup_dir)) { if (!mkdir($backup_dir, 0777, true)) { $cli->error("Could not create database backup folder: {$backup_dir}"); return false; } } if (count($args) != 1) { $cli->error("Please pass along the filename to import"); if ($handle = opendir($backup_dir)) { $cli->out("possible files:"); while (false !== ($entry = readdir($handle))) { if ($entry != '.' && $entry != '..') { $cli->out($entry); } } } else { $cli->error("Could not open database backup folder"); } return false; } $file = $args[0]; $path = $backup_dir . "/" . $file; if (!file_exists($path)) { $cli->error("{$file} does not exist"); return false; } $sql = file($path); $db = new LocalDB(); $templine = ''; $size = count($sql); $cli->out("Restoring database"); $progress = $cli->progress()->total($size); $current = 0; foreach ($sql as $line) { $current++; // Skip it if it's a comment if (substr($line, 0, 2) == '--' || $line == '') { continue; } $templine .= $line; if (substr(trim($line), -1, 1) == ';') { $db->execute($templine); $progress->current($current); $templine = ''; } } }
public function run($args) { $cli = new CLImate(); $file_name = 'db_' . time() . '.sql'; $remote_file = Remote::getHomePath() . $file_name; $local_file = Local::getDocRoot() . "{$file_name}"; $ssh = SSHConnection::getInstance(); $ssh->exec('mysqldump -h ' . Setting::getSetting('mysql:host') . ' -u ' . Setting::getSetting('mysql:user') . ' -p' . addslashes(Setting::getSetting('mysql:pass')) . ' ' . Setting::getSetting('mysql:db') . " > " . $remote_file); $ssh->scpRemoteLocal($remote_file, $local_file); $ssh->rmRemoteFile($remote_file); $sql = file($local_file); $db = new LocalDB(); $templine = ''; $size = count($sql); $cli->out("Importing database"); $progress = $cli->progress()->total($size); $current = 0; foreach ($sql as $line) { $current++; // Skip it if it's a comment if (substr($line, 0, 2) == '--' || $line == '') { continue; } $templine .= $line; if (substr(trim($line), -1, 1) == ';') { $db->execute($templine); $progress->current($current); $templine = ''; } } unlink($local_file); }
/** * * @param string $string * @return void */ protected function _log_out($string) { if (!$this->_logger) { return; } $this->_logger->out($string); return; }
/** * Receives the messages and pass them to sender */ public function handle() { $this->channel->basic_consume($this->listenQueue, '', false, true, false, false, function ($msg) { $this->climate->br(); $this->climate->info('Received: ' . $msg->body); $input = json_decode($msg->body, true); try { $output = $this->interestCalculator->caculateInterest($input); $output['token'] = $this->token; $output = json_encode($output); $this->climate->out('Sending back: ' . $output); $this->channel->basic_publish($this->amqpFactory->buildMessage($output), '', $this->broadcastQueue); } catch (Exception $e) { $this->climate->error('Unable to handle the message: ' . $e->getMessage()); return false; } return true; }); while (count($this->channel->callbacks)) { $this->channel->wait(); } $this->channel->close(); $this->connection->close(); }
/** * @param CLImate $cli * @param array $arguments * @return void */ public function execute(CLImate $cli, $arguments) { if (!$arguments['trackingNumber']) { $cli->error('ERROR. No tracking number provided.'); return null; } $chronopostAdapter = new ChronopostAdapter(); $deliveryTracking = new DeliveryTracking($chronopostAdapter); $cli->br(); try { $status = $deliveryTracking->getDeliveryStatus($arguments['trackingNumber']); $cli->out(sprintf('Delivery #%s is <green>%s</green>', $arguments['trackingNumber'], $status)); } catch (\Exception $e) { $cli->error(sprintf('ERROR. %s', $e->getMessage())); } $cli->br(); }
public function run($args) { $cli = new CLImate(); $file_name = 'db_' . time() . '.sql'; $remote_file = Remote::getHomePath() . $file_name; $local_file = Setting::getSetting('consh:db_backup_folder') . "/{$file_name}"; if (!file_exists(Setting::getSetting('consh:db_backup_folder'))) { if (!mkdir(Setting::getSetting('consh:db_backup_folder'), 0777, true)) { $cli->error("Could not create database backup folder: " . Setting::getSetting('consh:db_backup_folder')); return false; } } $ssh = SSHConnection::getInstance(); $ssh->exec('mysqldump -h ' . Setting::getSetting('mysql:host') . ' -u ' . Setting::getSetting('mysql:user') . ' -p' . addslashes(Setting::getSetting('mysql:pass')) . ' ' . Setting::getSetting('mysql:db') . " > " . $remote_file); $ssh->scpRemoteLocal($remote_file, $local_file); $ssh->rmRemoteFile($remote_file); $cli->out("File saved to {$local_file}"); }
/** * @param array $commands */ public function executeOnRemoteServer(array $commands) { /* * @var \phpseclib\Net\SFTP */ $connection = $this->connection->getAdapter()->getConnection(); if ($this->servers[$this->currentlyDeploying]['scheme'] != 'sftp' || get_class($connection) != \phpseclib\Net\SFTP::class) { $this->cli->yellow()->out("\r\nConnection scheme is not 'sftp' ignoring [pre/post]-deploy-remote"); return; } if (!$connection->isConnected()) { $this->cli->red()->out("\r\nSFTP adapter connection problem skipping '[pre/post]-deploy-remote' commands"); return; } foreach ($commands as $command) { $this->cli->out("Execute remote : <white>{$command}"); $output = $connection->exec($command); $this->cli->out("Result remote: <white>{$output}"); } }
/** * @param CLImate $cli * @param array $arguments * @return void */ public function execute(CLImate $cli, $arguments) { if (!$arguments['reference']) { $cli->error('ERROR. No reference provided.'); return null; } $cli->comment('Warning: this command may be slow. It may download and parse a lot of file.'); $cli->comment('I you know the tracking number, you may want to use the `tracking:status [trackingNumber]` command'); $chronopostAdapter = new ChronopostFtpAdapter(['host' => 'ftpserv.chronopost.fr', 'username' => 'arconseil', 'password' => '!arcnsl$']); $deliveryTracking = new DeliveryTracking($chronopostAdapter); $cli->br(); try { $status = $deliveryTracking->getDeliveryStatusByInternalReference($arguments['reference']); $cli->out(sprintf('Delivery #%s is <green>%s</green>', $arguments['reference'], $status)); $trackingNumber = $deliveryTracking->getTrackingNumberByInternalReference($arguments['reference']); $cli->whisper(sprintf('The associated tracking Number is %s.', $trackingNumber)); } catch (\Exception $e) { $cli->error(sprintf('ERROR. %s', $e->getMessage())); } $cli->br(); }
public function help() { $cli = new CLImate(); $cli->out("This command will pull both the files and the database from the remote server"); }
/** * execute a command on the remote server * @param $command string command to execute on the remote server */ public function exec($command) { $cli = new CLImate(); $con = $this->getConnection(); $cli->out($con->exec($command . "\n")); }
* */ error_reporting(E_ALL); ini_set('display_errors', 1); require_once __DIR__ . '/vendor/autoload.php'; define('ALEXLVCOM_TASK_RUNNER_VERSION', '0.0.2'); define('TASK_PATH', __DIR__ . '/app/tasks'); define('TASK_LOG_PATH', __DIR__ . '/app/logs'); define('ROOTPATH', __DIR__ . '/'); use League\CLImate\CLImate; use alexlvcom\TaskRunner\CommandContext; use alexlvcom\TaskRunner\ParamValidator; use alexlvcom\ServiceContainer\Container as ServiceContainer; $climate = new CLImate(); $container = new ServiceContainer(); $climate->out('<green>Task Runner by AlexLV. (c) 2015 .</green> <white>Version <yellow>' . ALEXLVCOM_TASK_RUNNER_VERSION . '</yellow>'); $climate->br(); $climate->arguments->add(['name' => ['longPrefix' => 'name', 'description' => 'Task Name', 'required' => true]]); try { $climate->arguments->parse(); } catch (Exception $e) { $climate->error($e->getMessage())->br()->usage(); $climate->br(); exit; } if ($climate->arguments->defined('name') === false || $climate->arguments->get('name') === '') { $climate->usage(); exit; } $time_start = microtime(true); $taskName = $climate->arguments->get('name');
use League\CLImate\CLImate; use StaticReview\Issue\Issue; use StaticReview\Reporter\Reporter; use StaticReview\Review\Message\BodyLineLengthReview; use StaticReview\Review\Message\SubjectImperativeReview; use StaticReview\Review\Message\SubjectLineCapitalReview; use StaticReview\Review\Message\SubjectLineLengthReview; use StaticReview\Review\Message\SubjectLinePeriodReview; use StaticReview\Review\Message\WorkInProgressReview; use StaticReview\StaticReview; use StaticReview\VersionControl\GitVersionControl; $reporter = new Reporter(); $climate = new CLImate(); $git = new GitVersionControl(); $review = new StaticReview($reporter); // Add any reviews to the StaticReview instance, supports a fluent interface. $review->addReview(new BodyLineLengthReview())->addReview(new SubjectImperativeReview())->addReview(new SubjectLineCapitalReview())->addReview(new SubjectLineLengthReview())->addReview(new SubjectLinePeriodReview())->addReview(new WorkInProgressReview()); // Check the commit message. $review->message($git->getCommitMessage($argv[1])); // Check if any matching issues were found. if ($reporter->hasIssues()) { $climate->out('')->out(''); foreach ($reporter->getIssues() as $issue) { $climate->red($issue); } $climate->out('')->red('✘ Please fix the errors above using: git commit --amend'); exit(0); } else { $climate->green('✔ That commit looks good!'); exit(0); }
/** * Prints a console message only if verbose is on * * @param $msg */ public function out($msg) { if ($this->config->get('general', 'verbose')) { $this->climate->out($msg); } }
/** * Returns CLImate output * * @param string $string Output * @return mixed */ public function out($string) { return $this->climate->out($string); }
use StaticReview\Review\General\LineEndingsReview; use StaticReview\Review\PHP\PhpCodeSnifferReview; use StaticReview\Review\PHP\PhpLintReview; use StaticReview\StaticReview; use StaticReview\VersionControl\GitVersionControl; $reporter = new Reporter(); $climate = new CLImate(); $git = new GitVersionControl(); $review = new StaticReview($reporter); // Add any reviews to the StaticReview instance, supports a fluent interface. $review->addReview(new LineEndingsReview())->addReview(new PhpLintReview())->addReview(new ComposerLintReview())->addReview(new ComposerSecurityReview()); $codeSniffer = new PhpCodeSnifferReview(); $codeSniffer->setOption('standard', 'PSR2'); $review->addReview($codeSniffer); if ($git->getStagedFiles()->count() === 0) { $climate->out('')->yellow('[-] Nothing to do.')->white('No files founded in the git staged.'); exit(0); } // Review the staged files. $review->files($git->getStagedFiles()); // Check if any matching issues were found. if ($reporter->hasIssues()) { $climate->out('')->out(''); foreach ($reporter->getIssues() as $issue) { $climate->red($issue); } $climate->out('')->red('[x] Please fix the errors above.'); exit(1); } else { $climate->out('')->green('[+] Very well guy.')->white('No issues detected, the commit will be performed in the next step.'); exit(0);
} // Reference the required classes and the reviews you want to use. use League\CLImate\CLImate; use StaticReview\Reporter\Reporter; use StaticReview\Review\Composer\ComposerLintReview; use StaticReview\Review\General\LineEndingsReview; use StaticReview\Review\General\NoCommitTagReview; use StaticReview\Review\PHP\PhpLeadingLineReview; use StaticReview\Review\PHP\PhpLintReview; use StaticReview\StaticReview; use StaticReview\VersionControl\GitVersionControl; $reporter = new Reporter(); $climate = new CLImate(); $git = new GitVersionControl(); $review = new StaticReview($reporter); // Add any reviews to the StaticReview instance, supports a fluent interface. $review->addReview(new LineEndingsReview())->addReview(new PhpLeadingLineReview())->addReview(new NoCommitTagReview())->addReview(new PhpLintReview())->addReview(new ComposerLintReview()); // Review the staged files. $review->review($git->getStagedFiles()); // Check if any matching issues were found. if ($reporter->hasIssues()) { $climate->out('')->out(''); foreach ($reporter->getIssues() as $issue) { $climate->red($issue); } $climate->out('')->red('✘ Please fix the errors above.'); exit(1); } else { $climate->out('')->green('✔ Looking good.')->white('Have you tested everything?'); exit(0); }
public function showDefaultHelp() { $cli = new CLImate(); $cli->out("Please enter a command"); $cli->out("Try consh help for more help or consh <command> help for more details about the command"); }