for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Cdf\BiCoreBundle\Twig\Extension;
use Symfony\Component\Process\Process;
use Symfony\Component\Cache\Simple\FilesystemCache;
class VersioneExtension extends \Twig_Extension
{
private $projectpath;
public function __construct($projectpath)
$this->projectpath = $projectpath;
}
public function getFunctions()
return array(
new \Twig_SimpleFunction('versione_tag_git', array($this, 'versioneTagGit', 'is_safe' => array('html'))),
);
public function versioneTagGit()
if ($this->isWindows()) {
return 0;
$cache = new FilesystemCache();
if ($cache->has('git_tag')) {
$version = $cache->get('git_tag');
} else {
$projectDir = $this->projectpath;
$process = new Process(array('git', 'describe', '--tags'));
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
$a = "a"; $ab = "ab"; $abc = "abc";
will produce issues in the first and second line, while this second example
will produce no issues.
$process->setWorkingDirectory($projectDir);
$process->setTimeout(60 * 100);
$process->run();
if ($process->isSuccessful()) {
$out = explode(chr(10), $process->getOutput());
$version = isset($out[0]) ? $out[0] : '0';
$cache->set('git_tag', $version);
$version = '0';
return $version;
private function isWindows()
if (PHP_OS == 'WINNT') {
return true;
return false;
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.