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\HttpKernel\KernelInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
class AssetExtension extends \Twig_Extension
{
private $kernel;
public function __construct(KernelInterface $kernel)
$this->kernel = $kernel;
}
public function getFunctions()
return [new \Twig_SimpleFunction('asset_exists', [$this, 'assetExists'], ['is_safe' => ['html']])];
public function assetExists($path)
$publicRoot = realpath($this->kernel->getRootDir() . '/../public/') . DIRECTORY_SEPARATOR;
$toCheck = realpath($publicRoot . $path);
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.
// check if the file exists
if (!is_file($toCheck)) {
return false;
// check if file is well contained in web/ directory (prevents ../ in paths)
if (strncmp($publicRoot, $toCheck, strlen($publicRoot)) !== 0) {
return true;
public function getName()
return 'asset_exists';
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.