Skip to content

Commit

Permalink
Style changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshSalway committed Dec 20, 2024
1 parent c0781d5 commit cf8152d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/Illuminate/Foundation/Console/ApiInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,16 +174,15 @@ protected function installPassport()
/**
* Attempt to add the given trait to the specified model.
*
* @param string $trait
* @param string $model
* @return void
*/
protected function addTraitToModel(string $trait, string $model)
{
$modelPath = $this->laravel->basePath(str_replace('\\', '/', $model) . '.php');
$modelPath = $this->laravel->basePath(str_replace('\\', '/', $model).'.php');

if (!file_exists($modelPath)) {
if (! file_exists($modelPath)) {
$this->components->error("Model not found at {$modelPath}.");

return;
}

Expand All @@ -193,13 +192,14 @@ protected function addTraitToModel(string $trait, string $model)
// Check if the trait is already used in the model
if (strpos($content, $traitBasename) !== false) {
$this->components->info("The [{$trait}] trait is already present in your [{$model}] model.");

return;
}

$modified = false;

// Ensure the 'use $trait;' statement is inserted correctly below other imports
if (!str_contains($content, "use $trait;")) {
if (! str_contains($content, "use $trait;")) {
$content = preg_replace(
'/(use\s+[\w\\\\]+;(\s+\/\/.*\n)*\s*)+/s',
"$0use $trait;\n",
Expand All @@ -221,11 +221,11 @@ protected function addTraitToModel(string $trait, string $model)
if (preg_match('/use\s+(.*?);/s', $content, $useMatches, PREG_OFFSET_CAPTURE, $insertPosition)) {
$traits = $useMatches[1][0];
$traitList = array_map('trim', explode(',', $traits));
if (!in_array($traitBasename, $traitList)) {
if (! in_array($traitBasename, $traitList)) {
$traitList[] = $traitBasename;
$content = substr_replace(
$content,
'use ' . implode(', ', $traitList) . ';',
'use '.implode(', ', $traitList).';',
$useMatches[0][1],
strlen($useMatches[0][0])
);
Expand All @@ -250,4 +250,4 @@ protected function addTraitToModel(string $trait, string $model)
$this->components->info("No changes were made to your [{$model}] model.");
}
}
}
}

0 comments on commit cf8152d

Please sign in to comment.