Skip to content

Commit d0a0acf

Browse files
author
rotimi
committed
PHP 8.1 min version readiness
1 parent c0d4f96 commit d0a0acf

File tree

5 files changed

+17
-32
lines changed

5 files changed

+17
-32
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
}
1212
],
1313
"require": {
14-
"php": ">=7.4.0"
14+
"php": ">=8.1.0"
1515
},
1616
"require-dev": {
17-
"phpunit/phpunit": "^9.0",
17+
"phpunit/phpunit": "^10.0",
1818
"php-coveralls/php-coveralls": "^2.0",
1919
"rector/rector": "^0.15.0",
2020
"vimeo/psalm": "^5.4"

rector.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
22
declare(strict_types=1);
33

4-
use Rector\Php74\Rector\Property\TypedPropertyRector;
54
use Rector\Set\ValueObject\SetList;
65
use Rector\Config\RectorConfig;
76

@@ -18,8 +17,8 @@
1817
$rectorConfigurator->import(SetList::PHP_72);
1918
$rectorConfigurator->import(SetList::PHP_73);
2019
$rectorConfigurator->import(SetList::PHP_74);
21-
//$rectorConfigurator->import(SetList::PHP_80);
22-
//$rectorConfigurator->import(SetList::PHP_81);
20+
$rectorConfigurator->import(SetList::PHP_80);
21+
$rectorConfigurator->import(SetList::PHP_81);
2322
$rectorConfigurator->import(SetList::DEAD_CODE);
2423
$rectorConfigurator->import(SetList::PSR_4);
2524
$rectorConfigurator->import(SetList::TYPE_DECLARATION);
@@ -44,5 +43,5 @@
4443
$services = $rectorConfigurator->services();
4544

4645
//TODO:PHP8 comment once PHP 8 becomes minimum version
47-
$services->remove(Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector::class);
46+
//$services->remove(Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector::class);
4847
};

src/CallableExecutionTimer.php

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
namespace FunctionExecutionTimer;
55

66
/**
7-
*
87
* A class that can be used to call any function or method while tracking the execution time of each call
98
*
109
* @psalm-suppress MixedAssignment
@@ -14,21 +13,17 @@
1413
*/
1514
class CallableExecutionTimer extends ObjectifiedCallable {
1615

17-
public const NANO_SECOND_TO_SECOND_DIVISOR = 1_000_000_000;
16+
final public const NANO_SECOND_TO_SECOND_DIVISOR = 1_000_000_000;
1817

1918
/**
2019
* Holds execution stats for all function / method calls across all instances of this class
21-
*
22-
* @var array
2320
*/
24-
protected static $benchmarks = [];
21+
protected static array $benchmarks = [];
2522

2623
/**
2724
* Holds execution stats for all function / method calls across all instances of this class
28-
*
29-
* @var array
3025
*/
31-
protected $benchmark = [];
26+
protected array $benchmark = [];
3227

3328
/**
3429
* An array containing data about file, line where static::callFunc(...) was invoked
@@ -49,9 +44,8 @@ class CallableExecutionTimer extends ObjectifiedCallable {
4944
5045
]
5146
*
52-
* @var array
5347
*/
54-
protected $calleeBacktraceData = [];
48+
protected array $calleeBacktraceData = [];
5549

5650
/**
5751
* Set to an array containing backtrace data about file, line where static::callFunc(...) was invoked
@@ -75,14 +69,12 @@ public function getCalleeBacktraceData(): array {
7569
}
7670

7771
/**
78-
*
7972
* @param string $method name of method being invoked
8073
* @param array<mixed> $args
81-
* @return mixed
8274
*
8375
* @throws \Exception from ObjectifiedCallable::__call
8476
*/
85-
public function __call(string $method, array $args) {
77+
public function __call(string $method, array $args): mixed {
8678

8779
if($this->calleeBacktraceData === []) {
8880

@@ -109,7 +101,7 @@ public function __call(string $method, array $args) {
109101
*
110102
* @return mixed result returned from executing function / method registered on an instance of this class
111103
*/
112-
public function __invoke(array $args) {
104+
public function __invoke(array $args): mixed {
113105

114106
$argsCopy = [];
115107

@@ -189,12 +181,10 @@ public function getLatestBenchmark(): array {
189181
* @param string $funcName a name of your choosing (for the callable to be executed) that adheres to PHP method naming rules that will be used to label the call for benchmarking purposes
190182
* @param callable $funcImplementation the callable to be executed
191183
* @param array<mixed> $args arguments required by the callable to be executed
192-
*
193-
* @return mixed
194184
*/
195185
public static function callFunc(
196186
string $funcName, callable $funcImplementation, array $args=[]
197-
) {
187+
): mixed {
198188
$backTraceData = \debug_backtrace();
199189
$funcObj = (new self($funcName, $funcImplementation));
200190

src/ObjectifiedCallable.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,24 +79,23 @@ public function setMethodName(string $methodName): self {
7979
return $this;
8080
}
8181

82-
/**
83-
*
82+
/**
8483
* @param string $methodName should match the name of the method assigned (i.e. to $this->methodName) when this object was created
8584
* @param array<mixed> $args arguments to pass to the function / method to be executed
8685
*
8786
* @return mixed result returned from executing function / method registered on an instance of this class
8887
*
8988
* @throws \Exception if $method !== $this->methodName
9089
*/
91-
public function __call(string $methodName, array $args) {
90+
public function __call(string $methodName, array $args): mixed {
9291

9392
if( $this->methodName === $methodName ) {
9493

9594
return $this->__invoke($args);
9695

9796
} else {
9897
throw new \InvalidArgumentException(
99-
"Error: Method `$methodName` not registered in this instance of `" . get_class($this) . '`'
98+
"Error: Method `$methodName` not registered in this instance of `" . static::class . '`'
10099
);
101100
}
102101
}
@@ -108,7 +107,7 @@ public function __call(string $methodName, array $args) {
108107
*
109108
* @return mixed result returned from executing function / method registered on an instance of this class
110109
*/
111-
public function __invoke(array $args) {
110+
public function __invoke(array $args): mixed {
112111

113112
// need to always keep this method very simple
114113
// because we don't want to add any overhead
@@ -119,7 +118,6 @@ public function __invoke(array $args) {
119118
}
120119

121120
/**
122-
*
123121
* @param string $methodName a valid name (conforming to PHP's method naming convention) for the callable to be registered to this object
124122
* @param callable $method a callable that will be executed via this object
125123
*/

src/Utils.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ class Utils {
1717
* @param array $potentialArray array in which value is to be retrieved from
1818
* @param string $key key in the array whose value is to be retrieved if key exists in array
1919
* @param mixed $defaultVal value to return if key not in array
20-
*
21-
* @return mixed
2220
*/
23-
public static function arrayGet(array $potentialArray, string $key, $defaultVal='') {
21+
public static function arrayGet(array $potentialArray, string $key, mixed $defaultVal=''): mixed {
2422

2523
return (\array_key_exists($key, $potentialArray))
2624
? $potentialArray[$key]

0 commit comments

Comments
 (0)