Commit Graph
196 Commits
Author SHA1 Message Date
snmatsui c290af858d reset foreignKeyConstraintsColumns on model loop start (#1461) 2024-02-07 21:31:12 +01:00
f64ff9c0b1 Add support for enum default arguments using enum cases (#1464)
* 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]>
2024-02-07 21:27:30 +01:00
Markus Podar a8b34ad228 Removed support for Laravel 8 and therefore for PHP < 8.0 (#1504)
* Removed support for Laravel 8 and therefore for PHP < 8.0

* Update php-cs-fixer to v3

* composer fix-style
2024-02-05 13:25:08 +01:00
Gerardo Ibarra edc422cd2e add annotation ignore for php code sniffer (#1456) 2023-07-31 11:08:02 +02:00
39885645b9 Add support for protected Attribute accessors (#1339)
* 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]>
2023-02-20 09:44:01 +01:00
b70a9f5048 add immutable_date/time:* casts (#1380)
* add immutable_date/time:* casts

* fix style

* Update CHANGELOG.md

---------

Co-authored-by: Barry vd. Heuvel <[email protected]>
Co-authored-by: Barry vd. Heuvel <[email protected]>
2023-02-20 09:36:24 +01:00
Wim Reckmanandlaravel-ide-helper 9f97f7cd5f Refactor resolving of null information for custom casted attribute types (#1330)
* Refactor resolving of null information for custom casted attribute types

* composer fix-style

---------

Co-authored-by: laravel-ide-helper <[email protected]>
2023-02-20 09:29:48 +01:00
Bartlomiej Kwarcinski 81d5b223ff Fix Castables issue #1312 (#1388)
* Return Castable class if failed to detect it from return types

* fix-style

* Add CHANGELOG.md entry
2023-02-04 14:56:40 +01:00
Taner KucukyurukandMarkus Podar f0e4cf5e78 Generics annotations support (#1298)
* 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]>
2023-01-28 16:48:05 +01:00
Barry vd. Heuvelandlaravel-ide-helper b55769213c Use dev instead of stable (#1409)
* Update run-integration-tests.yml

* composer fix-style

* Update run-integration-tests.yml

Co-authored-by: laravel-ide-helper <[email protected]>
2023-01-22 15:01:12 +01:00
sforwardandSimon Verwaard dda200fd34 Add support for CastsInboundAttributes (#1329)
* Add support for CastsInboundAttributes

* Update changelog

Co-authored-by: Simon Verwaard <[email protected]>
2022-09-13 10:42:06 +02:00
sforwardandSimon Verwaard 532ae5bec3 Fix database name (#1364)
Co-authored-by: Simon Verwaard <[email protected]>
2022-08-13 22:02:45 +02:00
JefemyandBarry vd. Heuvel c8f0f914e3 Fix issue where \Eloquent is not included when using write_mixin (#1352)
* Check for exact mixin name when writing

* changelog

* add mixin to test class

Co-authored-by: Barry vd. Heuvel <[email protected]>
2022-08-11 12:39:26 +02:00
KentarouTakeda 07f5eaea73 Fix return type of methods provided by SoftDeletes (#1345)
* Fix return type of methods provided by `SoftDeletes`

* Update CHANGELOG

* fix test / update snapshot
2022-08-11 12:36:43 +02:00
Corey McCormick c76fbb5b61 Allow for proper database resolve with schemas (#1349)
* Allow for proper database resolve with schemas

* Remove need to explode database and table name
2022-08-11 12:35:46 +02:00
Wim Reckman 5eadd2c7de Fix model factory method arguments for Laravel >= 9 (#1361) 2022-08-11 12:32:14 +02:00
Barry vd. Heuvelandlaravel-ide-helper 6e26f22c76 Feat useclassmappackage (#1357)
* Use composer/class-map-generator

* composer fix-style

Co-authored-by: laravel-ide-helper <[email protected]>
2022-06-20 15:54:12 +02:00
JefemyandMarkus Podar ee9188acf1 Implement new config to specify return type of custom relations (#1300)
* 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]>
2022-05-22 20:07:54 +02:00
FLeudts 6041681495 Add support for Carbon serialization options (#1324)
* Add Carbon serialization option handling

* Tests Added

* Add changelog

* Spellcheck
2022-03-04 09:12:42 +01:00
Barry vd. Heuvelandlaravel-ide-helper 3b03e4055d Replace composer with copy of classmap generator (#1313)
* Replace composer with copy of classmap generator

* composer fix-style

* Remove phpcleaner

* composer fix-style

* Use filecleaner copy

* composer fix-style

Co-authored-by: laravel-ide-helper <[email protected]>
2022-02-08 20:20:22 +01:00
BinotaLIU 2673bf4889 return mixed if we failed detect castable type (#1306)
fixed #1305
2022-01-24 21:39:17 +01:00
BinotaLIU 744a9cf380 support Castables (#1287) 2022-01-09 18:52:15 +01:00
Markus Podar f2a7f9d84f Improve performance for supporting Laravel 8.77+ cast attributes (#1292)
#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
```
2022-01-03 21:47:54 +01:00
Simon Jønsson 29dd57e1e2 Support Laravel 8.77 Attributes (#1289)
*  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
2022-01-03 10:02:18 +01:00
Michael Newton ebea96213d Improve casts support (#1262)
* support for all possible `Model::$casts` types

* add testing for casts

* update changelog

* update changelog (again?)
2021-11-14 17:40:15 +01:00
Sergiy Petrov 01be015f86 PHP 8.1 Support (#1274)
* test against php 8.1

* fix tests
2021-10-31 14:55:33 +01:00
Silvan Krähenbühl a091b9c94a Allow casts without property (#1267)
* Allow casts without property

* Update changelog
2021-10-25 13:45:30 +02:00
George Boot dd12b7cdcb Generate cleaner model mixin classes (#1268)
* Generate cleaner model mixin classes

* Fix test
2021-10-25 13:44:43 +02:00
Wim Reckmanandlaravel-ide-helper c733bde1ea Move default models filename to config (#1241)
* Move default models filename to config

* Add default value when getting models helper filename from config

* composer fix-style

Co-authored-by: laravel-ide-helper <[email protected]>
2021-08-10 07:12:56 +02:00
atsu.kg 52a4b64656 Consider foreign key constraints with isRelationNullable (#1231)
* Consider foreign key constraints with isRelationNullable

* test: add belongsTo Variation

* command: composer test-regenerate
2021-08-07 13:31:20 +02:00
Ajay Dwivedi 2fc239623b Fix #1173 Use FQN for write-mixin (#1174)
* Fix #1173 Use FQN for write-mixin

* Fix #1173 Use FQN for write-mixin: Update Test cases
2021-08-04 11:26:51 +02:00
37f08320ea Make tests pass on Windows (#1205)
* 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]>
2021-08-04 11:22:48 +02:00
ZeroThe2nd b6871d09a4 Bugfix/custom types cause exception (#1228)
* 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
2021-08-04 11:18:55 +02:00
Karel Faille 3b75048d12 Support variadic parameters in models command (#1234) 2021-08-04 11:13:23 +02:00
Alexander StockandMarkus Podar af84c78dec Use platformName to determine db type (#1212)
* 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]>
2021-06-20 10:38:04 +02:00
Daniël de WitandMarkus Podar e71f3d5fc0 Check for traits recursively (#1216)
* Check for traits recursively

* Remove autoload bool from class_uses_recursive

* Add test

* Update src/Console/ModelsCommand.php

Co-authored-by: Markus Podar <[email protected]>

* Updated changelog

Co-authored-by: Markus Podar <[email protected]>
2021-06-20 10:18:14 +02:00
Markus Podar 867a6fd9b4 Merge branch 'master' into jenga201_master 2021-04-03 00:15:42 +02:00
Rob Porter 39a96c3b95 run composer fix-style 2021-04-02 15:30:15 -04:00
wimski 2f61602e7a Support both customized namespace factories as well as default resolvable ones (#1201) 2021-04-02 16:32:13 +02:00
Rob Porter 16a4297992 Allowing Methods to be set in ModelHooks 2021-04-01 15:55:14 -04:00
Ahmed Fathy 92d7f2e706 fix ide-helper:models error if model doesn't have factory 2021-03-29 23:28:18 +02:00
wimskiandlaravel-ide-helper f0c138c4fd Model hooks (#945)
* Model hooks

* composer fix-style

* Fix test for ModelHooks

Co-authored-by: laravel-ide-helper <[email protected]>
2021-03-29 20:49:09 +02:00
biiiiiigmonsterandMarkus Podar c5c9b2b951 Add comments like table columns. (#1168)
* 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]>
2021-03-15 07:52:11 +01:00
Zaid J. Barghouthi db83fb8b6b Remove extra single quote 2021-02-19 07:48:56 +02:00
yaegassy 4f42af1fa1 Apply "@PSR12" in php-cs-fixer (#1150)
* Apply "@PSR12" in php-cs-fixer

* Run fix-style
2021-02-05 13:57:35 +01:00
Fabio Ivona 73c502d5c5 Fix broken ReflectionUnionTypes (#1132)
* 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
2021-01-11 09:15:22 +01:00
Markus Podarandlaravel-ide-helper a83df51ad4 tests: fix assertion (#1139)
* tests: fix assertion

* composer fix-style

Co-authored-by: laravel-ide-helper <[email protected]>
2021-01-11 09:14:12 +01:00
Ahmed Fathy 4f13ba85bd Generate PHPDoc for laravel 8.x factories (#1074)
* Generate PHPDoc for laravel 8.x factories

* formatting

* sorting imports

* fix code style

* fix tests in laravel 7.x and lower

* use markTestSkipped

* fix test failing ~_~

* add  argument

* determine the laravel vertion is 8.2.x or upper

* use version_compare instead of artisan command

* use correct namespace

* formatting

* formatting

* formatting

* update next release notes
2021-01-06 13:38:26 +01:00
Kaloqn 5515cabea3 FQCN bugfix when writing external eloquent builder methods inside models. (#1113)
* 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
2020-12-06 09:55:05 +01:00
Kaloqn 9859958cfa Fix broken test "GeneratePhpdocWithExternalEloquentBuilder" (#1111)
* 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
2020-12-04 14:23:42 +01:00