@@ -26,13 +26,13 @@ public function __call($method, $args)
2626
2727 /**
2828 * Set a container OR factory
29- * @param string $identifier Uniq identifier
30- * @param mixed $value Example:
31- * TestClasses\Test::class,
32- * TestClasses\Test::class."::__construct",
33- * TestClasses\Test::class."::getStaticMethod",
34- * @param array|null $args Pass argumnets to constructor staticMethod if you choose.
35- * @param bool|boolean $overwrite Will throw exception if already been defined if not arg is set to TRUE.
29+ * @param string $identifier Uniq identifier
30+ * @param mixed $value Example:
31+ * TestClasses\Test::class,
32+ * TestClasses\Test::class."::__construct",
33+ * TestClasses\Test::class."::getStaticMethod",
34+ * @param array|null $args Pass argumnets to constructor staticMethod if you choose.
35+ * @param bool|boolean $overwrite Will throw exception if already been defined if not arg is set to TRUE.
3636 */
3737 public function set (string $ identifier , $ value , ?array $ args = null , bool $ overwrite = false ): ContainerInterface
3838 {
@@ -55,9 +55,9 @@ public function set(string $identifier, $value, ?array $args = null, bool $overw
5555 * @param string $identifier Uniq identifier
5656 * @param callable $factory
5757 * @param bool|boolean $overwrite Will throw exception if already been defined if not arg is set to TRUE.
58- * @return void
58+ * @return self
5959 */
60- public function factory (string $ identifier , callable $ factory , bool $ overwrite = false ): ContainerInterface
60+ public function factory (string $ identifier , callable $ factory , bool $ overwrite = false ): self
6161 {
6262 if (!$ overwrite && $ this ->has ($ identifier )) {
6363 if (!$ this ->isFactory ($ identifier )) {
@@ -94,7 +94,7 @@ public function has(string $identifier): bool
9494 */
9595 public function isFactory (string $ identifier )
9696 {
97- return (bool )( $ this ->getService ($ identifier ) instanceof \Closure);
97+ return ($ this ->getService ($ identifier ) instanceof \Closure);
9898 }
9999
100100 /**
@@ -104,7 +104,7 @@ public function isFactory(string $identifier)
104104 */
105105 public function isContainer ($ identifier )
106106 {
107- return (bool )( !$ this ->isFactory ($ identifier ));
107+ return (!$ this ->isFactory ($ identifier ));
108108 }
109109
110110 /**
@@ -113,21 +113,20 @@ public function isContainer($identifier)
113113 * @param array $args Is possible to overwrite/add __construct or method argumnets
114114 * @return mixed
115115 */
116- public function get (string $ identifier , array $ args = [])
116+ public function get (string $ identifier , array $ args = []): mixed
117117 {
118118 if ($ service = $ this ->getService ($ identifier )) {
119- if (is_null ($ args )) {
119+ if (count ($ args ) === 0 ) {
120120 $ args = $ this ->getArgs ($ identifier );
121121 }
122-
123- if (($ service instanceof \Closure)) {
122+ if ($ this ->isFactory ($ identifier )) {
124123 $ this ->getter [$ identifier ] = $ service (...$ args );
125124 } else {
126125 if (empty ($ this ->getter [$ identifier ])) {
126+ /** @var string $service */
127127 if (is_string ($ service )) {
128- /** @var string $service */
129128 $ reflect = new Reflection ($ service );
130- if (! is_null ($ args )) {
129+ if (count ($ args ) > 0 ) {
131130 $ reflect ->setArgs ($ args );
132131 }
133132 $ this ->getter [$ identifier ] = $ reflect ->get ();
@@ -179,10 +178,10 @@ private function getService(string $identifier)
179178 /**
180179 * Get arguments
181180 * @param string $identifier
182- * @return array|null
181+ * @return array
183182 */
184- private function getArgs (string $ identifier )
183+ private function getArgs (string $ identifier ): array
185184 {
186- return ($ this ->args [$ identifier ] ?? null );
185+ return ($ this ->args [$ identifier ] ?? [] );
187186 }
188187}
0 commit comments