for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Cdf\BiCoreBundle\Twig\Extension;
class AssetExtension extends \Twig\Extension\AbstractExtension
{
private $projectpath;
public function __construct($projectpath)
$this->projectpath = $projectpath;
}
public function getFunctions()
return [new \Twig_SimpleFunction('asset_exists', [$this, 'assetExists'], ['is_safe' => ['html']])];
Twig_SimpleFunction
If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated annotation
ignore-deprecated
return [/** @scrutinizer ignore-deprecated */ new \Twig_SimpleFunction('asset_exists', [$this, 'assetExists'], ['is_safe' => ['html']])];
public function assetExists($path)
$publicRoot = realpath($this->projectpath.'/public/').DIRECTORY_SEPARATOR;
$toCheck = $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 (0 !== strncmp($publicRoot, $toCheck, strlen($publicRoot))) {
return true;