PackageDefinitionFacade   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 95.65%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
eloc 23
c 2
b 0
f 0
dl 0
loc 62
ccs 22
cts 23
cp 0.9565
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getPackageDependencyReference() 0 6 1
A createPackageStatement() 0 25 4
A __construct() 0 3 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 PackageDefinitionFacade
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|\Nette\DI\Statement $basePath
28
	 * @param array                           $baseUrls
29
	 * @param \Nette\DI\Statement             $versionStrategy
30
	 *
31
	 * @return \Nette\DI\Statement
32
	 */
33 1
	public function createPackageStatement(string $name, $basePath, array $baseUrls, Nette\DI\Statement $versionStrategy): Nette\DI\Statement
34
	{
35 1
		if (!empty($basePath) && !empty($baseUrls)) {
36
			throw new \LogicException('An asset package cannot have base URLs and base paths.');
37
		}
38
39 1
		if (empty($baseUrls)) {
40 1
			$reference = $this->getPackageDependencyReference(
41 1
				new Nette\DI\Statement(Symfony\Component\Asset\PathPackage::class, [
0 ignored issues
show
Unused Code introduced by
The call to Nette\DI\Statement::__construct() has too many arguments starting with Symfony\Component\Asset\PathPackage::class. ( Ignorable by Annotation )

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

41
				/** @scrutinizer ignore-call */ 
42
    new Nette\DI\Statement(Symfony\Component\Asset\PathPackage::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...
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

41
				/** @scrutinizer ignore-deprecated */ new Nette\DI\Statement(Symfony\Component\Asset\PathPackage::class, [
Loading history...
42 1
					'basePath' => $basePath ?? '',
43 1
					'versionStrategy' => $versionStrategy,
44
				]),
45 1
				$name
46
			);
47
		} else {
48 1
			$reference = $this->getPackageDependencyReference(
49 1
				new Nette\DI\Statement(Symfony\Component\Asset\UrlPackage::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

49
				/** @scrutinizer ignore-deprecated */ new Nette\DI\Statement(Symfony\Component\Asset\UrlPackage::class, [
Loading history...
50 1
					'baseUrls' => $baseUrls,
51 1
					'versionStrategy' => $versionStrategy,
52
				]),
53 1
				$name
54
			);
55
		}
56
57 1
		return new Nette\DI\Statement($reference);
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

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