Skip to content

Commit

Permalink
fix request option for make:dto command
Browse files Browse the repository at this point in the history
  • Loading branch information
d8vjork committed Oct 9, 2023
1 parent dc2232f commit 0c1c3f4
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/Commands/DtoMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ class DtoMakeCommand extends GeneratorCommand
protected function getStub()
{
$stubSuffix = '';
$requestOption = $this->option('request');
$hasRequestOption = $this->hasOption('request');

if (! is_null($requestOption)) {
if ($hasRequestOption) {
$stubSuffix .= '.request';
}

if ($requestOption === true) {
if ($hasRequestOption && $this->option('request') === null) {
$stubSuffix .= '.plain';
}

Expand Down Expand Up @@ -81,7 +81,7 @@ protected function buildClass($name)

$requestOption = $this->option('request');

if ($requestOption === true) {
if ($requestOption === null && $this->hasOption('request')) {
return $stub;
}

Expand Down Expand Up @@ -119,6 +119,10 @@ protected function replaceProperties(&$stub, $requestClass)
*/
protected function getProperties(string $requestClass)
{
if (! class_exists($requestClass)) {
return '';
}

$requestInstance = new $requestClass();
$properties = '';

Expand All @@ -143,6 +147,7 @@ protected function getProperties(string $requestClass)

$propertyType = match (true) {
str_contains($rules, 'string') => 'string',
str_contains($rules, 'boolean') => 'bool',
str_contains($rules, 'numeric') => 'int',
str_contains($rules, 'integer') => 'int',
str_contains($rules, 'array') => 'array',
Expand Down

0 comments on commit 0c1c3f4

Please sign in to comment.