Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Commit

Permalink
Fix: __toString ReflectionType deprecation (#90)
Browse files Browse the repository at this point in the history
* fix #82 by using either getName or __toString based on version

Backwards compatibility added for php version < 7.1 eg v5

* fix: logic errors and method use

* apply style CI suggestions

* 📝add an ignore annotation for scrutinizer
  • Loading branch information
ReeceM authored May 25, 2020
1 parent 0951534 commit eaaa216
Showing 1 changed file with 26 additions and 15 deletions.
41 changes: 26 additions & 15 deletions src/mailEclipse.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

namespace qoraiche\mailEclipse;

use RegexIterator;
use ErrorException;
use ReflectionClass;
use ReflectionProperty;
use ReeceM\Mocker\Mocked;
use Illuminate\Support\Str;
use Illuminate\Container\Container;
use Illuminate\Database\Eloquent\Factory as EloquentFactory;
use Illuminate\Mail\Markdown;
use RecursiveIteratorIterator;
use RecursiveDirectoryIterator;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB;
use Illuminate\Container\Container;
use Illuminate\Support\Facades\View;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Database\Eloquent\Factory as EloquentFactory;
use Illuminate\Support\Str;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use ReeceM\Mocker\Mocked;
use ReflectionClass;
use ReflectionProperty;
use RegexIterator;

class mailEclipse
{
Expand Down Expand Up @@ -655,15 +655,26 @@ private static function getMissingParams($arg, $params)
* Determine if a builtin type can be found.
* Not a string or object as a Mocked::class can work there.
*
* ->getType() needs to be cast to string to get the protected prop.
* getName() is undocumented alternative to casting to string.
* https://www.php.net/manual/en/class.reflectiontype.php#124658
*
* @var \ReflectionType $reflection
*/
$argType = (string) collect($params)->where('name', $arg)->first()->getType();
$reflection = collect($params)->where('name', $arg)->first()->getType();

$argType = self::TYPES[$argType] ?? null;
if (version_compare(phpversion(), '7.1', '>=')) {
$type = ! is_null($reflection)
? self::TYPES[$reflection->getName()]
: null;
} else {
$type = ! is_null($reflection)
? self::TYPES[/** @scrutinizer ignore-deprecated */ $reflection->__toString()]
: null;
}

try {
return ! is_null($argType)
? $argType
return ! is_null($type)
? $type
: new Mocked($arg, \ReeceM\Mocker\Utils\VarStore::singleton());
} catch (\Exception $e) {
return $arg;
Expand Down

0 comments on commit eaaa216

Please sign in to comment.