Skip to content

Commit 2182fcd

Browse files
author
Wazabii
committed
Types
1 parent 7705623 commit 2182fcd

8 files changed

Lines changed: 27 additions & 173 deletions

File tree

Container.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ public function get(string $identifier, array $args = [])
125125
} else {
126126
if (empty($this->getter[$identifier])) {
127127
if (is_string($service)) {
128+
/** @var string $service */
128129
$reflect = new Reflection($service);
129130
if (!is_null($args)) {
130131
$reflect->setArgs($args);
@@ -135,8 +136,6 @@ public function get(string $identifier, array $args = [])
135136
}
136137
}
137138
}
138-
139-
140139
return $this->getter[$identifier];
141140
} else {
142141
throw new NotFoundException("Tring to get a container ({$identifier}) that does not exists", 1);
@@ -158,7 +157,7 @@ public function fetch(string $identifier)
158157
$arr = Arr::value($this->services)->wildcardSearch($identifier)->get();
159158
if (count($arr) > 0) {
160159
$new = array();
161-
foreach ($arr as $key => $unusedValues) {
160+
foreach ($arr as $key => $_unusedValues) {
162161
$new[$key] = $this->get($key);
163162
}
164163
return $new;

Interfaces/ContainerInterface.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,25 @@ interface ContainerInterface
1212
/**
1313
* Finds an entry of the container by its identifier and returns it.
1414
*
15-
* @param string $id Identifier of the entry to look for.
15+
* @param string $identifier Identifier of the entry to look for.
1616
*
1717
* @throws NotFoundExceptionInterface No entry was found for **this** identifier.
1818
* @throws ContainerExceptionInterface Error while retrieving the entry.
1919
*
2020
* @return mixed Entry.
2121
*/
22-
public function get(string $id);
22+
public function get(string $identifier);
2323

2424
/**
2525
* Returns true if the container can return an entry for the given identifier.
2626
* Returns false otherwise.
2727
*
28-
* `has($id)` returning true does not mean that `get($id)` will not throw an exception.
29-
* It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface`.
28+
* `has($identifier)` returning true does not mean that `get($identifier)` will not throw an exception.
29+
* It does however mean that `get($identifier)` will not throw a `NotFoundExceptionInterface`.
3030
*
31-
* @param string $id Identifier of the entry to look for.
31+
* @param string $identifier Identifier of the entry to look for.
3232
*
3333
* @return bool
3434
*/
35-
public function has(string $id): bool;
35+
public function has(string $identifier): bool;
3636
}

Interfaces/FactoryInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ interface FactoryInterface
1212
/**
1313
* Add a single factory.
1414
*
15-
* @param string $id The id
15+
* @param string $identifier The id
1616
* @param callable $factory The callable
1717
* @param bool $factory The callable
1818
* @param bool|boolean $overwrite Will throw exception if already been defined if not arg is set to TRUE.
1919
* @return void
2020
*/
21-
public function factory(string $id, callable $factory, bool $overwrite = false): ContainerInterface;
21+
public function factory(string $identifier, callable $factory, bool $overwrite = false): ContainerInterface;
2222
}

Reflection.php

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ public function __construct($data)
3737
/**
3838
* If the dependency injector tries to read an interface in controller it
3939
* will search for the object in interfaceFactory.
40-
* @return controller
40+
* @param callable $call
41+
* @return void
4142
*/
42-
public static function interfaceFactory($call): void
43+
public static function interfaceFactory(callable $call): void
4344
{
4445
self::$interfaceFactory[] = function ($short, $class, $reflect) use ($call) {
4546
//self::$interfaceProtocol[$short] = $call($class, $short, $reflect);
@@ -59,9 +60,9 @@ public function allowInterfaces(bool $bool): void
5960

6061
/**
6162
* Call dependency injector
62-
* @return controller
63+
* @return object
6364
*/
64-
public function dependencyInjector()
65+
public function dependencyInjector(): object
6566
{
6667
$params = $this->reflect->getConstructor()->getParameters();
6768
$this->injectRecursion($params, $this->reflect->getName());
@@ -99,13 +100,14 @@ private function initReclusiveReflect(string $className, string $fromClass): Ref
99100

100101
/**
101102
* Recursion inject dependancies
102-
* @param array $params
103-
* @param array $args
103+
* @param array $params
104+
* @param string $fromClass
105+
* @param array $_args
104106
* @return array
105107
*/
106-
private function injectRecursion(array $params, string $fromClass, array $args = array())
108+
private function injectRecursion(array $params, string $fromClass, array $_args = array()): array
107109
{
108-
$args = array();
110+
$_args = array();
109111
foreach ($params as $param) {
110112
if ($param->getType() && !$param->getType()->isBuiltin()) {
111113
$classNameA = $param->getType()->getName();
@@ -118,23 +120,23 @@ private function injectRecursion(array $params, string $fromClass, array $args =
118120
}
119121

120122
if (count($reflectParam) > 0) {
121-
$args = $this->injectRecursion($reflectParam, $inst->getName(), $args);
123+
$_args = $this->injectRecursion($reflectParam, $inst->getName(), $_args);
122124

123125
// Will make it posible to set same instance in multiple nested classes
124-
$args = $this->insertMultipleNestedClasses($inst, $constructor, $classNameA, $reflectParam);
126+
$_args = $this->insertMultipleNestedClasses($inst, $constructor, $classNameA, $reflectParam);
125127
} else {
126128
if ($inst->isInterface()) {
127129
$this->insertInterfaceClasses($inst, $classNameA);
128130
} else {
129131
if (empty(self::$class[$classNameA])) {
130-
self::$class[$classNameA] = $this->newInstance($inst, (bool)$constructor, $args);
132+
self::$class[$classNameA] = $this->newInstance($inst, (bool)$constructor, $_args);
131133
}
132134
}
133-
$args[] = self::$class[$classNameA];
135+
$_args[] = self::$class[$classNameA];
134136
}
135137
}
136138
}
137-
return $args;
139+
return $_args;
138140
}
139141

140142
/**
@@ -252,9 +254,9 @@ public static function getClassList()
252254

253255
/**
254256
* Load dependencyInjector / or just a container
255-
* @return instance
257+
* @return object
256258
*/
257-
private function getClass()
259+
private function getClass(): object
258260
{
259261
if (!is_null($this->args)) {
260262
$inst = $this->reflect->newInstanceArgs($this->args);

tests/Controllers/TestController.php

Lines changed: 0 additions & 20 deletions
This file was deleted.

tests/TestClasses/Test.php

Lines changed: 0 additions & 27 deletions
This file was deleted.

tests/TestClasses/TestClass.php

Lines changed: 0 additions & 27 deletions
This file was deleted.

tests/index.php

Lines changed: 0 additions & 73 deletions
This file was deleted.

0 commit comments

Comments
 (0)