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

Commit

Permalink
Merge pull request #180 from Qoraiche/fix/issue-178
Browse files Browse the repository at this point in the history
fix: for issue #178 🐛
  • Loading branch information
ReeceM authored Sep 27, 2021
2 parents 566ab82 + 945367d commit d28f054
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 47 deletions.
4 changes: 2 additions & 2 deletions src/Actions/CreateMailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class CreateMailable
/**
* Handle Creating a new mailable.
*
* @param array $parameters
* @param array $parameters
* @return string[]
*/
public function handle(array $parameters)
Expand Down Expand Up @@ -50,7 +50,7 @@ public function handle(array $parameters)
/**
* Get the parameters for the artisan command.
*
* @param array $parameters
* @param array $parameters
* @return array
*/
protected function commandParameters(array $parameters)
Expand Down
82 changes: 45 additions & 37 deletions src/MailEclipse.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,18 @@ class MailEclipse
*/
public const TYPES = [
'int' => 31,
// 'string' => 'test_string', // not needed as it can be cast __toString()
'string' => null,
'bool' => false,
'float' => 3.14159,
'iterable' => null,
'array' => null,
];

public static $traversed = 0;

/**
* @return array
*
* @throws \ReflectionException
*/
public static function getMailables()
Expand All @@ -59,6 +62,7 @@ public static function getMailables()
* @param $key
* @param $name
* @return Collection
*
* @throws \ReflectionException
*/
public static function getMailable($key, $name): Collection
Expand Down Expand Up @@ -119,7 +123,7 @@ public static function getTemplatesFile()
/**
* Save templates to templates.json file.
*
* @param Collection $templates
* @param Collection $templates
*/
public static function saveTemplates(Collection $templates): void
{
Expand Down Expand Up @@ -313,9 +317,10 @@ public static function markdownedTemplateToView($save = true, $content = '', $vi
* @param $simpleview
* @param $content
* @param $viewName
* @param bool $template
* @param null $namespace
* @param bool $template
* @param null $namespace
* @return bool|string|void
*
* @throws \ReflectionException
*/
public static function previewMarkdownViewContent($simpleview, $content, $viewName, $template = false, $namespace = null)
Expand Down Expand Up @@ -385,7 +390,7 @@ public static function getMailableTemplateData($mailableName)
}

/**
* @param null $request
* @param null $request
* @return JsonResponse
*/
public static function generateMailable($request = null): JsonResponse
Expand Down Expand Up @@ -446,6 +451,7 @@ public static function generateMailable($request = null): JsonResponse
* Get Mailables list.
*
* @return array
*
* @throws \ReflectionException
*/
protected static function mailablesList()
Expand Down Expand Up @@ -548,8 +554,10 @@ protected static function mailablesList()

/**
* Handle Mailable Constructor arguments and pass the fake ones.
*
* @param $mailable
* @return object|void
*
* @throws \ReflectionException
*/
public static function handleMailableViewDataArgs($mailable)
Expand Down Expand Up @@ -624,9 +632,8 @@ 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 array $params the reflection param list
*
* @param string $arg the argument string|array
* @param array $params the reflection param list
* @return array|string|\ReeceM\Mocker\Mocked
*/
private static function getMissingParams($arg, $params)
Expand All @@ -638,24 +645,22 @@ private static function getMissingParams($arg, $params)
* getName() is undocumented alternative to casting to string.
* https://www.php.net/manual/en/class.reflectiontype.php#124658
*
* @var \ReflectionType $reflection
* @var \ReflectionNamedType|null $reflection
*/
$reflection = collect($params)->where('name', $arg)->first()->getType();
$reflection = collect($params)->where('name', $arg)->first()->getType() ?? null;

if (version_compare(phpversion(), '7.1', '>=')) {
$type = ! is_null($reflection)
try {
if (is_null($reflection)) {
return new Mocked($arg, \ReeceM\Mocker\Utils\VarStore::singleton());
}

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

try {
return ! is_null($type)
? $type
: new Mocked($arg, \ReeceM\Mocker\Utils\VarStore::singleton());
return is_null($type)
? new Mocked($arg, \ReeceM\Mocker\Utils\VarStore::singleton())
: $type;
} catch (\Exception $e) {
return $arg;
}
Expand All @@ -665,6 +670,7 @@ private static function getMissingParams($arg, $params)
* @param $mailable
* @param $mailable_data
* @return array|Collection
*
* @throws \ReflectionException
*/
private static function getMailableViewData($mailable, $mailable_data)
Expand Down Expand Up @@ -760,6 +766,7 @@ protected static function mailable_exists($mailable): bool
/**
* @param $mailable
* @return mixed|void
*
* @throws \ReflectionException
*/
protected static function getMarkdownViewName($mailable)
Expand All @@ -779,8 +786,9 @@ protected static function getMarkdownViewName($mailable)

/**
* @param $instance
* @param string $type
* @param string $type
* @return mixed
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
* @throws \ReflectionException
*/
Expand All @@ -800,9 +808,10 @@ public static function buildMailable($instance, $type = 'call')
/**
* @param $simpleview
* @param $view
* @param bool $template
* @param null $instance
* @param bool $template
* @param null $instance
* @return string|void
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
* @throws \ReflectionException
*/
Expand Down Expand Up @@ -900,7 +909,6 @@ public static function generateClassName($input)
*
* @param $eloquentFactory
* @param $model
*
* @return null|object
*/
private static function resolveFactory($eloquentFactory, $model): ?object
Expand Down Expand Up @@ -928,9 +936,8 @@ private static function resolveFactory($eloquentFactory, $model): ?object
* single level relation resolving for a model.
* It will load the relations or set to mocked class.
*
* @param mixed $eloquentFactory
* @param mixed $factoryModel
*
* @param mixed $eloquentFactory
* @param mixed $factoryModel
* @return null|object
*/
private static function hydrateRelations($eloquentFactory, $factoryModel): ?object
Expand Down Expand Up @@ -976,10 +983,9 @@ function () use ($factoryModel, $method) {
*
* @todo Account for the many type relations, link back to parent model for belongsTo
*
* @param mixed $relationName
* @param mixed $factoryModel
* @param mixed|null $eloquentFactory
*
* @param mixed $relationName
* @param mixed $factoryModel
* @param mixed|null $eloquentFactory
* @return null|object
*/
public static function loadRelations($relationName, $factoryModel, $eloquentFactory = null): ?object
Expand Down Expand Up @@ -1026,8 +1032,9 @@ public static function loadRelations($relationName, $factoryModel, $eloquentFact
}

/**
* @param string $name
* @param string $name
* @return bool|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
*
* @throws \ReflectionException
*/
public static function renderMailable(string $name)
Expand All @@ -1050,8 +1057,8 @@ public static function renderMailable(string $name)
}

/**
* @param string $name
* @param string $recipient
* @param string $name
* @param string $recipient
*/
public static function sendTest(string $name, string $recipient): void
{
Expand All @@ -1066,7 +1073,7 @@ public static function sendTest(string $name, string $recipient): void

/**
* @param $mailable
* @param string $email
* @param string $email
* @return mixed
*/
public static function setMailableSendTestRecipient($mailable, string $email)
Expand All @@ -1081,6 +1088,7 @@ public static function setMailableSendTestRecipient($mailable, string $email)
/**
* @param $mailable
* @return object|void
*
* @throws \ReflectionException
*/
private static function resolveMailableInstance($mailable)
Expand Down
11 changes: 6 additions & 5 deletions src/Utils/Replacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct()
/**
* Take the format of the Blade syntax and convert to one the editor understands.
*
* @param mixed $content
* @param mixed $content
* @return string|string[]|null
*/
public static function toEditor($content)
Expand All @@ -62,7 +62,7 @@ public static function toEditor($content)
/**
* Take the data from the editor and return a format that the Blade syntax.
*
* @param mixed $content
* @param mixed $content
* @return string|string[]|null
*/
public static function toBlade($content): string
Expand All @@ -75,9 +75,9 @@ public static function toBlade($content): string
/**
* Replace the content with the patterns and targeted format.
*
* @param array $patterns
* @param array $replacements
* @param mixed $content
* @param array $patterns
* @param array $replacements
* @param mixed $content
* @return string|string[]|null
*/
protected function replace(array $patterns, array $replacements, $content)
Expand All @@ -91,6 +91,7 @@ protected function replace(array $patterns, array $replacements, $content)
* This also ensures that the replace array is the same length as the match array
*
* @return void
*
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
protected function generateRegex()
Expand Down
6 changes: 3 additions & 3 deletions src/Utils/TemplateSkeletons.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public static function skeletons()
}

/**
* @param mixed $type
* @param mixed $name
* @param mixed $skeleton
* @param mixed $type
* @param mixed $name
* @param mixed $skeleton
* @return array|void
*/
public static function get($type, $name, $skeleton)
Expand Down

0 comments on commit d28f054

Please sign in to comment.