Issues (6)

src/CacheBuster/LastModifiedStrategy.php (2 issues)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Fabiang\AsseticBundle\CacheBuster;
6
7
use Assetic\Contracts\Asset\AssetInterface;
8
use Assetic\Contracts\Factory\Worker\WorkerInterface;
9
use Assetic\Factory\AssetFactory;
10
11
use function pathinfo;
12
use function strlen;
13
use function substr_replace;
14 1
15
use const PATHINFO_EXTENSION;
16 1
17 1
class LastModifiedStrategy implements WorkerInterface
18
{
19
    public function process(AssetInterface $asset, AssetFactory $factory): ?AssetInterface
20
    {
21 1
        $path = $asset->getTargetPath();
22
        if (null === $path) {
23 1
            return null;
24 1
        }
25 1
26
        $ext = pathinfo($path, PATHINFO_EXTENSION);
27 1
28 1
        $lastModified = $factory->getLastModified($asset);
29
        if (null !== $lastModified) {
30 1
            $path = substr_replace(
31
                $path,
32 1
                "$lastModified.$ext",
33
                -1 * strlen($ext)
0 ignored issues
show
It seems like $ext can also be of type array; however, parameter $string of strlen() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

33
                -1 * strlen(/** @scrutinizer ignore-type */ $ext)
Loading history...
34
            );
35
            $asset->setTargetPath($path);
0 ignored issues
show
It seems like $path can also be of type array; however, parameter $targetPath of Assetic\Contracts\Asset\...erface::setTargetPath() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

35
            $asset->setTargetPath(/** @scrutinizer ignore-type */ $path);
Loading history...
36
        }
37
        return null;
38
    }
39
}
40