File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -91,6 +91,20 @@ public function getNamespaces(): array
91
91
}
92
92
93
93
94
+ /** @return ClassType[] */
95
+ public function getClasses (): array
96
+ {
97
+ $ classes = [];
98
+ foreach ($ this ->namespaces as $ n => $ namespace ) {
99
+ $ n .= $ n ? '\\' : '' ;
100
+ foreach ($ namespace ->getClasses () as $ c => $ class ) {
101
+ $ classes [$ n . $ c ] = $ class ;
102
+ }
103
+ }
104
+ return $ classes ;
105
+ }
106
+
107
+
94
108
/** @return static */
95
109
public function addUse (string $ name , string $ alias = null ): self
96
110
{
Original file line number Diff line number Diff line change @@ -79,13 +79,40 @@ $file->addClass('FooBar\I');
79
79
80
80
sameFile (__DIR__ . '/expected/PhpFile.bracketed.expect ' , (string ) $ file );
81
81
82
+ Assert::same ([
83
+ 'Foo ' ,
84
+ 'Bar ' ,
85
+ 'Baz ' ,
86
+ '' ,
87
+ 'FooBar ' ,
88
+ ], array_keys ($ file ->getNamespaces ()));
89
+
90
+ Assert::same ([
91
+ 'Foo\A ' ,
92
+ 'Foo\B ' ,
93
+ 'Foo\C ' ,
94
+ 'Bar\B ' ,
95
+ 'Bar\C ' ,
96
+ 'Bar\D ' ,
97
+ 'Bar\EN ' ,
98
+ 'Baz\E ' ,
99
+ 'Baz\F ' ,
100
+ 'Baz\G ' ,
101
+ 'H ' ,
102
+ 'FooBar\I ' ,
103
+ ], array_keys ($ file ->getClasses ()));
104
+
105
+
106
+
82
107
$ file = new PhpFile ;
83
108
$ file ->addClass ('A ' );
84
109
$ file ->addUse ('A ' )
85
110
->addUse ('B ' , 'C ' );
86
111
87
112
sameFile (__DIR__ . '/expected/PhpFile.globalNamespace.expect ' , (string ) $ file );
88
113
114
+
115
+
89
116
$ file = new PhpFile ;
90
117
$ file ->addComment ('This file is auto-generated. DO NOT EDIT! ' );
91
118
$ file ->setStrictTypes ();
You can’t perform that action at this time.
0 commit comments