for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Enjoys\AssetsCollector\Content;
use Psr\Http\Message\UriInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\NullLogger;
/**
* Class ReplaceRelativeUrls
* @package Enjoys\AssetsCollector\Content
*/
class ReplaceRelativeUrls
{
use LoggerAwareTrait;
private string $content;
private string $domain;
$domain
// private UriInterface $uri;
private string $url;
public function __construct(string $content, string $url)
$this->content = $content;
$this->logger = new NullLogger();
$this->url = $url;
}
* @return string
public function getContent(): string
$result = preg_replace_callback('/(url\([\'"]?)(?!["\'a-z]+:|[\'"]?\/{2})(.+[^\'"])([\'"]?\))/i', function ($m){
$urlConverter = new UrlConverter();
return $m[1] . $urlConverter->relativeToAbsolute($this->url, $m[2]) . $m[3];
$urlConverter->relativeT...lute($this->url, $m[2])
false
concatenation
If this is a false-positive, you can also ignore this issue in your code via the ignore-type annotation
ignore-type
return $m[1] . /** @scrutinizer ignore-type */ $urlConverter->relativeToAbsolute($this->url, $m[2]) . $m[3];
}, $this->content);
if ($result === null) {
$this->logger->notice(sprintf('Regex return null value. Returned empty string: %s', $this->url));
return '';
$this->logger->info(sprintf('ReplaceRelativeUrls: %s', $this->url));
return $result;