Skip to content

Commit bb1a22f

Browse files
committed
run code inspection check
1 parent 66e0930 commit bb1a22f

6 files changed

+24
-25
lines changed

src/CallableResolver.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ private function resolveCallable($class, $method = '__invoke'): callable
9797
*
9898
* @throws \RuntimeException if the callable is not resolvable
9999
*/
100-
private function assertCallable($callable)
100+
private function assertCallable($callable): void
101101
{
102102
if (!\is_callable($callable)) {
103103
throw new RuntimeException(sprintf(

src/Container.php

+13-14
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class Container implements ContainerInterface, \ArrayAccess, \IteratorAggregate,
5555
* 'id' => Service Object
5656
* ... ...
5757
* ];
58-
* @var Service[]
58+
* @var ObjectItem[]
5959
*/
6060
private $services = [];
6161

@@ -107,7 +107,7 @@ public function set(string $id, $definition, array $opts = []): self
107107
// 已经是个服务实例 object
108108
if (\is_object($definition)) {
109109
$this->ids[$id] = (bool)$opts['locked'];
110-
$this->services[$id] = new Service($definition, $args, $opts['shared'], $opts['locked']);
110+
$this->services[$id] = new ObjectItem($definition, $args, $opts['shared'], $opts['locked']);
111111
$this->setAlias($id, $opts['aliases']);
112112

113113
return $this;
@@ -152,7 +152,7 @@ public function set(string $id, $definition, array $opts = []): self
152152
}
153153

154154
$this->ids[$id] = (bool)$opts['locked'];
155-
$this->services[$id] = new Service($callback, $args, $opts['shared'], $opts['locked']);
155+
$this->services[$id] = new ObjectItem($callback, $args, $opts['shared'], $opts['locked']);
156156
$this->setAlias($id, $opts['aliases']);
157157

158158
// active service
@@ -464,10 +464,10 @@ public function getInstance(string $id, $thrErr = true, $forceNew = false)
464464
* 获取某一个服务的信息
465465
* @param $id
466466
* @param bool $thrErr
467-
* @return Service|null
467+
* @return ObjectItem|null
468468
* @throws \InvalidArgumentException
469469
*/
470-
public function getService(string $id, $thrErr = false)
470+
public function getService(string $id, $thrErr = false): ?ObjectItem
471471
{
472472
$id = $this->resolveAlias($id);
473473

@@ -569,9 +569,9 @@ public function isLocked(string $id): bool
569569
}
570570

571571
/**
572-
* 是已注册的服务
572+
* Is a registered service object
573573
* @param string $id
574-
* @return bool|Service
574+
* @return bool|ObjectItem
575575
*/
576576
public function has($id)
577577
{
@@ -591,7 +591,7 @@ public function exists(string $id): bool
591591

592592
/**
593593
* @param $name
594-
* @return bool|Service
594+
* @return bool|ObjectItem
595595
*/
596596
public function __isset($name)
597597
{
@@ -621,9 +621,9 @@ public function __get($name)
621621
return $service->get($this);
622622
}
623623

624-
$method = 'get' . ucfirst($name);
624+
$method = 'get' . \ucfirst($name);
625625

626-
if (method_exists($this, $method)) {
626+
if (\method_exists($this, $method)) {
627627
return $this->$method();
628628
}
629629

@@ -677,21 +677,20 @@ public function offsetGet($offset)
677677
* Sets an offset in the iterator.
678678
* @param mixed $offset The array offset.
679679
* @param mixed $value The array value.
680-
* @return $this
681680
* @throws \InvalidArgumentException
682681
* @throws DependencyResolutionException
683682
*/
684-
public function offsetSet($offset, $value)
683+
public function offsetSet($offset, $value): void
685684
{
686-
return $this->set($offset, $value);
685+
$this->set($offset, $value);
687686
}
688687

689688
/**
690689
* Unset an offset in the iterator.
691690
* @param mixed $offset The array offset.
692691
* @return void
693692
*/
694-
public function offsetUnset($offset)
693+
public function offsetUnset($offset): void
695694
{
696695
$this->del($offset);
697696
}

src/DIManager.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public static function make(string $name = null, string $group = null): Containe
8282
* @param string $group
8383
* @return void
8484
*/
85-
public static function setDefaultGroup($group = 'di')
85+
public static function setDefaultGroup($group = 'di'): void
8686
{
8787
$group = strtolower(trim($group));
8888

@@ -109,7 +109,7 @@ public static function getDefaultGroup(): string
109109
* reset
110110
* @param string $group
111111
*/
112-
public static function reset($group = null)
112+
public static function reset($group = null): void
113113
{
114114
if (!$group) {
115115
static::$containers = [];

src/NameAliasTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ trait NameAliasTrait
2929
* @param string $name
3030
* @param array|string $alias
3131
*/
32-
public function setAlias(string $name, $alias)
32+
public function setAlias(string $name, $alias): void
3333
{
3434
if (!$name || !$alias) {
3535
return;

src/Service.php src/ObjectItem.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
namespace Toolkit\DI;
1212

1313
/**
14-
* Class Service
14+
* Class ObjectItem
1515
* @package Toolkit\DI
1616
*/
17-
final class Service
17+
final class ObjectItem
1818
{
1919
/**
2020
* @var callable
@@ -109,7 +109,7 @@ public function getCallback()
109109
/**
110110
* @param $callback
111111
*/
112-
public function setCallback($callback)
112+
public function setCallback($callback): void
113113
{
114114
if (!\method_exists($callback, '__invoke')) {
115115
$this->instance = $callback;
@@ -134,7 +134,7 @@ public function getArguments(): array
134134
* @param array $params 设置参数
135135
* @throws \InvalidArgumentException
136136
*/
137-
public function setArguments(array $params)
137+
public function setArguments(array $params): void
138138
{
139139
$this->arguments = $params;
140140
}
@@ -158,7 +158,7 @@ public function isLocked(): bool
158158
/**
159159
* @param bool $locked
160160
*/
161-
public function setLocked($locked = true)
161+
public function setLocked($locked = true): void
162162
{
163163
$this->locked = (bool)$locked;
164164
}
@@ -174,7 +174,7 @@ public function isShared(): bool
174174
/**
175175
* @param bool $shared
176176
*/
177-
public function setShared($shared = true)
177+
public function setShared($shared = true): void
178178
{
179179
$this->shared = (bool)$shared;
180180
}

test/ContainerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919
class ContainerTest extends TestCase
2020
{
21-
public function testCreate()
21+
public function testCreate(): void
2222
{
2323
$di = new Container([
2424
's1' => SomeClass::class,

0 commit comments

Comments
 (0)