Skip to content

Commit 904180b

Browse files
committed
Better code quality
1 parent ca5ada6 commit 904180b

File tree

5 files changed

+24
-22
lines changed

5 files changed

+24
-22
lines changed

Container.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function fetch(string $identifier): array
159159
if (str_contains($identifier, "*")) {
160160
$arr = Arr::value($this->services)->wildcardSearch($identifier)->get();
161161
if (count($arr) > 0) {
162-
$new = array();
162+
$new = [];
163163
foreach ($arr as $key => $_unusedValues) {
164164
$new[$key] = $this->get($key);
165165
}

EventHandler.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function addEvent(callable|object|string $event, ?string $bind = null): v
7474
* @param bool $stopPropagate
7575
* @return void
7676
*/
77-
public function stopPropagation(bool $stopPropagate): void
77+
public function stopPropagation(bool $stopPropagate): void
7878
{
7979
$this->stopPropagate = $stopPropagate;
8080
}
@@ -113,16 +113,18 @@ public function __call(string $method, array $args): mixed
113113
*/
114114
final protected function triggerEvents(): void
115115
{
116-
if (is_array($this->event)) foreach ($this->event as $key => $event) {
117-
if (is_array($event)) {
118-
$select = key($event);
119-
$this->getEvent($event[$select]);
120-
} else {
121-
$this->getEvent($event);
122-
}
123-
// Stop propagate make sure event is executed once
124-
if ($this->stopPropagate) {
125-
unset($this->event[$key]);
116+
if (is_array($this->event)) {
117+
foreach ($this->event as $key => $event) {
118+
if (is_array($event)) {
119+
$select = key($event);
120+
$this->getEvent($event[$select]);
121+
} else {
122+
$this->getEvent($event);
123+
}
124+
// Stop propagate make sure event is executed once
125+
if ($this->stopPropagate) {
126+
unset($this->event[$key]);
127+
}
126128
}
127129
}
128130
}
@@ -133,7 +135,7 @@ final protected function triggerEvents(): void
133135
* @return void
134136
*/
135137
final protected function getEvent(callable|object $data): void
136-
{
138+
{
137139
if(is_callable($data)) {
138140
$data();
139141
} else {

Interfaces/EventInterface.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@
99
*/
1010
interface EventInterface
1111
{
12-
1312
public function resolve(): void;
1413
}

Reflection.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Reflection
1717
private ?array $args = null;
1818
private bool $allowInterfaces = true;
1919
private ?string $dependMethod = null;
20-
private static array $class = array();
20+
private static array $class = [];
2121
private static ?array $interfaceFactory = null;
2222
//private static array $attr = [];
2323
//private static $interfaceProtocol;
@@ -72,7 +72,7 @@ public function allowInterfaces(bool $bool): void
7272
*/
7373
public function dependencyInjector(?object $class = null, ?string $method = null): mixed
7474
{
75-
$args = array();
75+
$args = [];
7676
$constructor = $this->setDependMethod($method, $this->reflect);
7777
if(!is_null($constructor)) {
7878
$params = $constructor->getParameters();
@@ -100,7 +100,7 @@ public function dependencyInjector(?object $class = null, ?string $method = null
100100
* @return ReflectionMethod|null
101101
* @throws ReflectionException
102102
*/
103-
function setDependMethod(?string $method, ReflectionClass $inst): ?ReflectionMethod
103+
public function setDependMethod(?string $method, ReflectionClass $inst): ?ReflectionMethod
104104
{
105105
$method = ($method === "constructor") ? null : $method;
106106
$this->dependMethod = $method;
@@ -138,14 +138,14 @@ private function initReclusiveReflect(string $className, string $fromClass): Ref
138138
* @return array
139139
* @throws Exception
140140
*/
141-
private function injectRecursion(array $params, string $fromClass, array $_args = array()): array
141+
private function injectRecursion(array $params, string $fromClass, array $_args = []): array
142142
{
143-
$_args = array();
143+
$_args = [];
144144
foreach ($params as $param) {
145145
if ($param->getType() && !$param->getType()->isBuiltin()) {
146146
$classNameA = $param->getType()->getName();
147147
$inst = $this->initReclusiveReflect($classNameA, $fromClass);
148-
$reflectParam = array();
148+
$reflectParam = [];
149149
$constructor = $inst->getConstructor();
150150

151151
if (!$inst->isInterface()) {
@@ -206,7 +206,7 @@ private function insertMultipleNestedClasses(
206206
string $classNameA,
207207
array $reflectParam
208208
): array {
209-
$args = array();
209+
$args = [];
210210
foreach ($reflectParam as $reflectInstance) {
211211
if ($reflectInstance->getType() && !$reflectInstance->getType()->isBuiltin()) {
212212
$classNameB = $reflectInstance->getType()->getName();

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"name": "maplephp/container",
33
"type": "library",
4+
"version": "v1.1.2",
45
"description": "Container, Factories and dependency injectors with full PSR-11 support.",
56
"keywords": ["container", "psr11", "factories", "dependency injectors", "injectors"],
67
"homepage": "https://wazabii.se",
@@ -17,7 +18,7 @@
1718
],
1819
"require": {
1920
"php": ">=8.0",
20-
"maplephp/dto": "^1.0"
21+
"maplephp/dto": "^2.0"
2122
},
2223
"autoload": {
2324
"psr-4": {

0 commit comments

Comments
 (0)