Skip to content

Commit

Permalink
Update MakeSettingCommand.php
Browse files Browse the repository at this point in the history
Updated the getNamespace() method to check for and remove the leading backslash from the generated namespace and added a conditional check to remove the leading backslash if present in the namespace string.
  • Loading branch information
hamzaelmaghari authored Mar 16, 2024
1 parent ddb70d6 commit e0fe46d
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions src/Console/MakeSettingCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,27 @@ protected function getPath($name, $path): string
return $path . '/' . $name . '.php';
}

protected function getNamespace($path): string
{
$path = preg_replace(
[
'/^(' . preg_quote(base_path(), '/') . ')/',
'/\//',
],
[
'',
'\\',
],
$path
);

return implode('\\', array_map(fn ($directory) => ucfirst($directory), explode('\\', $path)));
protected function getNamespace($path): string
{
$path = preg_replace(
[
'/^(' . preg_quote(base_path(), '/') . ')/',
'/\//',
],
[
'',
'\\',
],
$path
);

$namespace = implode('\\', array_map(fn ($directory) => ucfirst($directory), explode('\\', $path)));

// Remove leading backslash if present
if (substr($namespace, 0, 1) === '\\') {
$namespace = substr($namespace, 1);
}

return $namespace;
}
}

0 comments on commit e0fe46d

Please sign in to comment.