@@ -89,11 +89,11 @@ public static function unitFromSuffix(string $unitSuffix, string $unitName): Uni
8989 /**
9090 * List all supported units
9191 *
92- * @param null|string $unitPrefix
9392 * @param string[] $unitTypes
94- * @return array|\string[]
93+ * @param null|string $unitPrefix
94+ * @return array
9595 */
96- public function listUnits (? string $ unitPrefix = null , array $ unitTypes = self :: SUPPORTED_UNITS ): array
96+ public function listUnits (array $ unitTypes , ? string $ unitPrefix = null ): array
9797 {
9898 $ processBuilder = $ this ->getProcessBuilder ()
9999 ->add ('list-units ' );
@@ -113,6 +113,15 @@ public function listUnits(?string $unitPrefix = null, array $unitTypes = self::S
113113 }, []);
114114 }
115115
116+ /**
117+ * Invoke getUnit or getUnits depending on the requested method.
118+ * The method name needs to contain the unit type u want to call.
119+ *
120+ * @param $name
121+ * @param $arguments
122+ * @return array|AbstractUnit
123+ * @throws UnitTypeNotSupportedException
124+ */
116125 public function __call ($ name , $ arguments )
117126 {
118127 preg_match ('/get(?<unit>[^s]+)(?<plural>s)?/ ' , $ name , $ match );
@@ -121,7 +130,7 @@ public function __call($name, $arguments)
121130 $ unitName = strtolower ($ match ['unit ' ]);
122131
123132 if (!in_array ($ unitName , self ::SUPPORTED_UNITS )) {
124- throw new UnitTypeNotSupportedException ("Unit {$ unitName } not supported " );
133+ throw new UnitTypeNotSupportedException ("Unit ' {$ unitName }'' not supported " );
125134 }
126135
127136 if ($ isPlural ) {
@@ -152,7 +161,7 @@ private function getUnit(string $unitClass, $args): AbstractUnit
152161 private function getUnits (string $ unitName , $ arguments ): array
153162 {
154163 $ unitPrefix = $ arguments [0 ] ?? null ;
155- $ units = $ this ->listUnits ($ unitPrefix , [strtolower ($ unitName )]);
164+ $ units = $ this ->listUnits ([strtolower ($ unitName )], $ unitPrefix );
156165 $ unitClass = '\SystemCtl\Unit \\' . $ unitName ;
157166
158167 return array_map (function ($ unitName ) use ($ unitClass ) {
0 commit comments