1. Go to this page and download the library: Download sjparkinson/static-review library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sjparkinson / static-review example snippets
#!/usr/bin/env php
include __DIR__ . '/../../../autoload.php';
// Reference the
$reporter = new Reporter();
$review = new StaticReview($reporter);
// Add any reviews to the StaticReview instance, supports a fluent interface.
$review->addReview(new LineEndingsReview());
$git = new GitVersionControl();
// Review the staged files.
$review->files($git->getStagedFiles());
// Check if any issues were found.
// Exit with a non-zero status to block the commit.
($reporter->hasIssues()) ? exit(1) : exit(0);
#!/usr/bin/env php
include __DIR__ . '/../../../autoload.php';
// Reference the ..]
$reporter = new Reporter();
$review = new StaticReview($reporter);
// Add any reviews to the StaticReview instance, supports a fluent interface.
$review->addReview(new BodyLineLengthReview());
$git = new GitVersionControl();
// Review the current commit message.
// The hook is passed the file holding the commit message as the first argument.
$review->message($git->getCommitMessage($argv[1]));
// Check if any issues were found.
// Exit with a non-zero status to block the commit.
($reporter->hasIssues()) ? exit(1) : exit(0);
class NoCommitTagReview extends AbstractFileReview
{
// Review any text based file.
public function canReviewFile(FileInterface $file)
{
$mime = $file->getMimeType();
// check to see if the mime-type starts with 'text'
return (substr($mime, 0, 4) === 'text');
}
// Checks if the file contains `NOCOMMIT`.
public function review(ReporterInterface $reporter, ReviewableInterface $file)
{
$cmd = sprintf('grep --fixed-strings --ignore-case --quiet "NOCOMMIT" %s', $file->getFullPath());
$process = $this->getProcess($cmd);
$process->run();
if ($process->isSuccessful()) {
$message = 'A NOCOMMIT tag was found';
$reporter->error($message, $this, $file);
}
}
}
class WorkInProgressReview extends AbstractMessageReview
{
// Check if the commit message contains "wip"
public function review(ReporterInterface $reporter, ReviewableInterface $commit)
{
$fulltext = $commit->getSubject() . PHP_EOL . $commit->getBody();
if (preg_match('/\bwip\b/i', $fulltext)) {
$message = 'Do not commit WIP to shared branches';
$reporter->error($message, $this, $commit);
}
}
}