mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 01:57:13 +00:00
Fix typos; Optimise if-else branches (#1009)
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
],
|
||||
"require": {
|
||||
"php": ">=7.2",
|
||||
"ext-json": "*",
|
||||
"barryvdh/reflection-docblock": "^2.0.6",
|
||||
"composer/composer": "^1.6 || ^2.0@dev",
|
||||
"doctrine/dbal": "~2.3",
|
||||
|
||||
+8
-11
@@ -63,12 +63,12 @@ class Alias
|
||||
|
||||
$this->detectRoot();
|
||||
|
||||
if ((!$this->isTrait() && $this->root)) {
|
||||
$this->valid = true;
|
||||
} else {
|
||||
if (!$this->root || $this->isTrait()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->valid = true;
|
||||
|
||||
$this->addClass($this->root);
|
||||
$this->detectFake();
|
||||
$this->detectNamespace();
|
||||
@@ -306,10 +306,7 @@ class Alias
|
||||
protected function isTrait()
|
||||
{
|
||||
// Check if the facade is not a Trait
|
||||
if (function_exists('trait_exists') && trait_exists($this->facade)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return trait_exists($this->facade);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -416,7 +413,10 @@ class Alias
|
||||
{
|
||||
$serializer = new DocBlockSerializer(1, $prefix);
|
||||
|
||||
if ($this->phpdoc) {
|
||||
if (!$this->phpdoc) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if ($this->config->get('ide-helper.include_class_docblocks')) {
|
||||
// if a class doesn't expose any DocBlock tags
|
||||
// we can perform reflection on the class and
|
||||
@@ -431,9 +431,6 @@ class Alias
|
||||
return $serializer->getDocComment($this->phpdoc);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes method tags from the doc comment that already appear as functions inside the class.
|
||||
* This prevents duplicate function errors in the IDE.
|
||||
|
||||
@@ -85,12 +85,14 @@ class GeneratorCommand extends Command
|
||||
$this->error(
|
||||
'Error generating IDE Helper: first delete your compiled file (php artisan clear-compiled)'
|
||||
);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
$filename = $this->argument('filename');
|
||||
$format = $this->option('format');
|
||||
|
||||
// Strip the php extension
|
||||
if (substr($filename, -4, 4) == '.php') {
|
||||
if (substr($filename, -4, 4) === '.php') {
|
||||
$filename = substr($filename, 0, -4);
|
||||
}
|
||||
|
||||
@@ -126,7 +128,6 @@ class GeneratorCommand extends Command
|
||||
$this->error("The helper file could not be created at $filename");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function useMemoryDriver()
|
||||
{
|
||||
|
||||
@@ -71,7 +71,7 @@ class ModelsCommand extends Command
|
||||
protected $nullableColumns = [];
|
||||
|
||||
/**
|
||||
* During initializtion we use Laravels Date Facade to
|
||||
* During initialization we use Laravels Date Facade to
|
||||
* determine the actual date class and store it here.
|
||||
*
|
||||
* @var string
|
||||
@@ -224,9 +224,7 @@ class ModelsCommand extends Command
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
|
||||
$this->comment("Loading model '$name'");
|
||||
}
|
||||
$this->comment("Loading model '$name'", OutputInterface::VERBOSITY_VERBOSE);
|
||||
|
||||
if (!$reflectionClass->IsInstantiable()) {
|
||||
// ignore abstract class or interface
|
||||
@@ -346,7 +344,8 @@ class ModelsCommand extends Command
|
||||
|
||||
if (!isset($this->properties[$name])) {
|
||||
continue;
|
||||
} else {
|
||||
}
|
||||
|
||||
$realType = $this->checkForCustomLaravelCasts($realType);
|
||||
$realType = $this->getTypeOverride($realType);
|
||||
$this->properties[$name]['type'] = $this->getTypeInModel($model, $realType);
|
||||
@@ -356,10 +355,9 @@ class ModelsCommand extends Command
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the overide type for the give type.
|
||||
* Returns the override type for the give type.
|
||||
*
|
||||
* @param string $type
|
||||
* @return string|null
|
||||
@@ -368,7 +366,7 @@ class ModelsCommand extends Command
|
||||
{
|
||||
$typeOverrides = $this->laravel['config']->get('ide-helper.type_overrides', array());
|
||||
|
||||
return isset($typeOverrides[$type]) ? $typeOverrides[$type] : $type;
|
||||
return $typeOverrides[$type] ?? $type;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -396,7 +394,10 @@ class ModelsCommand extends Command
|
||||
|
||||
$columns = $schema->listTableColumns($table, $database);
|
||||
|
||||
if ($columns) {
|
||||
if (!$columns) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($columns as $column) {
|
||||
$name = $column->getName();
|
||||
if (in_array($name, $model->getDates())) {
|
||||
@@ -462,7 +463,6 @@ class ModelsCommand extends Command
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
@@ -856,14 +856,12 @@ class ModelsCommand extends Command
|
||||
*/
|
||||
public function getParameters($method)
|
||||
{
|
||||
//Loop through the default values for paremeters, and make the correct output string
|
||||
$params = array();
|
||||
//Loop through the default values for parameters, and make the correct output string
|
||||
$paramsWithDefault = array();
|
||||
/** @var \ReflectionParameter $param */
|
||||
foreach ($method->getParameters() as $param) {
|
||||
$paramClass = $param->getClass();
|
||||
$paramStr = (!is_null($paramClass) ? '\\' . $paramClass->getName() . ' ' : '') . '$' . $param->getName();
|
||||
$params[] = $paramStr;
|
||||
if ($param->isOptional() && $param->isDefaultValueAvailable()) {
|
||||
$default = $param->getDefaultValue();
|
||||
if (is_bool($default)) {
|
||||
@@ -1046,11 +1044,6 @@ class ModelsCommand extends Command
|
||||
return $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object|ReflectionClass $model
|
||||
* @param string $type
|
||||
* @return string
|
||||
*/
|
||||
protected function getTypeInModel(object $model, ?string $type): ?string
|
||||
{
|
||||
if ($type === null) {
|
||||
@@ -1064,11 +1057,6 @@ class ModelsCommand extends Command
|
||||
return $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object|ReflectionClass $model
|
||||
* @param string $className
|
||||
* @return string
|
||||
*/
|
||||
protected function getClassNameInDestinationFile(object $model, string $className): string
|
||||
{
|
||||
$reflection = $model instanceof ReflectionClass
|
||||
|
||||
+18
-14
@@ -85,25 +85,29 @@ class Eloquent
|
||||
}
|
||||
|
||||
$filename = $reflection->getFileName();
|
||||
if ($filename) {
|
||||
if (!$filename) {
|
||||
$command->error('Filename not found ' . $class);
|
||||
return;
|
||||
}
|
||||
|
||||
$contents = $files->get($filename);
|
||||
if ($contents) {
|
||||
if (!$contents) {
|
||||
$command->error('No file contents found ' . $filename);
|
||||
return;
|
||||
}
|
||||
|
||||
$count = 0;
|
||||
$contents = str_replace($originalDoc, $docComment, $contents, $count);
|
||||
if ($count > 0) {
|
||||
if ($files->put($filename, $contents)) {
|
||||
$command->info('Wrote expected docblock to ' . $filename);
|
||||
} else {
|
||||
$command->error('File write failed to ' . $filename);
|
||||
}
|
||||
} else {
|
||||
if ($count <= 0) {
|
||||
$command->error('Content did not change ' . $contents);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
$command->error('No file contents found ' . $filename);
|
||||
}
|
||||
} else {
|
||||
$command->error('Filename not found ' . $class);
|
||||
|
||||
if (!$files->put($filename, $contents)) {
|
||||
$command->error('File write failed to ' . $filename);
|
||||
return;
|
||||
}
|
||||
|
||||
$command->info('Wrote expected docblock to ' . $filename);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace Barryvdh\LaravelIdeHelper;
|
||||
|
||||
use Barryvdh\Reflection\DocBlock;
|
||||
use Barryvdh\Reflection\DocBlock\Tag;
|
||||
|
||||
class Macro extends Method
|
||||
{
|
||||
|
||||
+12
-10
@@ -251,9 +251,14 @@ class Method
|
||||
*/
|
||||
protected function normalizeReturn(DocBlock $phpdoc)
|
||||
{
|
||||
//Get the return type and adjust them for beter autocomplete
|
||||
//Get the return type and adjust them for better autocomplete
|
||||
$returnTags = $phpdoc->getTagsByName('return');
|
||||
if ($returnTags) {
|
||||
|
||||
if (count($returnTags) === 0) {
|
||||
$this->return = null;
|
||||
return;
|
||||
}
|
||||
|
||||
/** @var ReturnTag $tag */
|
||||
$tag = reset($returnTags);
|
||||
// Get the expanded type
|
||||
@@ -273,13 +278,10 @@ class Method
|
||||
? $tag->setType($this->root . '|static')
|
||||
: $tag->setType($this->root);
|
||||
}
|
||||
} else {
|
||||
$this->return = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert keywwords that are incorrect.
|
||||
* Convert keywords that are incorrect.
|
||||
*
|
||||
* @param string $string
|
||||
* @return string
|
||||
@@ -311,11 +313,11 @@ class Method
|
||||
* Get the parameters and format them correctly
|
||||
*
|
||||
* @param \ReflectionMethod $method
|
||||
* @return array
|
||||
* @return void
|
||||
*/
|
||||
public function getParameters($method)
|
||||
{
|
||||
//Loop through the default values for paremeters, and make the correct output string
|
||||
//Loop through the default values for parameters, and make the correct output string
|
||||
$params = array();
|
||||
$paramsWithDefault = array();
|
||||
foreach ($method->getParameters() as $param) {
|
||||
@@ -366,9 +368,9 @@ class Method
|
||||
if (strpos($phpdoc->getText(), '{@inheritdoc}') !== false) {
|
||||
//Not at the end yet, try another parent/interface..
|
||||
return $this->getInheritDoc($method);
|
||||
} else {
|
||||
}
|
||||
|
||||
return $phpdoc;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user