Passed
Push — master ( cea48f...3c52fb )
by Jean-Christophe
05:56
created

ClassesToYuml::parse()   B

Complexity

Conditions 8
Paths 3

Size

Total Lines 30
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 23
CRAP Score 8

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 30
ccs 23
cts 23
cp 1
rs 8.4444
c 0
b 0
f 0
cc 8
nc 3
nop 0
crap 8
1
<?php
2
3
namespace Ubiquity\utils\yuml;
4
5
use Ubiquity\cache\CacheManager;
6
use Ubiquity\controllers\Startup;
7
use Ubiquity\cache\ClassUtils;
8
use Ubiquity\utils\base\UString;
9
10
class ClassesToYuml {
11
	private $displayProperties;
12
	private $displayAssociations;
13
	private $displayMethods;
14
	private $displayMethodsParams;
15
	private $displayPropertiesTypes;
16
	private $manyToManys;
17
18 2
	public function __construct($displayProperties = true, $displayAssociations = true, $displayMethods = false, $displayMethodsParams = false, $displayPropertiesTypes = false) {
19 2
		$this->displayProperties = $displayProperties;
20 2
		$this->displayAssociations = $displayAssociations;
21 2
		$this->displayMethods = $displayMethods;
22 2
		$this->displayMethodsParams = $displayMethodsParams;
23 2
		$this->displayPropertiesTypes = $displayPropertiesTypes;
24 2
		$this->manyToManys = [ ];
25 2
	}
26
27
	/**
28
	 *
29
	 * @return ClassToYuml[]|string[]
30
	 */
31 2
	public function parse() {
32 2
		$yumlResult = [ ];
33 2
		$config = Startup::getConfig ();
34 2
		$files = CacheManager::getModelsFiles ( $config, true );
35 2
		if (\sizeof ( $files ) !== 0) {
36 2
			foreach ( $files as $file ) {
37 2
				$completeName = ClassUtils::getClassFullNameFromFile ( $file );
38 2
				$yumlR = new ClassToYuml ( $completeName, $this->displayProperties, false, $this->displayMethods, $this->displayMethodsParams, $this->displayPropertiesTypes, false );
39 2
				$yumlR->loadManyToManys();
40 2
				$yumlResult [] = $yumlR;
41
			}
42 2
			if ($this->displayAssociations) {
43 2
				$count = \sizeof ( $files );
44 2
				for($i = 0; $i < $count; $i ++) {
45 2
					$this->checkManyToManys ( $yumlResult [$i]->getExtManyToManys (), $yumlResult [$i] );
46
				}
47 2
				for($i = 0; $i < $count; $i ++) {
48 2
					$result = $yumlResult [$i]->oneToManyTostring ();
49 2
					if (UString::isNotNull ( $result )) {
50 2
						$yumlResult [] = $result;
51
					}
52 2
					$result = $yumlResult [$i]->manyToManyTostring (false);
53 2
					if (UString::isNotNull ( $result )) {
54 2
						$yumlResult [] = $result;
55
					}
56
				}
57
			}
58
		}
59 2
		$this->manyToManys=[];
60 2
		return $yumlResult;
61
	}
62
63 2
	private function checkManyToManys($manyToManys, ClassToYuml $classToYuml) {
64 2
		foreach ( $manyToManys as $targetClass => $class ) {
65 2
			if (array_search ( md5 ( $class . '_' . $targetClass ), $this->manyToManys ) !== false || array_search ( md5 ( $targetClass . '_' . $class ), $this->manyToManys ) !== false) {
66 2
				$classToYuml->removeManyToManyExt ( $targetClass );
67
			} else {
68 2
				$this->manyToManys [] = md5 ( $class . '_' . $targetClass );
69
			}
70
		}
71 2
	}
72
73 2
	public function __toString() {
74 2
		return \implode ( Yuml::$groupeSeparator, $this->parse () );
75
	}
76
}
77