Compare commits

..
Author SHA1 Message Date
laravel-ide-helper bd24b63abf composer fix-style 2025-01-01 09:40:57 +00:00
Barry vd. Heuvel e60926d6e6 Add default class for HttpClient macro 2025-01-01 10:40:30 +01:00
9 changed files with 42 additions and 88 deletions
-39
View File
@@ -1,44 +1,5 @@
# Changelog
## v3.5.2 - 2025-01-06
### Fixes
Fix empty/anonymous closure in meta command.
**Full Changelog**: https://github.com/barryvdh/laravel-ide-helper/compare/v3.5.1...v3.5.2
## v3.5.1 - 2025-01-06
### What's Changed
* Remove duplicate config, fix ->can() by @barryvdh in https://github.com/barryvdh/laravel-ide-helper/pull/1650
**Full Changelog**: https://github.com/barryvdh/laravel-ide-helper/compare/v3.5.0...v3.5.1
## v3.5.0 - 2025-01-06
### What's Changed
* Add phpstorm meta argument hints by @barryvdh in https://github.com/barryvdh/laravel-ide-helper/pull/1640
* Add meta override for user return types by @barryvdh in https://github.com/barryvdh/laravel-ide-helper/pull/1642
* Use forked ContextFactory by @barryvdh in https://github.com/barryvdh/laravel-ide-helper/pull/1643
* Remove php parser by @barryvdh in https://github.com/barryvdh/laravel-ide-helper/pull/1644
* Also add eloquent template tags from base class by @barryvdh in https://github.com/barryvdh/laravel-ide-helper/pull/1645
* Add more metadata by @barryvdh in https://github.com/barryvdh/laravel-ide-helper/pull/1646
* Fixed generating PHPDoc for methods with class templates by @chack1172 in https://github.com/barryvdh/laravel-ide-helper/pull/1647
* Feat guess macro types by @barryvdh in https://github.com/barryvdh/laravel-ide-helper/pull/1648
* Allow adding custom Macroable classes. by @mathieutu in https://github.com/barryvdh/laravel-ide-helper/pull/1629
* Add special `dev` to composer keywords by @jnoordsij in https://github.com/barryvdh/laravel-ide-helper/pull/1649
### New Contributors
* @chack1172 made their first contribution in https://github.com/barryvdh/laravel-ide-helper/pull/1647
* @mathieutu made their first contribution in https://github.com/barryvdh/laravel-ide-helper/pull/1629
* @jnoordsij made their first contribution in https://github.com/barryvdh/laravel-ide-helper/pull/1649
**Full Changelog**: https://github.com/barryvdh/laravel-ide-helper/compare/v3.4.0...v3.5.0
## v3.4.0 - 2024-12-29
### What's Changed
-2
View File
@@ -115,8 +115,6 @@ Str::macro('concat', function(string $str1, string $str2) : string {
});
```
You can add any custom Macroable traits to detect in the `macroable_traits` config option.
### Automatic PHPDocs for models
If you don't want to write your properties yourself, you can use the command `php artisan ide-helper:models` to generate
+1 -2
View File
@@ -11,8 +11,7 @@
"netbeans",
"sublime",
"codeintel",
"phpdoc",
"dev"
"phpdoc"
],
"authors": [
{
-14
View File
@@ -334,18 +334,4 @@ return [
// 'ide-helper:models --nowrite',
],
/*
|--------------------------------------------------------------------------
| Macroable Traits
|--------------------------------------------------------------------------
|
| Define which traits should be considered capable of adding Macro.
| You can add any custom trait that behaves like the original Laravel one.
|
*/
'macroable_traits' => [
Filament\Support\Concerns\Macroable::class,
Spatie\Macroable\Macroable::class,
],
];
+1 -2
View File
@@ -6,8 +6,7 @@ return collect(Illuminate\Support\Facades\Gate::abilities())
$policyClass = null;
$closureThis = $reflection->getClosureThis();
if ($closureThis && get_class($closureThis) === Illuminate\Auth\Access\Gate::class) {
if (get_class($reflection->getClosureThis()) === Illuminate\Auth\Access\Gate::class) {
$vars = $reflection->getClosureUsedVariables();
if (isset($vars['callback'])) {
+4 -12
View File
@@ -46,8 +46,6 @@ class Alias
protected $phpdoc = null;
protected $classAliases = [];
protected $isMacroable = false;
/** @var ConfigRepository */
protected $config;
@@ -62,13 +60,12 @@ class Alias
* @param array $magicMethods
* @param array $interfaces
*/
public function __construct($config, $alias, $facade, $magicMethods = [], $interfaces = [], $isMacroable = false)
public function __construct($config, $alias, $facade, $magicMethods = [], $interfaces = [])
{
$this->alias = $alias;
$this->magicMethods = $magicMethods;
$this->interfaces = $interfaces;
$this->config = $config;
$this->isMacroable = $isMacroable;
// Make the class absolute
$facade = '\\' . ltrim($facade, '\\');
@@ -398,20 +395,15 @@ class Alias
// Check if the class is macroable
// (Eloquent\Builder is also macroable but doesn't use Macroable trait)
if ($this->isMacroable || $class === EloquentBuilder::class) {
$traits = collect($reflection->getTraitNames());
if ($traits->contains('Illuminate\Support\Traits\Macroable') || $class === EloquentBuilder::class) {
$properties = $reflection->getStaticProperties();
$macros = isset($properties['macros']) ? $properties['macros'] : [];
foreach ($macros as $macro_name => $macro_func) {
if (!in_array($macro_name, $this->usedMethods)) {
try {
$method = $this->getMacroFunction($macro_func);
} catch (Throwable $e) {
// Invalid method, skip
continue;
}
// Add macros
$this->methods[] = new Macro(
$method,
$this->getMacroFunction($macro_func),
$this->alias,
$reflection,
$macro_name,
+6 -2
View File
@@ -232,14 +232,18 @@ class MetaCommand extends Command
'argumentSet' => 'auth',
],
[
'class' => ['\Illuminate\Support\Facades\Route', '\Illuminate\Support\Facades\Auth', 'Illuminate\Foundation\Auth\Access\Authorizable'],
'class' => ['\Illuminate\Support\Facades\Route', '\Illuminate\Support\Facades\Auth'],
'method' => ['can', 'cannot'],
'argumentSet' => 'auth',
],
[
'method' => 'config',
'argumentSet' => 'configs',
],
[
'class' => ['\Illuminate\Config\Repository', '\Illuminate\Support\Facades\Config'],
'method' => [
// 'get', // config() and Config::Get() are added with return type hints already
'get',
'getMany',
'set',
'string',
+3 -14
View File
@@ -35,7 +35,6 @@ class Generator
protected $magic = [];
protected $interfaces = [];
protected $helpers;
protected array $macroableTraits = [];
/**
* @param \Illuminate\Config\Repository $config
@@ -342,7 +341,7 @@ class Generator
continue;
}
$aliases[] = new Alias($this->config, $class, $class, [], $this->interfaces, true);
$aliases[] = new Alias($this->config, $class, $class, [], $this->interfaces);
}
}
@@ -364,18 +363,8 @@ class Generator
->filter(function ($class) {
$traits = class_uses_recursive($class);
if (isset($traits[Macroable::class])) {
return true;
}
// Filter only classes with a macroable trait
foreach ($this->config->get('ide-helper.macroable_traits', []) as $trait) {
if (isset($traits[$trait])) {
return true;
}
}
return false;
// Filter only classes with the macroable trait
return isset($traits[Macroable::class]);
})
->filter(function ($class) use ($aliases) {
$class = Str::start($class, '\\');
+27 -1
View File
@@ -7,6 +7,7 @@ namespace Barryvdh\LaravelIdeHelper\Tests;
use Barryvdh\LaravelIdeHelper\Alias;
use Barryvdh\LaravelIdeHelper\Macro;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Arr;
/**
@@ -15,6 +16,31 @@ use Illuminate\Support\Arr;
*/
class AliasTest extends TestCase
{
/**
* @covers ::detectMethods
*/
public function testDetectMethodsMacroableMacros(): void
{
// Mock
$macro = __FUNCTION__;
$alias = new AliasMock();
// Macros
Builder::macro(
$macro,
function () {
// empty
}
);
// Prepare
$alias->setClasses([Builder::class]);
$alias->detectMethods();
// Test
$this->assertNotNull($this->getAliasMacro($alias, Builder::class, $macro));
}
/**
* @covers ::detectMethods
*/
@@ -24,7 +50,7 @@ class AliasTest extends TestCase
$macro = __FUNCTION__;
$alias = new AliasMock();
// Macrosx
// Macros
EloquentBuilder::macro(
$macro,
function () {