Remove format and broken generateJsonHelper (#1053)

The JSON generate doesn't work, always generates an empty list.

I looked a bit around and seems changes around 3 years ago broke it.

Since there was no bug report ever about this, I conclude this feature
isn't used and suggest to remove it.

This also changes the config `filename` as there's no need for the
extension-less version and the format is gone too. This change is
backwards compatible as we just add back the `.php` in case it's missing
though users are encouraged to update it.
This commit is contained in:
Markus Podar
2020-12-04 09:54:50 +01:00
committed by GitHub
parent 113545bc1a
commit ae5d7708b7
4 changed files with 11 additions and 52 deletions
+3
View File
@@ -20,6 +20,9 @@ All notable changes to this project will be documented in this file.
- Error when generating helper for macroable classes which are not facades and contain a "fake" method [\#1066 / domkrm] (https://github.com/barryvdh/laravel-ide-helper/pull/1066) - Error when generating helper for macroable classes which are not facades and contain a "fake" method [\#1066 / domkrm] (https://github.com/barryvdh/laravel-ide-helper/pull/1066)
- Casts with a return type of `static` or `$this` now resolve to an instance of the cast [\#1103 / riesjart](https://github.com/barryvdh/laravel-ide-helper/pull/1103) - Casts with a return type of `static` or `$this` now resolve to an instance of the cast [\#1103 / riesjart](https://github.com/barryvdh/laravel-ide-helper/pull/1103)
### Removed
- Removed format and broken generateJsonHelper [\#1053 / mfn](https://github.com/barryvdh/laravel-ide-helper/pull/1053)
2020-09-07, 2.8.1 2020-09-07, 2.8.1
----------------- -----------------
### Added ### Added
+2 -3
View File
@@ -7,12 +7,11 @@ return [
| Filename & Format | Filename & Format
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
| |
| The default filename (without extension) and the format (php or json) | The default filename
| |
*/ */
'filename' => '_ide_helper', 'filename' => '_ide_helper.php',
'format' => 'php',
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
+5 -9
View File
@@ -89,15 +89,13 @@ class GeneratorCommand extends Command
} }
$filename = $this->argument('filename'); $filename = $this->argument('filename');
$format = $this->option('format');
// Strip the php extension // Add the php extension if missing
if (substr($filename, -4, 4) === '.php') { // This is a backwards-compatible shim and can be removed in the future
$filename = substr($filename, 0, -4); if (substr($filename, -4, 4) !== '.php') {
$filename .= '.php';
} }
$filename .= '.' . $format;
if ($this->option('memory')) { if ($this->option('memory')) {
$this->useMemoryDriver(); $this->useMemoryDriver();
} }
@@ -115,7 +113,7 @@ class GeneratorCommand extends Command
} }
$generator = new Generator($this->config, $this->view, $this->getOutput(), $helpers); $generator = new Generator($this->config, $this->view, $this->getOutput(), $helpers);
$content = $generator->generate($format); $content = $generator->generate();
$written = $this->files->put($filename, $content); $written = $this->files->put($filename, $content);
if ($written !== false) { if ($written !== false) {
@@ -165,11 +163,9 @@ class GeneratorCommand extends Command
*/ */
protected function getOptions() protected function getOptions()
{ {
$format = $this->config->get('ide-helper.format');
$writeMixins = $this->config->get('ide-helper.write_eloquent_model_mixins'); $writeMixins = $this->config->get('ide-helper.write_eloquent_model_mixins');
return [ return [
['format', 'F', InputOption::VALUE_OPTIONAL, 'The format for the IDE Helper', $format],
['write_mixins', 'W', InputOption::VALUE_OPTIONAL, 'Write mixins to Laravel Model?', $writeMixins], ['write_mixins', 'W', InputOption::VALUE_OPTIONAL, 'Write mixins to Laravel Model?', $writeMixins],
['helpers', 'H', InputOption::VALUE_NONE, 'Include the helper files'], ['helpers', 'H', InputOption::VALUE_NONE, 'Include the helper files'],
['memory', 'M', InputOption::VALUE_NONE, 'Use sqlite memory driver'], ['memory', 'M', InputOption::VALUE_NONE, 'Use sqlite memory driver'],
+1 -40
View File
@@ -67,21 +67,9 @@ class Generator
/** /**
* Generate the helper file contents; * Generate the helper file contents;
* *
* @param string $format The format to generate the helper in (php/json)
* @return string; * @return string;
*/ */
public function generate($format = 'php') public function generate()
{
// Check if the generator for this format exists
$method = 'generate' . ucfirst($format) . 'Helper';
if (method_exists($this, $method)) {
return $this->$method();
}
return $this->generatePhpHelper();
}
public function generatePhpHelper()
{ {
$app = app(); $app = app();
return $this->view->make('helper') return $this->view->make('helper')
@@ -94,33 +82,6 @@ class Generator
->render(); ->render();
} }
public function generateJsonHelper()
{
$classes = [];
foreach ($this->getValidAliases() as $aliases) {
foreach ($aliases as $alias) {
$functions = [];
foreach ($alias->getMethods() as $method) {
$functions[$method->getName()] = '(' . $method->getParamsWithDefault() . ')';
}
$classes[$alias->getAlias()] = [
'functions' => $functions,
];
}
}
$flags = JSON_FORCE_OBJECT;
if (defined('JSON_PRETTY_PRINT')) {
$flags |= JSON_PRETTY_PRINT;
}
return json_encode([
'php' => [
'classes' => $classes,
],
], $flags);
}
protected function detectDrivers() protected function detectDrivers()
{ {
$defaultUserModel = config('auth.providers.users.model', config('auth.model', 'App\User')); $defaultUserModel = config('auth.providers.users.model', config('auth.model', 'App\User'));