Passed
Push — main ( 422f08...35cd69 )
by Fabian
08:22 queued 02:49
created

LastModifiedStrategy::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3.0052

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 19
ccs 11
cts 12
cp 0.9167
rs 9.8666
c 0
b 0
f 0
cc 3
nc 3
nop 2
crap 3.0052
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 1
    public function process(AssetInterface $asset, AssetFactory $factory): ?AssetInterface
15
    {
16 1
        $path = $asset->getTargetPath();
17 1
        if (null === $path) {
18
            return null;
19
        }
20
21 1
        $ext = pathinfo($path, PATHINFO_EXTENSION);
22
23 1
        $lastModified = $factory->getLastModified($asset);
24 1
        if (null !== $lastModified) {
25 1
            $path = substr_replace(
26
                $path,
27 1
                "$lastModified.$ext",
28 1
                -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 1
            $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 1
        return null;
33
    }
34
35
}
36