Skip to content

Commit 3ab4ec3

Browse files
committedNov 30, 2021
breaking: migrate to php 80, for the src/Obj
1 parent 4bcaf5a commit 3ab4ec3

10 files changed

+29
-29
lines changed
 

‎src/Obj/AbstractMap.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function load(array $data): void
5555
* @param string $key
5656
* @param mixed $value
5757
*/
58-
public function setValue(string $key, $value): void
58+
public function setValue(string $key, mixed $value): void
5959
{
6060
ObjectHelper::init($this, [$key => $value]);
6161
}

‎src/Obj/ObjectHelper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public static function buildReflectCallArgs(ReflectionFunctionAbstract $rftFunc,
283283
* @return mixed
284284
* @throws ReflectionException
285285
*/
286-
public static function create(string $class)
286+
public static function create(string $class): mixed
287287
{
288288
try {
289289
$reflection = new ReflectionClass($class);

‎src/Obj/Traits/ArrayAccessByGetterSetterTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function offsetExists($offset): bool
4747
*
4848
* @return mixed The array value if it exists, null otherwise.
4949
*/
50-
public function offsetGet($offset)
50+
public function offsetGet($offset): mixed
5151
{
5252
$getter = 'get' . ucfirst($offset);
5353

‎src/Obj/Traits/ArrayAccessByPropertyTrait.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ trait ArrayAccessByPropertyTrait
3131
*
3232
* @return boolean True if the offset exists, false otherwise.
3333
*/
34-
public function offsetExists($offset): bool
34+
public function offsetExists(mixed $offset): bool
3535
{
3636
return property_exists($this, $offset);
3737
}
@@ -43,7 +43,7 @@ public function offsetExists($offset): bool
4343
*
4444
* @return mixed The array value if it exists, null otherwise.
4545
*/
46-
public function offsetGet($offset)
46+
public function offsetGet(mixed $offset): mixed
4747
{
4848
return $this->$offset;
4949
}
@@ -56,7 +56,7 @@ public function offsetGet($offset)
5656
*
5757
* @return void
5858
*/
59-
public function offsetSet($offset, $value): void
59+
public function offsetSet(mixed $offset, mixed $value): void
6060
{
6161
$this->$offset = $value;
6262
}
@@ -68,7 +68,7 @@ public function offsetSet($offset, $value): void
6868
*
6969
* @return void
7070
*/
71-
public function offsetUnset($offset): void
71+
public function offsetUnset(mixed $offset): void
7272
{
7373
// unset($this->$offset);
7474
}

‎src/Obj/Traits/NameAliasTrait.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ trait NameAliasTrait
1313
/**
1414
* @var array
1515
*/
16-
private $aliases = [];
16+
private array $aliases = [];
1717

1818
/**
1919
* set name alias(es)
2020
*
2121
* @param string $name
22-
* @param string|array $alias
22+
* @param array|string $alias
2323
* @param bool $validate
2424
*/
25-
public function setAlias(string $name, $alias, bool $validate = false): void
25+
public function setAlias(string $name, array|string $alias, bool $validate = false): void
2626
{
2727
foreach ((array)$alias as $aliasName) {
2828
if (!isset($this->aliases[$aliasName])) {

‎src/Obj/Traits/ObjectPoolTrait.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ trait ObjectPoolTrait
2727
/**
2828
* @var SplStack[] [class => \SplStack]
2929
*/
30-
private static $pool = [];
30+
private static array $pool = [];
3131

3232
/**
3333
* @param string $class
3434
*
3535
* @return mixed
3636
*/
37-
public static function get(string $class)
37+
public static function get(string $class): mixed
3838
{
3939
$stack = self::getStack($class);
4040

@@ -46,9 +46,9 @@ public static function get(string $class)
4646
}
4747

4848
/**
49-
* @param stdClass|string $object
49+
* @param string|stdClass $object
5050
*/
51-
public static function put($object): void
51+
public static function put(string|stdClass $object): void
5252
{
5353
if (is_string($object)) {
5454
$object = new $object;
@@ -63,7 +63,7 @@ public static function put($object): void
6363
*
6464
* @return mixed
6565
*/
66-
public static function use(string $class, Closure $handler)
66+
public static function use(string $class, Closure $handler): mixed
6767
{
6868
$obj = self::get($class);
6969
$ret = $handler($obj);
@@ -77,7 +77,7 @@ public static function use(string $class, Closure $handler)
7777
*
7878
* @return SplStack
7979
*/
80-
public static function getStack($class): SplStack
80+
public static function getStack(string|stdClass $class): SplStack
8181
{
8282
$class = is_string($class) ? $class : get_class($class);
8383

‎src/Obj/Traits/PropertyAccessByGetterSetterTrait.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ public function __set($name, $value): void
4444
if (method_exists($this, $setter)) {
4545
$this->$setter($value);
4646
} elseif (method_exists($this, 'get' . ucfirst($name))) {
47-
throw new SetPropertyException('Setting a Read-only property! ' . get_class($this) . "::{$name}");
47+
throw new SetPropertyException('Setting a Read-only property! ' . get_class($this) . "::$name");
4848
} else {
49-
throw new SetPropertyException('Setting a Unknown property! ' . get_class($this) . "::{$name}");
49+
throw new SetPropertyException('Setting a Unknown property! ' . get_class($this) . "::$name");
5050
}
5151
}
5252

@@ -67,10 +67,10 @@ public function __get($name)
6767
}
6868

6969
if (method_exists($this, 'set' . ucfirst($name))) {
70-
throw new GetPropertyException('Getting a Write-only property! ' . get_class($this) . "::{$name}");
70+
throw new GetPropertyException('Getting a Write-only property! ' . get_class($this) . "::$name");
7171
}
7272

73-
throw new GetPropertyException('Getting a Unknown property! ' . get_class($this) . "::{$name}");
73+
throw new GetPropertyException('Getting a Unknown property! ' . get_class($this) . "::$name");
7474
}
7575

7676
/**

‎src/Obj/Traits/SingletonPoolTrait.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ trait SingletonPoolTrait
1919
/**
2020
* @var array
2121
*/
22-
private static $singletons = [];
22+
private static array $singletons = [];
2323

2424
/**
2525
* @param string $class
2626
*
2727
* @return mixed
2828
*/
29-
public static function singleton(string $class)
29+
public static function singleton(string $class): mixed
3030
{
3131
if (!isset(self::$singletons[$class])) {
3232
self::$singletons[$class] = new $class;
@@ -40,7 +40,7 @@ public static function singleton(string $class)
4040
*
4141
* @return mixed
4242
*/
43-
public static function factory(string $class)
43+
public static function factory(string $class): mixed
4444
{
4545
if (!isset(self::$singletons[$class])) {
4646
self::$singletons[$class] = new $class;

‎src/Obj/Traits/SingletonTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ trait SingletonTrait
2121
/**
2222
* @return mixed
2323
*/
24-
public static function new()
24+
public static function new(): mixed
2525
{
2626
return Obj::singleton(static::class);
2727
}

‎src/Obj/Traits/StdObjectTrait.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -97,21 +97,21 @@ public function __call(string $method, array $args)
9797
// return call_user_func_array( array($this, $method), (array) $args);
9898
// }
9999

100-
throw new InvalidArgumentException('Called a Unknown method! ' . get_class($this) . "->{$method}()");
100+
throw new InvalidArgumentException('Called a Unknown method: ' . get_class($this) . "->$method()");
101101
}
102102

103103
/**
104104
* @param string $method
105-
* @param array $args
105+
* @param array $args
106106
*
107107
* @return mixed
108108
*/
109-
public static function __callStatic(string $method, $args)
109+
public static function __callStatic(string $method, array $args)
110110
{
111111
if (method_exists(self::class, $method)) {
112-
return call_user_func_array([self::class, $method], (array)$args);
112+
return call_user_func_array([self::class, $method], $args);
113113
}
114114

115-
throw new InvalidArgumentException('Called a Unknown static method! [ ' . self::class . "::{$method}()]");
115+
throw new InvalidArgumentException('Called a Unknown static method: ' . self::class . "::$method()");
116116
}
117117
}

0 commit comments

Comments
 (0)
Please sign in to comment.