* add case when default value is of type enum
* Update CHANGELOG.md
* add tests for enum arguments default values
* ignore psalm issue (built-in `\UnitEnum` class does not exists in PHP7)
* Update run-static-analysis.yml to use PHP8.1
---------
Co-authored-by: Barry vd. Heuvel <[email protected]>
Co-authored-by: Barry vd. Heuvel <[email protected]>
* Add support for protected Attribute accessors
* Fix formatting
* Prevent accessors methods marked as private from being added
* Exclude specific accessors based on trait instead of class
* Add changelog entry
* Add clarifying comment
* Fix accessor attributes not working on PHP < 8.1
* Reintroduce method variable to reduce PR clutter
* Change variable name to reduce PR clutter
* Update CHANGELOG.md
---------
Co-authored-by: Barry vd. Heuvel <[email protected]>
Co-authored-by: Barry vd. Heuvel <[email protected]>
* option to use generics syntax, default to yes in laravel 9
* rename `use_generics_syntax` to `use_generics_annotations`
* update readme and changelog
* remove laravel 9 default override
* include key type in generics annotations
* readme rewording
* set `use_generics_annotations` to `true` by default
* update tests to reflect `use_generics_annotations` being set to `true` by default
* default `use_generics_annotations` setting to true when not set in config
Co-authored-by: Markus Podar <[email protected]>
---------
Co-authored-by: Markus Podar <[email protected]>
* 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]>
* bugfix/custom-types-cause-exception
- Added use statements for DBAL Exception and Type
- Added @throws tag to getPropertiesFromTable method
- Added Type::addType() to properly register types
- Added Try-Catch around Type::addType() to give users a proper error message, then throw the exception up.
* bugfix/custom-types-cause-exception
- Updated CHANGELOG.MD
* bugfix/custom-types-cause-exception
- Fixed `Type enum_string_boolean already exists.` error from being triggered when multiple models are loaded
* Use current connection platform (driver) instead of default connection name to determine used dbms. Previous solution isn't working, when multiple connections with custom names are used.
* chore: add changelog
Co-authored-by: Markus Podar <[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
* 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