Ejemplo n.º 1
0
 /**
  * Output messages to the terminal.
  *
  * @param string $message
  * @param string $style
  *
  * @return void
  */
 public function out($message, $style = 'info')
 {
     switch ($style) {
         case 'info':
             $this->cli->blue($message);
             break;
         case 'success':
             $this->cli->green($message);
             break;
         case 'error':
             $this->cli->red($message);
             break;
         case 'warning':
             $this->cli->yellow($message);
             break;
     }
 }
Ejemplo n.º 2
0
echo PHP_EOL;
$climate = new CLImate();
$warnings = $errors = $info = 0;
if ($reporter->hasIssues()) {
    foreach ($reporter->getIssues() as $issue) {
        /** @var Issue $issue */
        if ($issue->getLevel() == Issue::LEVEL_INFO) {
            (new Process('git add ' . $issue->getSubject()->getName()))->run();
            ++$info;
        }
        if ($issue->getLevel() == Issue::LEVEL_WARNING) {
            ++$warnings;
        }
        if ($issue->getLevel() == Issue::LEVEL_ERROR) {
            $climate->backgroundRed($issue->getMessage());
            ++$errors;
        }
    }
}
if ($errors > 0) {
    $climate->backgroundRed('✘ Review has found errors.');
} elseif ($warnings > 0) {
    $climate->yellow('Review has found warnings.');
} elseif ($info > 0) {
    $climate->green('Review has found some problems and fixed them manually.');
} else {
    $climate->green('✔ Looking good. Have you tested everything?');
}
// Check if any issues were found.
// Exit with a non-zero to block the commit.
$errors > 0 ? exit(1) : exit(0);
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);
}
Ejemplo n.º 4
0
array_shift($argv);
// Discard the filename
$pathinfo = array_shift($argv);
if (empty($pathinfo)) {
    $pathinfo = '--help';
}
// Create our app instance
$app = new SlimController\Slim(['debug' => false, 'controller.class_prefix' => '', 'controller.class_suffix' => '', 'controller.method_suffix' => 'Action', 'controller.template_suffix' => '']);
// Set up the environment so that Slim can route
$app->environment = Slim\Environment::mock(['PATH_INFO' => $pathinfo]);
// Define the help command. If it doesn't have a name it won't include itself
$app->get('--help', function () use($app) {
    $writer = new CLImate();
    $writer->bold()->out('Available commands:');
    foreach ($app->router()->getNamedRoutes() as $route) {
        $writer->green()->out('    ' . $route->getPattern());
    }
});
// CLI-compatible not found error handler
$app->notFound(function () use($app) {
    $writer = new CLImate();
    $command = $app->environment['PATH_INFO'];
    $writer->red()->bold()->out(sprintf('Error: Cannot route to command "%s"', $command));
    $helpRoute = $app->router()->getMatchedRoutes('GET', '--help', true);
    $helpRoute[0]->dispatch();
    $app->stop();
});
// Format errors for CLI
$app->error(function (\Exception $e) use($app) {
    echo $e;
    echo PHP_EOL;