Skip to content

Commit

Permalink
Merge branch 'php-8.1-readiness'
Browse files Browse the repository at this point in the history
  • Loading branch information
rotimi committed Mar 15, 2024
2 parents 537e470 + 62b2d6a commit 7b74c0b
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 39 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@ jobs:

strategy:
matrix:
php: [8.2, 8.1, 8.0, 7.4]
php: [8.3, 8.2, 8.1]
# prefer-lowest is causing unit tests to fail when php 7.2 is run against PHPunit 7.x,
# PHPUnit 8.x is the latest stable release that supports PHP 7.2 and that runs fine
# dependency-version: [prefer-lowest, prefer-stable]
dependency-version: [prefer-stable]
os: [ubuntu-20.04, ubuntu-22.04]
include:
- os: ubuntu-20.04
php: 7.4
- os: ubuntu-20.04
php: 8.0
- os: ubuntu-20.04
php: 8.1
- os: ubuntu-22.04
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
}
],
"require": {
"php": ">=7.4.0"
"php": ">=8.1.0"
},
"require-dev": {
"phpunit/phpunit": "^9.0",
"phpunit/phpunit": "^10.0",
"php-coveralls/php-coveralls": "^2.0",
"rector/rector": "^1.0.0",
"vimeo/psalm": "^5.4"
Expand Down
12 changes: 7 additions & 5 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="./tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="./tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
<exclude/>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/coverage" lowUpperBound="35" highLowerBound="70"/>
Expand All @@ -18,4 +14,10 @@
<logging>
<junit outputFile="build/logs/junit.xml"/>
</logging>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
<exclude/>
</source>
</phpunit>
4 changes: 2 additions & 2 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
$rectorConfigurator->import(SetList::PHP_72);
$rectorConfigurator->import(SetList::PHP_73);
$rectorConfigurator->import(SetList::PHP_74);
//$rectorConfigurator->import(SetList::PHP_80);
//$rectorConfigurator->import(SetList::PHP_81);
$rectorConfigurator->import(SetList::PHP_80);
$rectorConfigurator->import(SetList::PHP_81);
$rectorConfigurator->import(SetList::DEAD_CODE);
//$rectorConfigurator->import(SetList::PSR_4);
$rectorConfigurator->import(SetList::TYPE_DECLARATION);
Expand Down
22 changes: 6 additions & 16 deletions src/CallableExecutionTimer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
namespace FunctionExecutionTimer;

/**
*
* A class that can be used to call any function or method while tracking the execution time of each call
*
* @psalm-suppress MixedAssignment
Expand All @@ -18,17 +17,13 @@ class CallableExecutionTimer extends ObjectifiedCallable {

/**
* Holds execution stats for all function / method calls across all instances of this class
*
* @var array
*/
protected static $benchmarks = [];
protected static array $benchmarks = [];

/**
* Holds execution stats for all function / method calls across all instances of this class
*
* @var array
*/
protected $benchmark = [];
protected array $benchmark = [];

/**
* An array containing data about file, line where static::callFunc(...) was invoked
Expand All @@ -49,9 +44,8 @@ class CallableExecutionTimer extends ObjectifiedCallable {
]
*
* @var array
*/
protected $calleeBacktraceData = [];
protected array $calleeBacktraceData = [];

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

/**
*
* @param string $method name of method being invoked
* @param array<mixed> $args
* @return mixed
*
* @throws \Exception from ObjectifiedCallable::__call
*/
public function __call(string $method, array $args) {
public function __call(string $method, array $args): mixed {

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

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

$argsCopy = [];

Expand Down Expand Up @@ -189,12 +181,10 @@ public function getLatestBenchmark(): array {
* @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
* @param callable $funcImplementation the callable to be executed
* @param array<mixed> $args arguments required by the callable to be executed
*
* @return mixed
*/
public static function callFunc(
string $funcName, callable $funcImplementation, array $args=[]
) {
): mixed {
$backTraceData = \debug_backtrace();
$funcObj = (new self($funcName, $funcImplementation));

Expand Down
10 changes: 4 additions & 6 deletions src/ObjectifiedCallable.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,23 @@ public function setMethodName(string $methodName): self {
return $this;
}

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

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

return $this->__invoke($args);

} else {
throw new \InvalidArgumentException(
"Error: Method `$methodName` not registered in this instance of `" . get_class($this) . '`'
"Error: Method `$methodName` not registered in this instance of `" . static::class . '`'
);
}
}
Expand All @@ -108,7 +107,7 @@ public function __call(string $methodName, array $args) {
*
* @return mixed result returned from executing function / method registered on an instance of this class
*/
public function __invoke(array $args) {
public function __invoke(array $args): mixed {

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

/**
*
* @param string $methodName a valid name (conforming to PHP's method naming convention) for the callable to be registered to this object
* @param callable $method a callable that will be executed via this object
*/
Expand Down
4 changes: 1 addition & 3 deletions src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ class Utils {
* @param array $potentialArray array in which value is to be retrieved from
* @param string $key key in the array whose value is to be retrieved if key exists in array
* @param mixed $defaultVal value to return if key not in array
*
* @return mixed
*/
public static function arrayGet(array $potentialArray, string $key, $defaultVal='') {
public static function arrayGet(array $potentialArray, string $key, mixed $defaultVal=''): mixed {

return (\array_key_exists($key, $potentialArray))
? $potentialArray[$key]
Expand Down

0 comments on commit 7b74c0b

Please sign in to comment.