Skip to content

Commit

Permalink
refactor(message): Improve make method in Message class
Browse files Browse the repository at this point in the history
- Refactored the make method in the Message class to handle different argument scenarios efficiently
- Added logic to handle cases where no arguments are passed
- Improved handling of default properties and defined/required properties
  • Loading branch information
guanguans committed Mar 4, 2024
1 parent 36fefe5 commit d50eddb
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Foundation/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,22 @@ public function __debugInfo()
}

/**
* @param array|mixed $options
*
* @return static
*/
public static function make(...$parameters): self
public static function make($options = []): self
{
return new static(...$parameters);
if (0 === \func_num_args()) {
return new static($options);
}

$defaultProperties = (new \ReflectionClass(static::class))->getDefaultProperties();
$defined = array_unique(array_merge($defaultProperties['defined'] ?? [], $defaultProperties['required'] ?? []));
if (1 === \count($defined)) {
return new static([reset($defined) => $options]);
}

return new static($options);
}
}

0 comments on commit d50eddb

Please sign in to comment.