@@ -44,7 +44,6 @@ public function findClassByFQCN(FQCN $fqcn){
4444 if (array_key_exists ($ str , $ this ->classes )){
4545 return $ this ->classes [$ str ];
4646 }
47- return null ;
4847 }
4948
5049 /**
@@ -56,6 +55,10 @@ public function findInterfaceByFQCN(FQCN $fqcn){
5655 return $ this ->interfaces [$ str ];
5756 }
5857 }
58+
59+ /**
60+ * @return ClassData[]
61+ */
5962 public function findClassChildren (FQCN $ class ){
6063 if (!array_key_exists ($ class ->toString (), $ this ->extends )
6164 || !is_array ($ this ->extends [$ class ->toString ()])
@@ -64,24 +67,53 @@ public function findClassChildren(FQCN $class){
6467 }
6568 return $ this ->extends [$ class ->toString ()];
6669 }
70+
71+ /**
72+ * @return ClassData[]
73+ */
74+ public function findInterfaceChildrenClasses (FQCN $ interface ){
75+ if (!array_key_exists ($ interface ->toString (), $ this ->implements )
76+ || !is_array ($ this ->implements [$ interface ->toString ()])
77+ ){
78+ $ this ->implements [$ interface ->toString ()] = [];
79+ }
80+ return $ this ->implements [$ interface ->toString ()];
81+ }
82+
83+ /**
84+ * @return ClassData[]
85+ */
6786 public function getClasses (){
6887 return $ this ->classes ;
6988 }
89+
90+ /**
91+ * @return InterfaceData[]
92+ */
93+ public function getInterfaces (){
94+ return $ this ->interfaces ;
95+ }
96+
7097 public function addClass (ClassData $ class ){
7198 $ this ->classes [$ class ->fqcn ->toString ()] = $ class ;
7299 if (!empty ($ class ->getParent ())){
73100 $ this ->addExtend ($ class , $ class ->getParent ());
74101 }
102+ foreach ($ class ->getInterfaces () as $ interface ){
103+ $ this ->addImplement ($ class , $ interface );
104+ }
75105 foreach ($ this ->findClassChildren ($ class ->fqcn ) AS $ child ){
76106 $ child ->setParent ($ class );
77107 }
78108 }
109+
79110 public function addInterface (InterfaceData $ interface ){
80111 $ this ->interfaces [$ interface ->fqcn ->toString ()] = $ interface ;
112+ foreach ($ this ->findInterfaceChildrenClasses ($ interface ->fqcn ) as $ child ){
113+ $ child ->addInterface ($ interface );
114+ }
81115 }
82- public function getInterfaces (){
83- return $ this ->interfaces ;
84- }
116+
85117 public function addFQCN (FQCN $ fqcn ){
86118 $ this ->fqcns [$ fqcn ->toString ()] = $ fqcn ;
87119 }
@@ -112,13 +144,15 @@ protected function addExtend(ClassData $class, FQCN $parent){
112144 }
113145 }
114146
115- protected function addImplement ($ class , $ interface ){
116- if (!array_key_exists ($ interface , $ this ->implements )
117- || !is_array ($ this ->implements [$ interface ])){
118- $ this ->implements [$ interface ] = [];
147+ protected function addImplement (ClassData $ class , FQCN $ interface ){
148+ if (!array_key_exists ($ interface-> toString () , $ this ->implements )
149+ || !is_array ($ this ->implements [$ interface-> toString () ])){
150+ $ this ->implements [$ interface-> toString () ] = [];
119151 }
120- if (!in_array ($ class , $ this ->implements [$ interface ])){
121- $ this ->implements [$ interface ][] = $ class ;
152+ $ this ->implements [$ interface ->toString ()][$ class ->fqcn ->toString ()] = $ class ;
153+ $ interface = $ this ->findInterfaceByFQCN ($ interface );
154+ if ($ interface instanceof InterfaceData){
155+ $ class ->addInterface ($ interface );
122156 }
123157 }
124158
0 commit comments