* Implement new config to specify return type of custom relations
* Apply suggestions from code review
Co-authored-by: Markus Podar <[email protected]>
* add test for morphed
* fix test output
* add info about how to add custom relationships
* fix wording
Co-authored-by: Markus Podar <[email protected]>
#1289 calls `getReturnType` for every method on every model, which in
turn calls `getReturnTypeFromDocBlock` which has this code:
```php
$phpDocContext = (new ContextFactory())->createFromReflector($reflection);
```
Extracting the docblock is super slow, always has been. Now that we do
this for every method, this adds up a lot.
Performance on a private commercial project _before_ #1289 was introduced:
```
$ time ./artisan ide-helper:models --write --reset >/dev/null
real 0m2.857s
user 0m1.835s
sys 0m0.129s
```
After #1289 :
```
$ time ./artisan ide-helper:models --write --reset >/dev/null
real 0m54.147s
user 0m47.132s
sys 0m1.047s
```
However, in this case we **do not need** the phpdoc fallback (which is
legitimate and by design for many other cases), because also the Laravel
implementation only works by inspecting the _actual type_, see
https://github.com/laravel/framework/blob/e0c2620b57be6416820ea7ca8e46fd2f71d2fe35/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php#L570-L575
```php
$returnType = (new ReflectionMethod($this, $method))->getReturnType();
return static::$attributeMutatorCache[get_class($this)][$key] = $returnType &&
$returnType instanceof ReflectionNamedType &&
$returnType->getName() === Attribute::class &&
is_callable($this->{$method}()->get);
```
This side-stepping the phpdoc parsing a) still works correctly and b)
brings us back to the previous performance characteristics:
```
time ./artisan ide-helper:models --write --reset >/dev/null
real 0m2.987s
user 0m1.915s
sys 0m0.120s
```
* ✨ Set properties from model functions returning an Attribute
* ✅ Add test for model Attributes
* 🎨 Fix code style
* 🔖 Update changelog
* ✅ Update test to not require php 8
* 🐛 Fix PHP 7.3 incompatibility
* ✅ Update tests to only run when Illuminate Attribute exists
* Make all tests pass cross platform
* Add job to run tests on Windows
* Merge test jobs with conditional Windows step for line endings
* Prefix job name with OS
* Update git lf step if statement
* Exclude all tests for Windows except PHP 8.0
* composer fix-style
Co-authored-by: Barry vd. Heuvel <[email protected]>
Co-authored-by: laravel-ide-helper <[email protected]>
* add comment with @method & @property-read & property-write in models
* add readme comment
* add readme comment
* add comment tag unit-test
* add comment tag unit-test
* both a getter and a setter has a @comment test
* Update README.md
improve README
Co-authored-by: Markus Podar <[email protected]>
* Update CHANGELOG.md
Co-authored-by: Markus Podar <[email protected]>
* Fix exceptions on ReflectionUnionTypes
this commit fixes exceptions thrown on ReflectionUnionType::isBuiltIn() and ReflectionUnionType::getNme() called on php8 union types
* Fix exceptions on ReflectionUnionTypes
this commit fixes exceptions thrown on ReflectionUnionType::isBuiltIn() and ReflectionUnionType::getNme() called on php8 union types
* add check for php8.0
* fix static analysis error
* fix $types variable undefined
* fix failing test
* fix failing test
* fixed style with php-cs-fixer
* add test for union types in parameters and return type
* add test for nullable union types in parameters and return type
* updated CHANGELOG.md
* composer.json: drop support for PHP 7.2/Laravel 6+7 and bump dependencies
* tests: remove framework version tests
They don't apply anymore, we're Laravel 8+ only from now on
* changelog: update for ending support for L6/7 and PHP7.2
* Fix code that was causing the test to break and fix bug with not built in types
* Run cs fixer
* Remove fetching the doc block type and the putting it as a type hint as a php doc block is sufficient
* Revert doc block type hinting
* Enchance doc block type hinting
* Combine replacements
* Use the full builder class instead of the parsed one after the getClassName function and remove in array check
* Get the builder from the model itself instead of passing a string directly the function
* Use the full builder class to get the builder methods and reflection, but use the parsed builder class after setting its method in the doc
* Add test for fqn support on external eloquent builder
* Use the external builder if necessary when building the magic wheres
* Use the default eloquent builder if the user has disabled the external builder option
* Fix code that was causing the test to break and fix bug with not built in types
* Run cs fixer
* Remove fetching the doc block type and the putting it as a type hint as a php doc block is sufficient
* Revert doc block type hinting
* Enchance doc block type hinting
* Combine replacements
* Add support for generating helpers for external eloquent builders
* Extract external builder methods generator to its own method and add an option to toggle this feature
* Check if we are using the default name of the eloquent builder
* Add tests with snapshots for external eloquent builder feature
* Refactor codegs
* Allow for type hinting
* Update test
* Run cs fix
* Update readme
* Use getName for parameter instead of relying on __toString()
* Do not use str_contains and use built in php method
* gha: run on PHP8 too
The composer.json constraint is unbound, so it's already "allowed" at least.
* gha: remove php-cs-fixer when running unit tests
- not necessary anyway
- not compatible with PHP8 currently
* gha: lumen 6 and 7 don't support PHP8
* composer.json: allow spatie/phpunit-snapshot-assertions 4.* for PHP8 compatibility
* php8-compat: Method ReflectionParameter::getClass() is deprecated
* php8-compat: adapt expected error message depending on PHP version
* composer.json: bump mockery to 1.3.3 minimum
This is the minimum version also supporting PHP8
* gha: disable prefer-lowest for PHP8
Some lower version requirements like doctrone/dbal won't work and
would require at least dbal 2.12.0, which in turn doesn't support PHP 7.2
anymore.
So instead of bumping dbal and excluding PHP 7.2 users, we ignore the
lowest version for PHP 8 for the time being.
* Update CHANGELOG.md
* allow model_locations to have glob patterns
This if statement check for a valid directory was happening to early. It was checking the string that contained the wildcards to see if it is a valid directory and always failing. Need to check after the foreach starts. fixes#1058 .
* test(#1059) Allow glob directories
* Fix tests to chdir() into where to expect the glob to work
* Update CHANGELOG.md
Co-authored-by: Markus Podar <[email protected]>
* New --write-mixin option.
* Keep all tags from the existing docblock.
* Update argument description to be more descriptive
Co-authored-by: Markus Podar <[email protected]>
* Add the new --write-mixin option to the docs
* Add test for the new --write-mixin option
* Update README.md
* composer fix-style
* Adapt test after refactoring recently done
Co-authored-by: Markus Podar <[email protected]>
* Make createLocalViewFactory compatible with Laravel 8
Fixes https://github.com/barryvdh/laravel-ide-helper/issues/1024
* tests: move up mockFilesystem so it get be re-used in other tests
Note: removed `$this->mockOutput = '';` as it was a no-op, that property
doesn't exist (it was probably a typo, but I guess we don't need it
anyway)
* tests: show basic features for ide-helper:meta working
Discovered via https://github.com/barryvdh/laravel-ide-helper/pull/1017#issuecomment-679318764
This only happens if you run an artisan command _before_ `runCommand`,
but since every of these tests performs migrations, using artisan,
the mocked output instance is left behind and also affected us.
The call added in `runCommand` explicitly unregisters
`\Illuminate\Console\OutputStyle` and thus also throwing away possibly
mocked versions.
* phpcs: enable also for config, resources and tests
* composer fix-style
* vendor/bin/phpunit -d --update-snapshots
* gha: instead of checking the style, fix and auto-commit it 💪
* Fixes 992 (class names in phpdoc where using imported names incorrectly when writing to external file).
Disabled using imported name in external file, except for the models own name.
* Added missing declare strict types