From e306af7413f2660fefd9c21dad65fa4380b74757 Mon Sep 17 00:00:00 2001 From: ReeceM Date: Thu, 10 Dec 2020 23:32:22 +0200 Subject: [PATCH 1/4] fix: restore missing logic in parameter resolution See issue #140 --- src/MailEclipse.php | 53 ++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/src/MailEclipse.php b/src/MailEclipse.php index 436dcde..3cf288e 100644 --- a/src/MailEclipse.php +++ b/src/MailEclipse.php @@ -623,14 +623,7 @@ public static function handleMailableViewDataArgs($mailable) return; } } else { - try { - $missingParam = self::getMissingParams($arg, $params); - $filteredparams[] = is_null($missingParam) - ? new Mocked($arg, \ReeceM\Mocker\Utils\VarStore::singleton()) - : $missingParam; - } catch (\Exception $error) { - $filteredparams[] = $arg; - } + $filteredparams = self::getMissingParams($arg, $params); } } @@ -649,38 +642,44 @@ public static function handleMailableViewDataArgs($mailable) /** * Gets any missing params that may not be collectable in the reflection. * - * @param string $arg the argument string|array + * @param string $arg the argument string| * @param array $params the reflection param list * * @return array|string|\ReeceM\Mocker\Mocked */ 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. - * - * getName() is undocumented alternative to casting to string. - * https://www.php.net/manual/en/class.reflectiontype.php#124658 - * - * @var \ReflectionType $reflection + /** + * Determine if a builtin type can be found. + * Not a string or object as a Mocked::class can work there. + * + * getName() is undocumented alternative to casting to string. + * https://www.php.net/manual/en/class.reflectiontype.php#124658 + * + * @var \ReflectionType $reflection */ $reflection = collect($params)->where('name', $arg)->first()->getType(); - if (is_null($reflection)) { - return $arg; - } - if (version_compare(phpversion(), '7.1', '>=')) { - $reflectionType = $reflection->getName(); + $type = !is_null($reflection) + ? self::TYPES[$reflection->getName()] + : null; } else { - $reflectionType = /** @scrutinizer ignore-deprecated */ $reflection->__toString(); + $type = !is_null($reflection) + ? self::TYPES[ + /** @scrutinizer ignore-deprecated */ + $reflection->__toString()] + : null; } - return array_key_exists($reflectionType, self::TYPES) - ? self::TYPES[$reflectionType] - : $reflectionType; - } + try { + return !is_null($type) + ? $type + : new Mocked($arg, \ReeceM\Mocker\Utils\VarStore::singleton()); + } catch (\Exception $e) { + return $arg; + } + } private static function getMailableViewData($mailable, $mailable_data) { From e7250f4adbf47667f87f61fdc5acf1b0a8f75e27 Mon Sep 17 00:00:00 2001 From: ReeceM Date: Thu, 10 Dec 2020 23:41:20 +0200 Subject: [PATCH 2/4] style ci --- src/MailEclipse.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/MailEclipse.php b/src/MailEclipse.php index 3cf288e..d416fe1 100644 --- a/src/MailEclipse.php +++ b/src/MailEclipse.php @@ -649,23 +649,23 @@ public static function handleMailableViewDataArgs($mailable) */ 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. - * - * getName() is undocumented alternative to casting to string. - * https://www.php.net/manual/en/class.reflectiontype.php#124658 - * - * @var \ReflectionType $reflection + /** + * Determine if a builtin type can be found. + * Not a string or object as a Mocked::class can work there. + * + * getName() is undocumented alternative to casting to string. + * https://www.php.net/manual/en/class.reflectiontype.php#124658 + * + * @var \ReflectionType $reflection */ $reflection = collect($params)->where('name', $arg)->first()->getType(); if (version_compare(phpversion(), '7.1', '>=')) { - $type = !is_null($reflection) + $type = ! is_null($reflection) ? self::TYPES[$reflection->getName()] : null; } else { - $type = !is_null($reflection) + $type = ! is_null($reflection) ? self::TYPES[ /** @scrutinizer ignore-deprecated */ $reflection->__toString()] @@ -679,7 +679,7 @@ private static function getMissingParams($arg, $params) } catch (\Exception $e) { return $arg; } - } + } private static function getMailableViewData($mailable, $mailable_data) { From 730ba2fdd8f05682383137c1fa81ce826a3caec4 Mon Sep 17 00:00:00 2001 From: ReeceM Date: Thu, 10 Dec 2020 23:42:00 +0200 Subject: [PATCH 3/4] changelog --- changelog.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/changelog.md b/changelog.md index 50bd746..2a543c3 100644 --- a/changelog.md +++ b/changelog.md @@ -159,3 +159,23 @@ see #107, #106 ### Addition - Revert Laravel 8 support - Console command for installing assets see PR #111 + +## Version 2.2.1 +Patch Release. + +### Fixes + +- Fixes the string error that happens when the constructor params have a string type hint, issue #103 +see #113 + +## Version 2.2.2 +This is a patch release of the package for a PSR-4 warning + +### Fix + +- The namespace and the file structure of the console command were corrected to PSR-4 standards thanks @ivebe, see #115 + + +## Version 2.2.3 +### Fix +- port version 3 fix back into v2, see #140, #141 \ No newline at end of file From 078218c8df3946fcf6b99a890d2d345cb8bba8fd Mon Sep 17 00:00:00 2001 From: ReeceM Date: Thu, 10 Dec 2020 23:43:19 +0200 Subject: [PATCH 4/4] style: once again I fight with style ci, the battle continues --- src/MailEclipse.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MailEclipse.php b/src/MailEclipse.php index d416fe1..f49ac1f 100644 --- a/src/MailEclipse.php +++ b/src/MailEclipse.php @@ -673,7 +673,7 @@ private static function getMissingParams($arg, $params) } try { - return !is_null($type) + return ! is_null($type) ? $type : new Mocked($arg, \ReeceM\Mocker\Utils\VarStore::singleton()); } catch (\Exception $e) {