Passed
Push — master ( 488e2d...680fd5 )
by Jean-Christophe
05:46
created

ClassToYumlRelationsTrait::_getYumlOneToMany()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 2
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Ubiquity\utils\yuml\traits;
4
5
use Ubiquity\orm\OrmUtils;
6
use Ubiquity\utils\yuml\ClassToYuml;
7
use Ubiquity\utils\yuml\Yuml;
8
9
/**
10
 * Ubiquity\utils\yuml\traits$ClassToYumlRelationsTrait
11
 * This class is part of Ubiquity
12
 *
13
 * @author jcheron <[email protected]>
14
 * @version 1.0.3
15
 *
16
 */
17
trait ClassToYumlRelationsTrait {
18
	protected $oneToManys = [ ];
19
	protected $manyToOne = [ ];
20
	protected $manyToManys = [ ];
21
	protected $extManyToManys = [ ];
22
23 2
	protected function loadOneToManys() {
24 2
		$oneToManys = OrmUtils::getAnnotationInfo ( $this->class, "#oneToMany" );
25 2
		if ($oneToManys) {
26 2
			foreach ( $oneToManys as $member => $array ) {
27 2
				$this->oneToManys [$member] = $array ["className"];
28
			}
29
		}
30 2
	}
31
32 2
	public function loadManyToManys() {
33 2
		$manyToManys = OrmUtils::getAnnotationInfo ( $this->class, "#manyToMany" );
34 2
		if ($manyToManys) {
35 2
			foreach ( $manyToManys as $member => $array ) {
36 2
				if (isset ( $array ["targetEntity"] )) {
37 2
					$this->manyToManys [$member] = $array ["targetEntity"];
38 2
					$this->extManyToManys [$array ["targetEntity"]] = $this->class;
39
				}
40
			}
41
		}
42 2
	}
43
44
	protected function loadManyToOne() {
45
		$manyToOne = OrmUtils::getAnnotationInfo ( $this->class, "#manyToOne" );
46
		if ($manyToOne) {
47
			foreach ( $manyToOne as $member ) {
48
				$joinColumn = OrmUtils::getAnnotationInfoMember ( $this->class, "#joinColumn", $member );
49
				if ($joinColumn && isset ( $joinColumn ["className"] )) {
50
					$this->manyToOne [$member] = $joinColumn ["className"];
51
				}
52
			}
53
		}
54
	}
55
56 2
	protected function _getYumlRelationsType($relations, $branche) {
57 2
		$myClass = $this->getShortClassName ( $this->class );
0 ignored issues
show
Bug introduced by
It seems like getShortClassName() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

57
		/** @scrutinizer ignore-call */ 
58
  $myClass = $this->getShortClassName ( $this->class );
Loading history...
58 2
		$yumlRelations = [ ];
59 2
		foreach ( $relations as $model ) {
60 2
			$yumlRelations [] = Yuml::setClassContent ( $myClass ) . $branche . new ClassToYuml ( $model, $this->displayAssociationClassProperties, false );
61
		}
62 2
		return $yumlRelations;
63
	}
64
65
	protected function _getYumlManyToOne() {
66
		return $this->_getYumlRelationsType ( $this->manyToOne, "0..*-1" );
67
	}
68
69 2
	protected function _getYumlOneToMany() {
70 2
		return $this->_getYumlRelationsType ( $this->oneToManys, "1-0..*" );
71
	}
72
73 2
	protected function _getYumlManyToMany() {
74 2
		return $this->_getYumlRelationsType ( $this->manyToManys, "0..*-0..*" );
75
	}
76
77
	/**
78
	 *
79
	 * @return array
80
	 */
81 2
	public function getExtManyToManys() {
82 2
		return $this->extManyToManys;
83
	}
84
85 2
	public function removeManyToManyExt($targetClass) {
86 2
		$member = array_search ( $targetClass, $this->manyToManys );
87 2
		if ($member !== false) {
88 2
			unset ( $this->manyToManys [$member] );
89
		}
90 2
	}
91
}
92
93