WebLibraryManagerValidator   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 40
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B validateClass() 0 31 6
1
<?php
2
namespace Mouf\Html\Utils\WebLibraryManager;
3
4
use Mouf\Validator\MoufStaticValidatorInterface;
5
use Mouf\Composer\ComposerService;
6
use Mouf\Validator\MoufValidatorResult;
7
use Mouf\MoufManager;
8
9
/**
10
 * This validator is in charge of checking that "component" packages have matching weblibraries
11
 * declared in Mouf.
12
 * 
13
 * @author David Négrier
14
 */
15
class WebLibraryManagerValidator implements MoufStaticValidatorInterface {
16
	
17
	/**
18
	 * Runs the validation of the class.
19
	 * Returns a MoufValidatorResult explaining the result.
20
	 *
21
	 * @return MoufValidatorResult
22
	 */
23
	static function validateClass() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
24
		$composerService = new ComposerService();
25
		$packages = $composerService->getLocalPackagesOrderedByDependencies();
26
		
27
		$componentViolations = array();
28
		$moufManager = MoufManager::getMoufManager();
29
		
30
		foreach ($packages as $package) {
31
			/* @var $package PackageInterface */
32
			if ($package->getType() == "component") {
33
				$extra = $package->getExtra();
34
				 
35
				if (isset($extra['component']['name'])) {
36
					$packageName = $extra['component']['name'];
37
				} else {
38
					$packageName = explode('/', $package->getName())[1];
39
				}
40
	
41
				if (!$moufManager->has("component.".$packageName)) {
42
					$componentViolations[] = $packageName;
43
				}
44
			}
45
		}
46
47
		if (!$componentViolations) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $componentViolations of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
48
			return new MoufValidatorResult(MoufValidatorResult::SUCCESS, "<b>WebLibraryManager: </b>No missing WebLibrary for Bower or Components packages.");
49
		} else {
50
			return new MoufValidatorResult(MoufValidatorResult::ERROR, "<b>WebLibraryManager: </b>Missing matching WebLibrary for package(s) ".implode(', ', $componentViolations).
51
				"<div><a href='".MOUF_URL."assetsIntegration/fixAll' class='btn btn-success'>Click here to create all web-libraries matching these packages</a></div>");
52
		}
53
	}
54
}
55