for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Rj\FrontendBundle\Package;
class FallbackPackage
{
private $patterns;
private $package;
private $fallback;
public function __construct($patterns, $package)
$this->patterns = $patterns;
$this->package = $package;
}
public function setFallback($fallback)
$this->fallback = $fallback;
return $this;
public function getVersion($path)
if ($this->mustFallback($path)) {
return $this->fallback->getVersion($path);
return $this->package->getVersion($path);
public function getUrl($path, $version = null)
return $this->fallback->getUrl($path, $version);
return $this->package->getUrl($path);
protected function mustFallback($path)
foreach ($this->patterns as $pattern) {
if (1 === preg_match("/$pattern/", $path)) {
sprintf
$pattern
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.
// Instead of $x = "foo $bar $baz"; // Better use either $x = "foo " . $bar . " " . $baz; $x = sprintf("foo %s %s", $bar, $baz);
return true;
return false;
It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.