Passed
Push — master ( d1c5a6...bac8bf )
by Fabian
03:36 queued 12s
created

LastModifiedStrategy::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 19
rs 9.8666
c 0
b 0
f 0
cc 3
nc 3
nop 2
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
class LastModifiedStrategy implements WorkerInterface
12
{
13
14
    public function process(AssetInterface $asset, AssetFactory $factory): ?AssetInterface
15
    {
16
        $path = $asset->getTargetPath();
17
        if (null === $path) {
18
            return null;
19
        }
20
21
        $ext = pathinfo($path, PATHINFO_EXTENSION);
22
23
        $lastModified = $factory->getLastModified($asset);
24
        if (null !== $lastModified) {
25
            $path = substr_replace(
26
                $path,
27
                "$lastModified.$ext",
28
                -1 * strlen($ext)
0 ignored issues
show
Bug introduced by
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

28
                -1 * strlen(/** @scrutinizer ignore-type */ $ext)
Loading history...
29
            );
30
            $asset->setTargetPath($path);
0 ignored issues
show
Bug introduced by
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

30
            $asset->setTargetPath(/** @scrutinizer ignore-type */ $path);
Loading history...
31
        }
32
        return null;
33
    }
34
35
}
36