@@ -11,16 +11,16 @@ class Arguments
1111 /** @var array */
1212 private $ arguments ;
1313
14- /** @var Collection */
14+ /** @var array */
1515 private $ flags ;
1616
17- /** @var Collection */
17+ /** @var array */
1818 private $ lists ;
1919
2020 /** @var Parser */
2121 private $ parser ;
2222
23- /** @var Collection */
23+ /** @var array */
2424 private $ values ;
2525
2626 /**
@@ -34,7 +34,7 @@ public function __construct($argv = null, $removeFirstArgument = true)
3434 if (is_array ($ argv )) {
3535 $ this ->parseArguments ($ argv , $ removeFirstArgument );
3636 } else {
37- $ this ->bindValuesFromGenerator ( );
37+ $ this ->setArgumentsFromParser ( $ this -> parser );
3838 }
3939 }
4040
@@ -47,68 +47,70 @@ public function getArguments()
4747 }
4848
4949 /**
50- * @param bool $convertCollectionToArray
51- * @return array|Collection
50+ * @return array
5251 */
53- public function getFlags ($ convertCollectionToArray = true )
52+ public function getFlags ()
5453 {
55- return (
56- $ this ->convertCollectionToArrayIfNeeded (
57- $ this ->flags ,
58- $ convertCollectionToArray
59- )
60- );
54+ return $ this ->flags ;
6155 }
6256
6357 /**
6458 * @param string $name
65- * @param bool $convertCollectionToArray
66- * @return null|Collection
59+ * @return null|array
6760 */
68- public function getList ($ name, $ convertCollectionToArray = true )
61+ public function getList ($ name )
6962 {
70- $ list = $ this ->lists ->offsetGet ($ name );
63+ return (isset ($ this ->lists [$ name ]))
64+ ? $ this ->lists [$ name ]
65+ : null ;
66+ }
7167
72- if ($ list instanceof Collection) {
73- $ return = (
74- $ this ->convertCollectionToArrayIfNeeded (
75- $ list ,
76- $ convertCollectionToArray
77- )
78- );
79- } else {
80- $ return = null ;
81- }
68+ /**
69+ * @return int
70+ */
71+ public function getNumberOfArguments ()
72+ {
73+ return (count ($ this ->arguments ));
74+ }
75+
76+ /**
77+ * @return int
78+ */
79+ public function getNumberOfFlags ()
80+ {
81+ return (count ($ this ->flags ));
82+ }
83+
84+ /**
85+ * @return int
86+ */
87+ public function getNumberOfLists ()
88+ {
89+ return (count ($ this ->lists ));
90+ }
8291
83- return $ return ;
92+ /**
93+ * @return int
94+ */
95+ public function getNumberOfValues ()
96+ {
97+ return (count ($ this ->values ));
8498 }
8599
86100 /**
87- * @param bool $convertCollectionToArray
88- * @return array|Collection
101+ * @return array
89102 */
90- public function getLists ($ convertCollectionToArray = true )
103+ public function getLists ()
91104 {
92- return (
93- $ this ->convertCollectionToArrayIfNeeded (
94- $ this ->lists ,
95- $ convertCollectionToArray
96- )
97- );
105+ return $ this ->lists ;
98106 }
99107
100108 /**
101- * @param bool $convertCollectionToArray
102- * @return array|Collection
109+ * @return array
103110 */
104- public function getValues ($ convertCollectionToArray = true )
111+ public function getValues ()
105112 {
106- return (
107- $ this ->convertCollectionToArrayIfNeeded (
108- $ this ->values ,
109- $ convertCollectionToArray
110- )
111- );
113+ return $ this ->values ;
112114 }
113115
114116 /**
@@ -125,15 +127,15 @@ public function hasArguments()
125127 */
126128 public function hasFlag ($ name )
127129 {
128- return $ this ->flags -> containsValue ( $ name );
130+ return ( in_array ( $ name , $ this ->flags ) );
129131 }
130132
131133 /**
132134 * @return bool
133135 */
134136 public function hasFlags ()
135137 {
136- return (!$ this ->flags -> isEmpty ( ));
138+ return (!empty ( $ this ->flags ));
137139 }
138140
139141 /**
@@ -142,23 +144,23 @@ public function hasFlags()
142144 */
143145 public function hasList ($ name )
144146 {
145- return $ this ->lists -> containsKey ( $ name );
147+ return ( isset ( $ this ->lists [ $ name]) );
146148 }
147149
148150 /**
149151 * @return bool
150152 */
151153 public function hasLists ()
152154 {
153- return (!$ this ->lists -> isEmpty ( ));
155+ return (!empty ( $ this ->lists ));
154156 }
155157
156158 /**
157159 * @return bool
158160 */
159161 public function hasValues ()
160162 {
161- return (!$ this ->values -> isEmpty ( ));
163+ return (!empty ( $ this ->values ));
162164 }
163165
164166 /**
@@ -173,8 +175,8 @@ public function parseArguments(array $argv, $removeFirstArgument = true)
173175 }
174176
175177 $ this ->arguments = $ argv ;
176- $ this ->parse ($ this ->arguments );
177- $ this ->bindValuesFromGenerator ( );
178+ $ this ->parser -> parse ($ this ->arguments );
179+ $ this ->setArgumentsFromParser ( $ this -> parser );
178180
179181 return $ this ;
180182 }
@@ -203,33 +205,13 @@ public function __toString()
203205 return $ this ->convertToString ();
204206 }
205207
206- private function parse (array $ arguments )
207- {
208- $ parser = $ this ->parser ;
209-
210- $ parser ->parse ($ arguments );
211- }
212-
213- private function bindValuesFromGenerator ()
208+ /**
209+ * @param Parser $parser
210+ */
211+ private function setArgumentsFromParser (Parser $ parser )
214212 {
215- $ parser = $ this ->parser ;
216-
217213 $ this ->flags = $ parser ->getFlags ();
218214 $ this ->lists = $ parser ->getLists ();
219215 $ this ->values = $ parser ->getValues ();
220216 }
221-
222- /**
223- * @param Collection $collection
224- * @param bool $isNeeded
225- * @return array|Collection
226- */
227- private function convertCollectionToArrayIfNeeded (Collection $ collection , $ isNeeded )
228- {
229- return (
230- $ isNeeded
231- ? $ collection ->convertToArray ()
232- : $ collection
233- );
234- }
235217}
0 commit comments