VersionDefinitionFacade   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 21
c 1
b 0
f 0
dl 0
loc 62
ccs 22
cts 22
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createVersionStatement() 0 24 3
A __construct() 0 3 1
A getVersionDependencyReference() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SixtyEightPublishers\Asset\DI;
6
7
use Nette;
8
use Symfony;
9
10
final class VersionDefinitionFacade
11
{
12
	use Nette\SmartObject;
13
14
	/** @var \SixtyEightPublishers\Asset\DI\ReferenceFacade  */
15
	private $referenceFacade;
16
17
	/**
18
	 * @param \SixtyEightPublishers\Asset\DI\ReferenceFacade $referenceFacade
19
	 */
20 1
	public function __construct(ReferenceFacade $referenceFacade)
21
	{
22 1
		$this->referenceFacade = $referenceFacade;
23 1
	}
24
25
	/**
26
	 * @param string      $name
27
	 * @param string|NULL $version
28
	 * @param string      $format
29
	 * @param string|NULL $jsonManifestPath
30
	 *
31
	 * @return \Nette\DI\Statement
32
	 */
33 1
	public function createVersionStatement(string $name, ?string $version, string $format, ?string $jsonManifestPath): Nette\DI\Statement
34
	{
35
		// Configuration prevents $version and $jsonManifestPath from being set
36 1
		if (NULL !== $version) {
37 1
			$reference = $this->getVersionDependencyReference(
38 1
				new Nette\DI\Statement(Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy::class, [
0 ignored issues
show
Deprecated Code introduced by
The class Nette\DI\Statement has been deprecated: use Nette\DI\Definitions\Statement ( Ignorable by Annotation )

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

38
				/** @scrutinizer ignore-deprecated */ new Nette\DI\Statement(Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy::class, [
Loading history...
Unused Code introduced by
The call to Nette\DI\Statement::__construct() has too many arguments starting with Symfony\Component\Asset\...cVersionStrategy::class. ( Ignorable by Annotation )

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

38
				/** @scrutinizer ignore-call */ 
39
    new Nette\DI\Statement(Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy::class, [

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
39 1
					'version' => $version,
40 1
					'format' => $format,
41
				]),
42 1
				$name
43
			);
44
		}
45
46 1
		if (NULL !== $jsonManifestPath) {
47 1
			$reference = $this->getVersionDependencyReference(
48 1
				new Nette\DI\Statement(Symfony\Component\Asset\VersionStrategy\JsonManifestVersionStrategy::class, [
0 ignored issues
show
Deprecated Code introduced by
The class Nette\DI\Statement has been deprecated: use Nette\DI\Definitions\Statement ( Ignorable by Annotation )

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

48
				/** @scrutinizer ignore-deprecated */ new Nette\DI\Statement(Symfony\Component\Asset\VersionStrategy\JsonManifestVersionStrategy::class, [
Loading history...
49 1
					'manifestPath' => $jsonManifestPath,
50
				]),
51 1
				$name
52
			);
53
		}
54
55 1
		return new Nette\DI\Statement(
0 ignored issues
show
Deprecated Code introduced by
The class Nette\DI\Statement has been deprecated: use Nette\DI\Definitions\Statement ( Ignorable by Annotation )

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

55
		return /** @scrutinizer ignore-deprecated */ new Nette\DI\Statement(
Loading history...
56 1
			$reference ?? $this->getVersionDependencyReference(Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy::class, $name)
57
		);
58
	}
59
60
	/**
61
	 * @param string|\Nette\DI\Statement $definition
62
	 * @param string                     $versionName
63
	 *
64
	 * @return string
65
	 */
66 1
	public function getVersionDependencyReference($definition, string $versionName): string
67
	{
68 1
		return $this->referenceFacade->getDependencyReference(
69 1
			$definition,
70 1
			'version_strategy.' . $versionName,
71 1
			Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface::class
72
		);
73
	}
74
}
75