mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 01:57:13 +00:00
Bring back changes
Missed them from previous commit
This commit is contained in:
@@ -63,6 +63,7 @@ class ModelsCommand extends Command
|
|||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->files = $files;
|
$this->files = $files;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the console command.
|
* Execute the console command.
|
||||||
*
|
*
|
||||||
@@ -193,6 +194,7 @@ class ModelsCommand extends Command
|
|||||||
|
|
||||||
$this->getPropertiesFromMethods($model);
|
$this->getPropertiesFromMethods($model);
|
||||||
$output .= $this->createPhpDocs($name);
|
$output .= $this->createPhpDocs($name);
|
||||||
|
$ignore[] = $name;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$this->error("Exception: " . $e->getMessage() . "\nCould not analyze class $name.");
|
$this->error("Exception: " . $e->getMessage() . "\nCould not analyze class $name.");
|
||||||
}
|
}
|
||||||
@@ -347,6 +349,7 @@ class ModelsCommand extends Command
|
|||||||
$code .= $file->current();
|
$code .= $file->current();
|
||||||
$file->next();
|
$file->next();
|
||||||
}
|
}
|
||||||
|
$code = trim(preg_replace('/\s\s+/', '', $code));
|
||||||
$begin = strpos($code, 'function(');
|
$begin = strpos($code, 'function(');
|
||||||
$code = substr($code, $begin, strrpos($code, '}') - $begin + 1);
|
$code = substr($code, $begin, strrpos($code, '}') - $begin + 1);
|
||||||
|
|
||||||
@@ -362,24 +365,29 @@ class ModelsCommand extends Command
|
|||||||
$search = '$this->' . $relation . '(';
|
$search = '$this->' . $relation . '(';
|
||||||
if ($pos = stripos($code, $search)) {
|
if ($pos = stripos($code, $search)) {
|
||||||
$code = substr($code, $pos + strlen($search));
|
$code = substr($code, $pos + strlen($search));
|
||||||
$arguments = explode(',', substr($code, 0, strpos($code, ')')));
|
$end = strpos($code, ')->') ?:strpos($code, ');');
|
||||||
//Remove quotes, ensure 1 \ in front of the model
|
if (false !== $end) {
|
||||||
$returnModel = $this->getClassName($arguments[0], $model);
|
$arguments = substr($code, 0, $end);
|
||||||
if ($relation === "belongsToMany" or $relation === 'hasMany' or $relation === 'morphMany' or $relation === 'morphToMany') {
|
$arguments = array_map(function($item) {
|
||||||
//Collection or array of models (because Collection is Arrayable)
|
return trim($item, ' \'\"');
|
||||||
$this->setProperty(
|
}, explode(',', $arguments));
|
||||||
$method,
|
//Remove quotes, ensure 1 \ in front of the model
|
||||||
'\Illuminate\Database\Eloquent\Collection|' . $returnModel . '[]',
|
$returnModel = $this->getClassName($arguments[0], $model);
|
||||||
true,
|
if ($relation === "belongsToMany" or $relation === 'hasMany' or $relation === 'morphMany' or $relation === 'morphToMany') {
|
||||||
null
|
//Collection or array of models (because Collection is Arrayable)
|
||||||
);
|
$this->setProperty(
|
||||||
} else {
|
$method,
|
||||||
//Single model is returned
|
'\Illuminate\Database\Eloquent\Collection|' . $returnModel . '[]',
|
||||||
$this->setProperty($method, $returnModel, true, null);
|
true,
|
||||||
|
null
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
//Single model is returned
|
||||||
|
$this->setProperty($method, $returnModel, true, null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -549,7 +557,7 @@ class ModelsCommand extends Command
|
|||||||
{
|
{
|
||||||
// If the class name was resolved via get_class($this) or static::class
|
// If the class name was resolved via get_class($this) or static::class
|
||||||
if (strpos($className, 'get_class($this)') !== false || strpos($className, 'static::class') !== false) {
|
if (strpos($className, 'get_class($this)') !== false || strpos($className, 'static::class') !== false) {
|
||||||
return get_class($model);
|
return "\\" . get_class($model);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the class name was resolved via ::class (PHP 5.5+)
|
// If the class name was resolved via ::class (PHP 5.5+)
|
||||||
|
|||||||
Reference in New Issue
Block a user