Skip to content

Commit

Permalink
Update to php 7.4/8
Browse files Browse the repository at this point in the history
  • Loading branch information
LordMonoxide committed Feb 18, 2021
1 parent 906bf4f commit ad6b6d0
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor/
composer.lock
.idea/
.phpunit.result.cache
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
language: php

php:
- 7.1
- 7.2
- 7.4
- 8.0

before_script:
- travis_retry composer self-update
Expand Down
18 changes: 13 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,30 @@
"name": "bapcat/phi",
"description": "A super-minimal inversion-of-control library",
"license": "GPL-3.0-or-later",
"homepage": "http://github.com/BapCat/Phi",
"homepage": "https://github.com/BapCat/Phi",
"keywords": ["IOC", "Inversion of control", "DI", "Dependency injection"],
"authors": [
{
"name": "Corey Frenette",
"email": "corey@narwhunderful.com"
}
],
"config": {
"preferred-install": "dist",
"platform": {
"php": "7.4"
},
"optimize-autoloader": true,
"sort-packages": true
},
"require": {
"php": "^7.1",
"raphhh/trex-reflection": "^1.0"
"php": "^7.4|^8.0",
"raphhh/trex-reflection": "^1.1"
},
"require-dev": {
"roave/security-advisories": "dev-master",
"phpunit/phpunit": "^7.5",
"bapcat/values": "^0.2"
"phpunit/phpunit": "^9.5",
"bapcat/values": "^1.0"
},
"autoload": {
"psr-4": {
Expand Down
24 changes: 14 additions & 10 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="./vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<testsuites>
<testsuite name="unit">
<directory>tests</directory>
</testsuite>
</testsuites>

<phpunit bootstrap="./vendor/autoload.php">
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>

<exclude>
<directory suffix=".php">vendor</directory>
</exclude>
</whitelist>
</filter>
</include>
<exclude>
<directory suffix=".php">vendor</directory>
</exclude>
</coverage>
</phpunit>
24 changes: 15 additions & 9 deletions src/Phi.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use BapCat\Values\Value;

use ReflectionException;
use ReflectionNamedType;
use TRex\Reflection\CallableReflection;

use InvalidArgumentException;
Expand Down Expand Up @@ -121,7 +122,7 @@ public function make(string $alias, array $arguments = []) {
* @param string $binding The binding to instantiate
* @param array $arguments The arguments to pass to the constructor
*
* @return object The instance that is created
* @return mixed The instance that is created
*
* @throws ReflectionException
*/
Expand Down Expand Up @@ -165,9 +166,9 @@ public function call(callable $call, array $arguments = []) {
* @param ReflectionFunctionAbstract $method The method to call
* @param mixed[] $arguments The arguments to pass to the the method
*
* @return mixed The return value of the method
* @return mixed[] The return value of the method
*/
private function buildArguments(ReflectionFunctionAbstract $method, array $arguments = []) {
private function buildArguments(ReflectionFunctionAbstract $method, array $arguments = []): array {
$parameters = $method->getParameters();
$values = [];

Expand Down Expand Up @@ -232,10 +233,11 @@ private function buildArguments(ReflectionFunctionAbstract $method, array $argum

// Step 2...
foreach($parameters as $param_index => $parameter) {
if($parameter->getClass()) {
$type = $parameter->getType();
if($type instanceof ReflectionNamedType && !$type->isBuiltin()) {
foreach($arguments as $arg_index => $argument) {
if(is_object($argument)) {
if($parameter->getClass()->isInstance($argument)) {
if($argument instanceof ($type->getName())) {
$values[$param_index] = $argument;
unset($arguments[$arg_index]);
break;
Expand All @@ -248,14 +250,18 @@ private function buildArguments(ReflectionFunctionAbstract $method, array $argum
// Step 3...
foreach($parameters as $param_index => $parameter) {
if(!array_key_exists($param_index, $values)) {
if($parameter->getClass()) {
if($parameter->getClass()->isSubclassOf(Value::class)) {
$values[$param_index] = $this->make($parameter->getClass()->getName(), [array_shift($arguments)]);
$type = $parameter->getType();

if($type instanceof ReflectionNamedType && !$type->isBuiltin()) {
$class = new ReflectionClass($type->getName());

if($class->isSubclassOf(Value::class)) {
$values[$param_index] = $this->make($type->getName(), [array_shift($arguments)]);
continue;
}

if(!$parameter->isOptional()) {
$values[$param_index] = $this->make($parameter->getClass()->getName());
$values[$param_index] = $this->make($type->getName());
}
} elseif(count($arguments) !== 0) {
$values[$param_index] = array_shift($arguments);
Expand Down

0 comments on commit ad6b6d0

Please sign in to comment.