Skip to content

Commit ae5d770

Browse files
authored
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.
1 parent 113545b commit ae5d770

File tree

4 files changed

+11
-52
lines changed

4 files changed

+11
-52
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ All notable changes to this project will be documented in this file.
2020
- 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)
2121
- 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)
2222

23+
### Removed
24+
- Removed format and broken generateJsonHelper [\#1053 / mfn](https://github.com/barryvdh/laravel-ide-helper/pull/1053)
25+
2326
2020-09-07, 2.8.1
2427
-----------------
2528
### Added

config/ide-helper.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
| Filename & Format
88
|--------------------------------------------------------------------------
99
|
10-
| The default filename (without extension) and the format (php or json)
10+
| The default filename
1111
|
1212
*/
1313

14-
'filename' => '_ide_helper',
15-
'format' => 'php',
14+
'filename' => '_ide_helper.php',
1615

1716
/*
1817
|--------------------------------------------------------------------------

src/Console/GeneratorCommand.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,13 @@ public function handle()
8989
}
9090

9191
$filename = $this->argument('filename');
92-
$format = $this->option('format');
9392

94-
// Strip the php extension
95-
if (substr($filename, -4, 4) === '.php') {
96-
$filename = substr($filename, 0, -4);
93+
// Add the php extension if missing
94+
// This is a backwards-compatible shim and can be removed in the future
95+
if (substr($filename, -4, 4) !== '.php') {
96+
$filename .= '.php';
9797
}
9898

99-
$filename .= '.' . $format;
100-
10199
if ($this->option('memory')) {
102100
$this->useMemoryDriver();
103101
}
@@ -115,7 +113,7 @@ public function handle()
115113
}
116114

117115
$generator = new Generator($this->config, $this->view, $this->getOutput(), $helpers);
118-
$content = $generator->generate($format);
116+
$content = $generator->generate();
119117
$written = $this->files->put($filename, $content);
120118

121119
if ($written !== false) {
@@ -165,11 +163,9 @@ protected function getArguments()
165163
*/
166164
protected function getOptions()
167165
{
168-
$format = $this->config->get('ide-helper.format');
169166
$writeMixins = $this->config->get('ide-helper.write_eloquent_model_mixins');
170167

171168
return [
172-
['format', 'F', InputOption::VALUE_OPTIONAL, 'The format for the IDE Helper', $format],
173169
['write_mixins', 'W', InputOption::VALUE_OPTIONAL, 'Write mixins to Laravel Model?', $writeMixins],
174170
['helpers', 'H', InputOption::VALUE_NONE, 'Include the helper files'],
175171
['memory', 'M', InputOption::VALUE_NONE, 'Use sqlite memory driver'],

src/Generator.php

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,9 @@ public function __construct(
6767
/**
6868
* Generate the helper file contents;
6969
*
70-
* @param string $format The format to generate the helper in (php/json)
7170
* @return string;
7271
*/
73-
public function generate($format = 'php')
74-
{
75-
// Check if the generator for this format exists
76-
$method = 'generate' . ucfirst($format) . 'Helper';
77-
if (method_exists($this, $method)) {
78-
return $this->$method();
79-
}
80-
81-
return $this->generatePhpHelper();
82-
}
83-
84-
public function generatePhpHelper()
72+
public function generate()
8573
{
8674
$app = app();
8775
return $this->view->make('helper')
@@ -94,33 +82,6 @@ public function generatePhpHelper()
9482
->render();
9583
}
9684

97-
public function generateJsonHelper()
98-
{
99-
$classes = [];
100-
foreach ($this->getValidAliases() as $aliases) {
101-
foreach ($aliases as $alias) {
102-
$functions = [];
103-
foreach ($alias->getMethods() as $method) {
104-
$functions[$method->getName()] = '(' . $method->getParamsWithDefault() . ')';
105-
}
106-
$classes[$alias->getAlias()] = [
107-
'functions' => $functions,
108-
];
109-
}
110-
}
111-
112-
$flags = JSON_FORCE_OBJECT;
113-
if (defined('JSON_PRETTY_PRINT')) {
114-
$flags |= JSON_PRETTY_PRINT;
115-
}
116-
117-
return json_encode([
118-
'php' => [
119-
'classes' => $classes,
120-
],
121-
], $flags);
122-
}
123-
12485
protected function detectDrivers()
12586
{
12687
$defaultUserModel = config('auth.providers.users.model', config('auth.model', 'App\User'));

0 commit comments

Comments
 (0)