diff --git a/.gitattributes b/.gitattributes index 84b8468..ccc4e1e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,14 +2,14 @@ # https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html # Ignore all test and documentation with "export-ignore". -/.gitattributes export-ignore -/.github export-ignore -/.gitignore export-ignore -/.editorconfig export-ignore -/phpunit.xml.dist export-ignore -/tests export-ignore -/.php_cs.common.php export-ignore -/.php_cs.dist export-ignore -/.php_cs.tests.php export-ignore -/psalm.xml export-ignore -/psalm-baseline.xml export-ignore +/.editorconfig export-ignore +/.gitattributes export-ignore +/.github export-ignore +/.gitignore export-ignore +/.php-cs-fixer.cache export-ignore +/.php-cs-fixer.php export-ignore +/.php-cs-fixer.tests.cache export-ignore +/phpunit.xml.dist export-ignore +/psalm-baseline.xml export-ignore +/psalm.xml export-ignore +/tests export-ignore diff --git a/.github/workflows/composer-normalize.yml b/.github/workflows/composer-normalize.yml index 9a2fc97..b7dba34 100644 --- a/.github/workflows/composer-normalize.yml +++ b/.github/workflows/composer-normalize.yml @@ -9,7 +9,7 @@ on: jobs: normalize: timeout-minutes: 15 - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - name: Git checkout uses: actions/checkout@v4 diff --git a/.github/workflows/fix-code-style.yml b/.github/workflows/fix-code-style.yml index 8019a32..da75524 100644 --- a/.github/workflows/fix-code-style.yml +++ b/.github/workflows/fix-code-style.yml @@ -7,7 +7,7 @@ jobs: fix-style: name: Fix Code Style timeout-minutes: 15 - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 env: COMPOSER_NO_INTERACTION: 1 @@ -18,7 +18,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.0 + php-version: 8.3 coverage: none - name: Install dependencies diff --git a/.github/workflows/run-integration-tests.yml b/.github/workflows/run-integration-tests.yml index 96173bf..ed33366 100644 --- a/.github/workflows/run-integration-tests.yml +++ b/.github/workflows/run-integration-tests.yml @@ -12,27 +12,19 @@ on: jobs: php-laravel-integration-tests: - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 timeout-minutes: 15 env: COMPOSER_NO_INTERACTION: 1 strategy: + fail-fast: false matrix: - php: [8.3, 8.2, 8.1, 8.0, 7.4, 7.3] - laravel: [10.*, 9.*, 8.*] + php: [8.3, 8.2, 8.1] + laravel: [11.*, 10.*] exclude: - - php: 8.0 - laravel: 10.* - - php: 7.4 - laravel: 10.* - - php: 7.4 - laravel: 10.* - - php: 7.3 - laravel: 10.* - - php: 7.4 - laravel: 9.* - - php: 7.3 - laravel: 9.* + - php: 8.1 + laravel: 11.* + name: P${{ matrix.php }} - Laravel${{ matrix.laravel }} steps: - name: Checkout code @@ -57,7 +49,7 @@ jobs: run: | cd sample sed -e 's|"type": "project",|&\n"repositories": [ { "type": "path", "url": "../src" } ],|' -i composer.json - composer require --dev "barryvdh/laravel-ide-helper:*" + composer require --dev "barryvdh/laravel-ide-helper:*" --with-all-dependencies - name: Execute generate run run: | diff --git a/.github/workflows/run-static-analysis.yml b/.github/workflows/run-static-analysis.yml index 1085dfe..2c9ea0d 100644 --- a/.github/workflows/run-static-analysis.yml +++ b/.github/workflows/run-static-analysis.yml @@ -9,15 +9,15 @@ on: jobs: build: timeout-minutes: 15 - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 - + - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.0 + php-version: 8.3 coverage: none extensions: pdo_sqlite diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 55b79cd..9aa055f 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -18,28 +18,15 @@ jobs: COMPOSER_NO_INTERACTION: 1 strategy: + fail-fast: false matrix: - os: [ubuntu-20.04, windows-2019] - php: [8.3, 8.2, 8.1, 8.0, 7.4, 7.3] - laravel: [8.*, 9.*, 10.*] - dependency-version: [prefer-lowest, prefer-stable] + os: [ubuntu-22.04, windows-2019] + php: [8.3, 8.2, 8.1] + laravel: [10.*, 11.*] + stability: [prefer-lowest, prefer-stable] exclude: - - php: 8.0 - laravel: 10.* - - php: 7.4 - laravel: 10.* - - php: 7.3 - laravel: 10.* - - php: 8.0 - dependency-version: prefer-lowest - - php: 7.4 - laravel: 9.* - - php: 7.3 - laravel: 9.* - - os: windows-2019 - php: 7.4 - - os: windows-2019 - php: 7.3 + - php: 8.1 + laravel: 11.* steps: - name: Set git to use LF if: ${{ matrix.os == 'windows-2019' }} @@ -62,7 +49,7 @@ jobs: composer remove vimeo/psalm --no-update --dev composer remove friendsofphp/php-cs-fixer --no-update --dev composer require "laravel/framework:${{ matrix.laravel }}" --no-update --no-progress - composer update --prefer-dist --no-progress + composer update --prefer-dist --no-progress --${{ matrix.stability }} - name: Execute Unit Tests run: composer test-ci diff --git a/.gitignore b/.gitignore index 1192196..c92a701 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,8 @@ .phpunit.result.cache /.idea -/.php_cs -/.php_cs.cache -/.php_cs.tests.cache +/.php-cs-fixer.cache +/.php-cs-fixer.php +/.php-cs-fixer.tests.cache /composer.lock /vendor diff --git a/.php_cs.common.php b/.php-cs-fixer.common.php similarity index 94% rename from .php_cs.common.php rename to .php-cs-fixer.common.php index aebd544..31f433b 100644 --- a/.php_cs.common.php +++ b/.php-cs-fixer.common.php @@ -30,7 +30,6 @@ return [ ], 'return_type_declaration' => true, 'short_scalar_cast' => true, - 'single_blank_line_before_namespace' => true, 'single_trait_insert_per_statement' => true, 'ternary_operator_spaces' => true, 'visibility_required' => [ @@ -56,7 +55,7 @@ return [ 'no_unused_imports' => true, 'single_quote' => true, 'space_after_semicolon' => true, - 'trailing_comma_in_multiline_array' => true, + 'trailing_comma_in_multiline' => true, 'trim_array_spaces' => true, 'unary_operator_spaces' => true, 'whitespace_after_comma_in_array' => true, diff --git a/.php_cs.dist b/.php-cs-fixer.dist.php similarity index 59% rename from .php_cs.dist rename to .php-cs-fixer.dist.php index 2083345..41c5d21 100644 --- a/.php_cs.dist +++ b/.php-cs-fixer.dist.php @@ -5,10 +5,10 @@ $finder = PhpCsFixer\Finder::create() ->in(__DIR__) ->exclude('tests'); -$config = require __DIR__ . '/.php_cs.common.php'; +$config = require __DIR__ . '/.php-cs-fixer.common.php'; -return PhpCsFixer\Config::create() +return (new PhpCsFixer\Config()) ->setFinder($finder) ->setRules($config) ->setRiskyAllowed(true) - ->setCacheFile(__DIR__ . '/.php_cs.cache'); + ->setCacheFile(__DIR__ . '/.php-cs-fixer.cache'); diff --git a/.php_cs.tests.php b/.php-cs-fixer.tests.php similarity index 69% rename from .php_cs.tests.php rename to .php-cs-fixer.tests.php index 24c484d..652efcd 100644 --- a/.php_cs.tests.php +++ b/.php-cs-fixer.tests.php @@ -5,7 +5,7 @@ $finder = PhpCsFixer\Finder::create() ->in(__DIR__ . '/tests') ->exclude('__snapshots__'); -$config = require __DIR__ . '/.php_cs.common.php'; +$config = require __DIR__ . '/.php-cs-fixer.common.php'; // Additional rules for tests $config = array_merge( @@ -15,8 +15,8 @@ $config = array_merge( ] ); -return PhpCsFixer\Config::create() +return (new PhpCsFixer\Config()) ->setFinder($finder) ->setRules($config) ->setRiskyAllowed(true) - ->setCacheFile(__DIR__ . '/.php_cs.tests.cache'); + ->setCacheFile(__DIR__ . '/.php-cs-fixer.tests.cache'); diff --git a/CHANGELOG.md b/CHANGELOG.md index 70ed218..d77229a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,18 +2,92 @@ All notable changes to this project will be documented in this file. -[Next release](https://github.com/barryvdh/laravel-ide-helper/compare/v2.13.0...master) +[Next release](https://github.com/barryvdh/laravel-ide-helper/compare/v3.0.0...master) -------------- +### Fixed + +### Changed + +### Added + +2024-03-01, 3.0.0 +------------------ + +### Added +- Support for Laravel 11 [#1520 / KentarouTakeda](https://github.com/barryvdh/laravel-ide-helper/pull/1520) + +### Changed +- Make `--reset` always keep the text and remove `--smart-reset`. Always skip the classname [#1523 / barryvdh](https://github.com/barryvdh/laravel-ide-helper/pull/1523) & [#1525 / mfn](https://github.com/barryvdh/laravel-ide-helper/pull/1525) +- Use short types (`int` and `bool` instead of `integer` and `boolean`) [#1524 / barryvdh](https://github.com/barryvdh/laravel-ide-helper/pull/1524) + +### Removed +- Support for Laravel 9 and use of doctrine/dbal [#1512 / barryvdh](https://github.com/barryvdh/laravel-ide-helper/pull/1512) + With this functionality gone, a few changes have been made: + - support for custom datatypes has been dropped (config `custom_db_types`) unknown data types default to `string` now and to fix the type, add a proper cast in Eloquent + - You _might_ have top-level dependency on doctrine/dbal. This may have been in the past due to ide-helper, we suggest to check if you still need it and remove it otherwise + - Minimum PHP version, due to Laravel 10, is now PHP 8.1 + +2024-02-15, 2.15.1 +------------------ + +### Fixed +- Fix final class keyword in wrong position [#1517 / barryvdh](https://github.com/barryvdh/laravel-ide-helper/pull/1517) + +### Changed + +### Added + +2024-02-14, 2.15.0 +------------------ +### Fixed +- Fix case issue in `ModelsCommand::unsetMethod()` [#1453 / leo108](https://github.com/barryvdh/laravel-ide-helper/pull/1453) +- Fix non-facade classes will result in no autocomplete [#841 / netpok](https://github.com/barryvdh/laravel-ide-helper/pull/841) +- Skip swoole, otherwise fatal error [#1477 / TimoFrenzel](https://github.com/barryvdh/laravel-ide-helper/pull/1477) +- Fix vulnerability CVE-2021-43608 [#1392 / allanlaal](https://github.com/barryvdh/laravel-ide-helper/pull/1392) +- Reset foreignKeyConstraintsColumns on model loop start [#1461 / snmatsui](https://github.com/barryvdh/laravel-ide-helper/pull/1461) +- Accept scope & scopes as relation [#1452 / Muetze42](https://github.com/barryvdh/laravel-ide-helper/pull/1452) +- Fix #1300 relation_return_type must take precedence if it is defined [#1394 / menthol](https://github.com/barryvdh/laravel-ide-helper/pull/1394) + +### Changed +- Disable inspections of helper files [#1486 / eidng8](https://github.com/barryvdh/laravel-ide-helper/pull/1486) +- Removed support for Laravel 8 and therefore for PHP < 8.0 [#1504 / mfn](https://github.com/barryvdh/laravel-ide-helper/pull/1504) + +### Added +- Add support for enum default arguments using enum cases. [#1464 / d8vjork](https://github.com/barryvdh/laravel-ide-helper/pull/1464) +- Add support for real-time facades in the helper file. [#1455 / filipac](https://github.com/barryvdh/laravel-ide-helper/pull/1455) +- Add support for relations with composite keys. [#1479 / calebdw](https://github.com/barryvdh/laravel-ide-helper/pull/1479) +- Add support for attribute accessors with no backing field or type hinting [#1411 / pindab0ter](https://github.com/barryvdh/laravel-ide-helper/pull/1411). +- Add support for AsCollection and AsArrayObject casts [#1393 / pataar](https://github.com/barryvdh/laravel-ide-helper/pull/1393) +- Reintroduce support for multi-db setups [#1426 / benpoulson](https://github.com/barryvdh/laravel-ide-helper/pull/1426) +- Support the BINARY(...) database field type [#1434 / Sfonxs](https://github.com/barryvdh/laravel-ide-helper/pull/1434) +- Add AllowDynamicProperties Attribute to cooperate with php8.2 deprecation [#1428 / GeoSot](https://github.com/barryvdh/laravel-ide-helper/pull/1428) + +2024-02-05, 2.14.0 +------------------ + ### Changed - Official support for Lumen has been dropped [#1425 / mfn](https://github.com/barryvdh/laravel-ide-helper/pull/1425) - Refactor resolving of null information for custom casted attribute types [#1330 / wimski](https://github.com/barryvdh/laravel-ide-helper/pull/1330) ### Fixed -- Add support for attribute accessors marked as protected. [#1339 / pindab0ter](https://github.com/barryvdh/laravel-ide-helper/pull/1339) +- Catch exceptions when loading aliases [#1465 / dongm2ez](https://github.com/barryvdh/laravel-ide-helper/pull/1465) ### Added +- Add support for nikic/php-parser 5 (next to 4) [#1502 / mfn](https://github.com/barryvdh/laravel-ide-helper/pull/1502) - Add support for `immutable_date:*` and `immutable_datetime:*` casts. [#1380 / thekonz](https://github.com/barryvdh/laravel-ide-helper/pull/1380) +- Add support for attribute accessors marked as protected. [#1339 / pindab0ter](https://github.com/barryvdh/laravel-ide-helper/pull/1339) + +2024-01-04, v2.14.0 +------------------ + +### Fixes + +- Add AllowDynamicProperties when creating mixin: credit to GeoSot - https://github.com/GeoSot/laravel-ide-helper +- Fix for getSomethingAttribute functions which return a collection with type templating in the phpDoc. https://github.com/scrumble-nl/laravel-ide-helper/pull/1 + +### Extra +This release contains all commits from the main laravel-ide-helper repo up to 04-01-2024. 2023-02-04, 2.13.0 ------------------ diff --git a/README.md b/README.md index 92f04fa..b28c0dd 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ This package generates helper files that enable your IDE to provide accurate autocompletion. Generation is done based on the files in your project, so they are always up-to-date. -It supports Laravel 8+ and PHP 7.3+ +The 3.x branch supports Laravel 10 and 11. For older version, use the 2.x releases. - [Installation](#installation) - [Usage](#usage) @@ -33,6 +33,10 @@ Require this package with composer using the following command: composer require --dev barryvdh/laravel-ide-helper ``` +> [!NOTE] +> If you encounter version conflicts with doctrine/dbal, please try: +> `composer require --dev barryvdh/laravel-ide-helper --with-all-dependencies` + This package makes use of [Laravels package auto-discovery mechanism](https://medium.com/@taylorotwell/package-auto-discovery-in-laravel-5-5-ea9e3ab20518), which means if you don't install dev dependencies in production, it also won't be loaded. If for some reason you want manually control this: @@ -68,7 +72,7 @@ If for some reason you want manually control this: _Check out [this Laracasts video](https://laracasts.com/series/how-to-be-awesome-in-phpstorm/episodes/15) for a quick introduction/explanation!_ - `php artisan ide-helper:generate` - [PHPDoc generation for Laravel Facades ](#automatic-phpdoc-generation-for-laravel-facades) -- `php artisan ide-helper:models` - [PHPDocs for models](#automatic-PHPDocs-for-models) +- `php artisan ide-helper:models` - [PHPDocs for models](#automatic-phpdocs-for-models) - `php artisan ide-helper:meta` - [PhpStorm Meta file](#phpstorm-meta-for-container-instances) @@ -109,6 +113,10 @@ The generator tries to identify the real class, but if it cannot be found, you c Some classes need a working database connection. If you do not have a default working connection, some facades will not be included. You can use an in-memory SQLite driver by adding the `-M` option. +If you use [real-time facades](https://laravel.com/docs/master/facades#real-time-facades) in your app, those will also be included in the generated file using a `@mixin` annotation and extending the original class underneath the facade. + +**Note**: this feature uses the generated real-time facades files in the `storage/framework/cache` folder. Those files are generated on-demand as you use the real-time facade, so if the framework has not generated that first, it will not be included in the helper file. Run the route/command/code first and then regenerate the helper file and this time the real-time facade will be included in it. + You can choose to include helper files. This is not enabled by default, but you can override it with the `--helpers (-H)` option. The `Illuminate/Support/helpers.php` is already set up, but you can add/remove your own files in the config file. @@ -141,9 +149,9 @@ The class name will be different from the model, avoiding the IDE duplicate anno > Please make sure to back up your models, before writing the info. -Writing to the models should keep the existing comments and only append new properties/methods. -The existing PHPDoc is replaced, or added if not found. -With the `--reset (-R)` option, the existing PHPDocs are ignored, and only the newly found columns/relations are saved as PHPDocs. +Writing to the models should keep the existing comments and only append new properties/methods. It will not update changed properties/methods. + +With the `--reset (-R)` option, the whole existing PHPDoc is replaced, including any comments that have been made. ```bash php artisan ide-helper:models "App\Models\Post" @@ -263,26 +271,6 @@ add support for creating a new dedicated class instead of using local scopes in If for some reason it's undesired to have them generated (one for each column), you can disable this via config `write_model_external_builder_methods` and setting it to `false`. -#### Unsupported or custom database types - -Common column types (e.g. varchar, integer) are correctly mapped to PHP types (`string`, `int`). - -But sometimes you may want to use custom column types in your database like `geography`, `jsonb`, `citext`, `bit`, etc. which may throw an "Unknown database type"-Exception. - -For those special cases, you can map them via the config `custom_db_types`. Example: -```php -'custom_db_types' => [ - 'mysql' => [ - 'geography' => 'array', - 'point' => 'array', - ], - 'postgresql' => [ - 'jsonb' => 'string', - '_int4' => 'array', - ], -], -``` - #### Custom Relationship Types If you are using relationships not built into Laravel you will need to specify the name and returning class in the config to get proper generation. diff --git a/composer.json b/composer.json index 2eecae2..1585378 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "barryvdh/laravel-ide-helper", + "name": "scrumble-nl/laravel-ide-helper", "description": "Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.", "license": "MIT", "keywords": [ @@ -20,30 +20,30 @@ } ], "require": { - "php": "^7.3 || ^8.0", + "php": "^8.1", "ext-json": "*", - "barryvdh/reflection-docblock": "^2.0.6", + "barryvdh/reflection-docblock": "^2.1.1", "composer/class-map-generator": "^1.0", - "doctrine/dbal": "^2.6 || ^3", - "illuminate/console": "^8 || ^9 || ^10", - "illuminate/filesystem": "^8 || ^9 || ^10", - "illuminate/support": "^8 || ^9 || ^10", - "nikic/php-parser": "^4.7", + "illuminate/console": "^10 || ^11", + "illuminate/database": "^10.38 || ^11", + "illuminate/filesystem": "^10 || ^11", + "illuminate/support": "^10 || ^11", + "nikic/php-parser": "^4.18 || ^5", "phpdocumentor/type-resolver": "^1.1.0" }, "require-dev": { "ext-pdo_sqlite": "*", - "friendsofphp/php-cs-fixer": "^2", - "illuminate/config": "^8 || ^9 || ^10", - "illuminate/view": "^8 || ^9 || ^10", + "friendsofphp/php-cs-fixer": "^3", + "illuminate/config": "^9 || ^10 || ^11", + "illuminate/view": "^9 || ^10 || ^11", "mockery/mockery": "^1.4", - "orchestra/testbench": "^6 || ^7 || ^8", - "phpunit/phpunit": "^8.5 || ^9", - "spatie/phpunit-snapshot-assertions": "^3 || ^4", + "orchestra/testbench": "^8 || ^9", + "phpunit/phpunit": "^10.5", + "spatie/phpunit-snapshot-assertions": "^4 || ^5", "vimeo/psalm": "^5.4" }, "suggest": { - "illuminate/events": "Required for automatic helper generation (^6|^7|^8|^9|^10)." + "illuminate/events": "Required for automatic helper generation (^6|^7|^8|^9|^10|^11)." }, "minimum-stability": "dev", "prefer-stable": true, @@ -65,7 +65,7 @@ }, "extra": { "branch-alias": { - "dev-master": "2.13-dev" + "dev-master": "3.0-dev" }, "laravel": { "providers": [ @@ -81,7 +81,7 @@ ], "fix-style": [ "php-cs-fixer fix", - "php-cs-fixer fix --config=.php_cs.tests.php" + "php-cs-fixer fix --config=.php-cs-fixer.tests.php" ], "psalm-set-baseline": "psalm --set-baseline=psalm-baseline.xml", "test": "phpunit", diff --git a/config/ide-helper.php b/config/ide-helper.php index 80afdb2..e3bdc57 100644 --- a/config/ide-helper.php +++ b/config/ide-helper.php @@ -200,36 +200,6 @@ return [ ], - /* - |-------------------------------------------------------------------------- - | Support for custom DB types - |-------------------------------------------------------------------------- - | - | This setting allow you to map any custom database type (that you may have - | created using CREATE TYPE statement or imported using database plugin - | / extension to a Doctrine type. - | - | Each key in this array is a name of the Doctrine2 DBAL Platform. Currently valid names are: - | 'postgresql', 'db2', 'drizzle', 'mysql', 'oracle', 'sqlanywhere', 'sqlite', 'mssql' - | - | This name is returned by getName() method of the specific Doctrine/DBAL/Platforms/AbstractPlatform descendant - | - | The value of the array is an array of type mappings. Key is the name of the custom type, - | (for example, "jsonb" from Postgres 9.4) and the value is the name of the corresponding Doctrine2 type (in - | our case it is 'json_array'. Doctrine types are listed here: - | https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/types.html#types - | - | So to support jsonb in your models when working with Postgres, just add the following entry to the array below: - | - | "postgresql" => array( - | "jsonb" => "json_array", - | ), - | - */ - 'custom_db_types' => [ - - ], - /* |-------------------------------------------------------------------------- | Support for camel cased models @@ -322,7 +292,8 @@ return [ | | When using custom relation types its possible for the class name to not contain | the proper return type of the relation. The key of the array is the relationship - | method name. The value of the array is the return type of the relation. + | method name. The value of the array is the return type of the relation ('many' + | or 'morphTo'). | e.g. `'relationName' => 'many'`. | */ diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5168263..410be68 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,24 +1,17 @@ - + tests - + src/ - + diff --git a/psalm-baseline.xml b/psalm-baseline.xml index f6a5b14..84de223 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -16,4 +16,9 @@ \Storage + + + \UnitEnum + + diff --git a/resources/views/helper.php b/resources/views/helper.php index ecbd055..9479a7e 100644 --- a/resources/views/helper.php +++ b/resources/views/helper.php @@ -8,6 +8,7 @@ */ ?> +/* @noinspection ALL */ // @formatter:off // phpcs:ignoreFile @@ -22,9 +23,6 @@ */ $aliases) : ?> - namespace { getDocComment(' ')) ?> @@ -71,6 +69,16 @@ namespace { + + +namespace { + /** + * @mixin + */ + class extends {} +} + + namespace { diff --git a/resources/views/meta.php b/resources/views/meta.php index 2840d91..5b7b9c2 100644 --- a/resources/views/meta.php +++ b/resources/views/meta.php @@ -1,6 +1,8 @@ +/* @noinspection ALL */ // @formatter:off +// phpcs:ignoreFile namespace PHPSTORM_META { diff --git a/src/Alias.php b/src/Alias.php index ff4ae67..046fffe 100644 --- a/src/Alias.php +++ b/src/Alias.php @@ -329,7 +329,7 @@ class Alias continue; } $method = new \ReflectionMethod($className, $name); - $class = new \ReflectionClass($className); + $class = new ReflectionClass($className); if (!in_array($magic, $this->usedMethods)) { if ($class !== $this->root) { @@ -348,7 +348,7 @@ class Alias protected function detectMethods() { foreach ($this->classes as $class) { - $reflection = new \ReflectionClass($class); + $reflection = new ReflectionClass($class); $methods = $reflection->getMethods(\ReflectionMethod::IS_PUBLIC); if ($methods) { diff --git a/src/Console/GeneratorCommand.php b/src/Console/GeneratorCommand.php index 40758ec..0004e8f 100644 --- a/src/Console/GeneratorCommand.php +++ b/src/Console/GeneratorCommand.php @@ -42,7 +42,7 @@ class GeneratorCommand extends Command /** @var \Illuminate\Config\Repository */ protected $config; - /** @var \Illuminate\Filesystem\Filesystem */ + /** @var Filesystem */ protected $files; /** @var \Illuminate\View\Factory */ @@ -54,7 +54,7 @@ class GeneratorCommand extends Command /** * * @param \Illuminate\Config\Repository $config - * @param \Illuminate\Filesystem\Filesystem $files + * @param Filesystem $files * @param \Illuminate\View\Factory $view */ public function __construct( diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index 17bda64..4ec323a 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -18,12 +18,12 @@ use Barryvdh\Reflection\DocBlock\Context; use Barryvdh\Reflection\DocBlock\Serializer as DocBlockSerializer; use Barryvdh\Reflection\DocBlock\Tag; use Composer\ClassMapGenerator\ClassMapGenerator; -use Doctrine\DBAL\Exception as DBALException; -use Doctrine\DBAL\Types\Type; use Illuminate\Console\Command; use Illuminate\Contracts\Database\Eloquent\Castable; use Illuminate\Contracts\Database\Eloquent\CastsAttributes; use Illuminate\Contracts\Database\Eloquent\CastsInboundAttributes; +use Illuminate\Database\Eloquent\Casts\AsArrayObject; +use Illuminate\Database\Eloquent\Casts\AsCollection; use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Model; @@ -38,7 +38,9 @@ use Illuminate\Database\Eloquent\Relations\MorphOne; use Illuminate\Database\Eloquent\Relations\MorphTo; use Illuminate\Database\Eloquent\Relations\MorphToMany; use Illuminate\Database\Eloquent\Relations\Relation; +use Illuminate\Database\Schema\Builder; use Illuminate\Filesystem\Filesystem; +use Illuminate\Support\Arr; use Illuminate\Support\Collection; use Illuminate\Support\Str; use phpDocumentor\Reflection\Types\ContextFactory; @@ -104,7 +106,6 @@ class ModelsCommand extends Command protected $write_mixin = false; protected $dirs = []; protected $reset; - protected $keep_text; protected $phpstorm_noinspections; protected $write_model_external_builder_methods; /** @@ -152,9 +153,6 @@ class ModelsCommand extends Command $ignore = $this->option('ignore'); $this->reset = $this->option('reset'); $this->phpstorm_noinspections = $this->option('phpstorm-noinspections'); - if ($this->option('smart-reset')) { - $this->keep_text = $this->reset = true; - } $this->write_model_magic_where = $this->laravel['config']->get('ide-helper.write_model_magic_where', true); $this->write_model_external_builder_methods = $this->laravel['config']->get('ide-helper.write_model_external_builder_methods', true); $this->write_model_relation_count_properties = @@ -211,7 +209,7 @@ class ModelsCommand extends Command return [ ['filename', 'F', InputOption::VALUE_OPTIONAL, 'The path to the helper file'], ['dir', 'D', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, - 'The model dir, supports glob patterns', [],], + 'The model dir, supports glob patterns', [], ], ['write', 'W', InputOption::VALUE_NONE, 'Write to Model file'], ['write-mixin', 'M', InputOption::VALUE_NONE, "Write models to {$this->filename} and adds @mixin to each model, avoiding IDE duplicate declaration warnings", @@ -242,8 +240,6 @@ class ModelsCommand extends Command */ \n\n"; - $hasDoctrine = interface_exists('Doctrine\DBAL\Driver'); - if (empty($loadModels)) { $models = $this->loadModels(); } else { @@ -267,6 +263,7 @@ class ModelsCommand extends Command } $this->properties = []; $this->methods = []; + $this->foreignKeyConstraintsColumns = []; if (class_exists($name)) { try { // handle abstract classes, interfaces, ... @@ -285,9 +282,7 @@ class ModelsCommand extends Command $model = $this->laravel->make($name); - if ($hasDoctrine) { - $this->getPropertiesFromTable($model); - } + $this->getPropertiesFromTable($model); if (method_exists($model, 'getCasts')) { $this->castPropertiesType($model); @@ -311,13 +306,6 @@ class ModelsCommand extends Command } } - if (!$hasDoctrine) { - $this->error( - 'Warning: `"doctrine/dbal": "~2.3"` is required to load database information. ' . - 'Please require that in your composer.json and run `composer update`.' - ); - } - return $output; } @@ -355,7 +343,7 @@ class ModelsCommand extends Command /** * cast the properties's type from $casts. * - * @param \Illuminate\Database\Eloquent\Model $model + * @param Model $model */ public function castPropertiesType($model) { @@ -387,7 +375,7 @@ class ModelsCommand extends Command break; case 'boolean': case 'bool': - $realType = 'boolean'; + $realType = 'bool'; break; case 'decimal': case 'string': @@ -403,7 +391,7 @@ class ModelsCommand extends Command case 'int': case 'integer': case 'timestamp': - $realType = 'integer'; + $realType = 'int'; break; case 'real': case 'double': @@ -418,9 +406,13 @@ class ModelsCommand extends Command case 'immutable_datetime': $realType = '\Carbon\CarbonImmutable'; break; + case AsCollection::class: case 'collection': $realType = '\Illuminate\Support\Collection'; break; + case AsArrayObject::class: + $realType = '\ArrayObject'; + break; default: // In case of an optional custom cast parameter , only evaluate // the `$type` until the `:` @@ -499,33 +491,16 @@ class ModelsCommand extends Command /** * Load the properties from the database table. * - * @param \Illuminate\Database\Eloquent\Model $model + * @param Model $model * - * @throws DBALException If custom field failed to register */ public function getPropertiesFromTable($model) { - $database = $model->getConnection()->getDatabaseName(); - $table = $model->getConnection()->getTablePrefix() . $model->getTable(); - $schema = $model->getConnection()->getDoctrineSchemaManager(); - $databasePlatform = $schema->getDatabasePlatform(); - $databasePlatform->registerDoctrineTypeMapping('enum', 'string'); + $table = $model->getTable(); + $schema = $model->getConnection()->getSchemaBuilder(); + $columns = $schema->getColumns($table); + $driverName = $model->getConnection()->getDriverName(); - $platformName = $databasePlatform->getName(); - $customTypes = $this->laravel['config']->get("ide-helper.custom_db_types.{$platformName}", []); - foreach ($customTypes as $yourTypeName => $doctrineTypeName) { - try { - if (!Type::hasType($yourTypeName)) { - Type::addType($yourTypeName, get_class(Type::getType($doctrineTypeName))); - } - } catch (DBALException $exception) { - $this->error("Failed registering custom db type \"$yourTypeName\" as \"$doctrineTypeName\""); - throw $exception; - } - $databasePlatform->registerDoctrineTypeMapping($yourTypeName, $doctrineTypeName); - } - - $columns = $schema->listTableColumns($table, $database); if (!$columns) { return; @@ -533,49 +508,28 @@ class ModelsCommand extends Command $this->setForeignKeys($schema, $table); foreach ($columns as $column) { - $name = $column->getName(); + $name = $column['name']; if (in_array($name, $model->getDates())) { $type = $this->dateClass; } else { - $type = $column->getType()->getName(); - switch ($type) { - case 'string': - case 'text': - case 'date': - case 'time': - case 'guid': - case 'datetimetz': - case 'datetime': - case 'decimal': - $type = 'string'; - break; - case 'integer': - case 'bigint': - case 'smallint': - $type = 'integer'; - break; - case 'boolean': - switch ($platformName) { - case 'sqlite': - case 'mysql': - $type = 'integer'; - break; - default: - $type = 'boolean'; - break; - } - break; - case 'float': - $type = 'float'; - break; - default: - $type = 'mixed'; - break; - } + // Match types to php equivalent + $type = match ($column['type_name']) { + 'tinyint', 'bit', + 'integer', 'int', 'int4', + 'smallint', 'int2', + 'mediumint', + 'bigint', 'int8' => 'int', + + 'boolean', 'bool' => 'bool', + + 'float', 'real', 'float4', + 'double', 'float8' => 'float', + + default => 'string', + }; } - $comment = $column->getComment(); - if (!$column->getNotnull()) { + if ($column['nullable']) { $this->nullableColumns[$name] = true; } $this->setProperty( @@ -583,8 +537,8 @@ class ModelsCommand extends Command $this->getTypeInModel($model, $type), true, true, - $comment, - !$column->getNotnull() + $column['comment'], + $column['nullable'] ); if ($this->write_model_magic_where) { $builderClass = $this->write_model_external_builder_methods @@ -603,7 +557,7 @@ class ModelsCommand extends Command } /** - * @param \Illuminate\Database\Eloquent\Model $model + * @param Model $model */ public function getPropertiesFromMethods($model) { @@ -614,10 +568,7 @@ class ModelsCommand extends Command // methods that resemble mutators but aren't. $reflections = array_filter($reflections, function (\ReflectionMethod $methodReflection) { return !$methodReflection->isPrivate() && !( - in_array( - \Illuminate\Database\Eloquent\Concerns\HasAttributes::class, - $methodReflection->getDeclaringClass()->getTraitNames() - ) && ( + $methodReflection->getDeclaringClass()->getName() === Model::class && ( $methodReflection->getName() === 'setClassCastableAttribute' || $methodReflection->getName() === 'setEnumCastableAttribute' ) @@ -643,18 +594,15 @@ class ModelsCommand extends Command $this->setProperty($name, $type, true, null, $comment); } } elseif ($isAttribute) { - $name = Str::snake($method); - $types = $this->getAttributeReturnType($model, $reflection); - $comment = $this->getCommentFromDocBlock($reflection); - - if ($types->has('get')) { - $type = $this->getTypeInModel($model, $types['get']); - $this->setProperty($name, $type, true, null, $comment); - } - - if ($types->has('set')) { - $this->setProperty($name, null, null, true, $comment); - } + $types = $this->getAttributeTypes($model, $reflection); + $type = $this->getTypeInModel($model, $types->get('get') ?: $types->get('set')) ?: null; + $this->setProperty( + Str::snake($method), + $type, + $types->has('get'), + $types->has('set'), + $this->getCommentFromDocBlock($reflection) + ); } elseif ( Str::startsWith($method, 'set') && Str::endsWith( $method, @@ -667,7 +615,7 @@ class ModelsCommand extends Command $comment = $this->getCommentFromDocBlock($reflection); $this->setProperty($name, null, null, true, $comment); } - } elseif (Str::startsWith($method, 'scope') && $method !== 'scopeQuery') { + } elseif (Str::startsWith($method, 'scope') && $method !== 'scopeQuery' && $method !== 'scope' && $method !== 'scopes') { //Magic setAttribute $name = Str::camel(substr($method, 5)); if (!empty($name)) { @@ -753,9 +701,14 @@ class ModelsCommand extends Command get_class($relationObj->getRelated()) ); + $relationReturnType = $this->getRelationReturnTypes()[$relation] ?? false; + if ( - strpos(get_class($relationObj), 'Many') !== false || - ($this->getRelationReturnTypes()[$relation] ?? '') === 'many' + $relationReturnType === 'many' || + ( + !$relationReturnType && + strpos(get_class($relationObj), 'Many') !== false + ) ) { //Collection or array of models (because Collection is Arrayable) $relatedClass = '\\' . get_class($relationObj->getRelated()); @@ -778,12 +731,15 @@ class ModelsCommand extends Command 'int|null', true, false - // What kind of comments should be added to the relation count here? + // What kind of comments should be added to the relation count here? ); } } elseif ( - $relation === 'morphTo' || - ($this->getRelationReturnTypes()[$relation] ?? '') === 'morphTo' + $relationReturnType === 'morphTo' || + ( + !$relationReturnType && + $relation === 'morphTo' + ) ) { // Model isn't specified because relation is polymorphic $this->setProperty( @@ -838,12 +794,17 @@ class ModelsCommand extends Command $fkProp = $reflectionObj->getProperty('foreignKey'); $fkProp->setAccessible(true); - if ($relation === 'belongsTo') { - return isset($this->nullableColumns[$fkProp->getValue($relationObj)]) || - !in_array($fkProp->getValue($relationObj), $this->foreignKeyConstraintsColumns, true); + foreach (Arr::wrap($fkProp->getValue($relationObj)) as $foreignKey) { + if (isset($this->nullableColumns[$foreignKey])) { + return true; + } + + if (!in_array($foreignKey, $this->foreignKeyConstraintsColumns, true)) { + return true; + } } - return isset($this->nullableColumns[$fkProp->getValue($relationObj)]); + return false; } /** @@ -892,7 +853,12 @@ class ModelsCommand extends Command public function unsetMethod($name) { - unset($this->methods[strtolower($name)]); + foreach ($this->methods as $k => $v) { + if (strtolower($k) === strtolower($name)) { + unset($this->methods[$k]); + return; + } + } } public function getMethodType(Model $model, string $classType) @@ -920,19 +886,13 @@ class ModelsCommand extends Command if ($this->reset) { $phpdoc = new DocBlock('', new Context($namespace)); - if ($this->keep_text) { - $phpdoc->setText( - (new DocBlock($reflection, new Context($namespace)))->getText() - ); - } + $phpdoc->setText( + (new DocBlock($reflection, new Context($namespace)))->getText() + ); } else { $phpdoc = new DocBlock($reflection, new Context($namespace)); } - if (!$phpdoc->getText()) { - $phpdoc->setText($class); - } - $properties = []; $methods = []; foreach ($phpdoc->getTags() as $tag) { @@ -1059,9 +1019,9 @@ class ModelsCommand extends Command $classname = $this->write_mixin ? $mixinClassName : $classname; $allowDynamicAttributes = $this->write_mixin ? "#[\AllowDynamicProperties]\n\t" : ''; - $output = "namespace {$namespace}{\n{$docComment}\n\t{$keyword}{$allowDynamicAttributes}class {$classname} "; + $output = "namespace {$namespace}{\n{$docComment}\n\t{$allowDynamicAttributes}{$keyword}class {$classname} "; - if (! $this->write_mixin) { + if (!$this->write_mixin) { $output .= "extends \Eloquent "; if ($interfaceNames) { @@ -1102,6 +1062,8 @@ class ModelsCommand extends Command $default = 'null'; } elseif (is_int($default)) { //$default = $default; + } elseif ($default instanceof \UnitEnum) { + $default = '\\' . get_class($default) . '::' . $default->name; } else { $default = "'" . trim($default) . "'"; } @@ -1129,7 +1091,7 @@ class ModelsCommand extends Command return '\Illuminate\Database\Eloquent\Collection'; } - /** @var \Illuminate\Database\Eloquent\Model $model */ + /** @var Model $model */ $model = new $className(); return '\\' . get_class($model->newCollection()); } @@ -1176,7 +1138,10 @@ class ModelsCommand extends Command return $this->laravel['config']->get('ide-helper.model_camel_case_properties', false); } - protected function getAttributeReturnType(Model $model, \ReflectionMethod $reflectionMethod): Collection + /** + * @psalm-suppress NoValue + */ + protected function getAttributeTypes(Model $model, \ReflectionMethod $reflectionMethod): Collection { // Private/protected ReflectionMethods require setAccessible prior to PHP 8.1 $reflectionMethod->setAccessible(true); @@ -1184,13 +1149,25 @@ class ModelsCommand extends Command /** @var Attribute $attribute */ $attribute = $reflectionMethod->invoke($model); - return collect([ - 'get' => $attribute->get ? optional(new \ReflectionFunction($attribute->get))->getReturnType() : null, - 'set' => $attribute->set ? optional(new \ReflectionFunction($attribute->set))->getReturnType() : null, - ]) - ->filter() + $methods = new Collection(); + + if ($attribute->get) { + $methods['get'] = optional(new \ReflectionFunction($attribute->get))->getReturnType(); + } + if ($attribute->set) { + $function = optional(new \ReflectionFunction($attribute->set)); + if ($function->getNumberOfParameters() === 0) { + $methods['set'] = null; + } else { + $methods['set'] = $function->getParameters()[0]->getType(); + } + } + + return $methods ->map(function ($type) { - if ($type instanceof \ReflectionUnionType) { + if ($type === null) { + $types = collect([]); + } elseif ($type instanceof \ReflectionUnionType) { $types = collect($type->getTypes()) /** @var ReflectionType $reflectionType */ ->map(function ($reflectionType) { @@ -1201,7 +1178,7 @@ class ModelsCommand extends Command $types = collect($this->extractReflectionTypes($type)); } - if ($type->allowsNull()) { + if ($type && $type->allowsNull()) { $types->push('null'); } @@ -1295,7 +1272,7 @@ class ModelsCommand extends Command /** * Generates methods provided by the SoftDeletes trait - * @param \Illuminate\Database\Eloquent\Model $model + * @param Model $model */ protected function getSoftDeleteMethods($model) { @@ -1312,7 +1289,7 @@ class ModelsCommand extends Command /** * Generate factory method from "HasFactory" trait. * - * @param \Illuminate\Database\Eloquent\Model $model + * @param Model $model */ protected function getFactoryMethods($model) { @@ -1340,16 +1317,12 @@ class ModelsCommand extends Command return; } - if (version_compare($this->laravel->version(), '9', '>=')) { - $this->setMethod('factory', $factory, ['$count = null, $state = []']); - } else { - $this->setMethod('factory', $factory, ['...$parameters']); - } + $this->setMethod('factory', $factory, ['$count = null, $state = []']); } /** * Generates methods that return collections - * @param \Illuminate\Database\Eloquent\Model $model + * @param Model $model */ protected function getCollectionMethods($model) { @@ -1392,7 +1365,7 @@ class ModelsCommand extends Command return $type; } - $reflection = new \ReflectionClass($type); + $reflection = new ReflectionClass($type); if (!$reflection->implementsInterface(Castable::class)) { return $type; @@ -1424,7 +1397,7 @@ class ModelsCommand extends Command return $type; } - $reflection = new \ReflectionClass($type); + $reflection = new ReflectionClass($type); if (!$reflection->implementsInterface(CastsAttributes::class)) { return $type; @@ -1462,8 +1435,7 @@ class ModelsCommand extends Command { $reflection = $model instanceof ReflectionClass ? $model - : new ReflectionObject($model) - ; + : new ReflectionObject($model); $className = trim($className, '\\'); $writingToExternalFile = !$this->write || $this->write_mixin; @@ -1630,7 +1602,7 @@ class ModelsCommand extends Command } /** - * @param \Illuminate\Database\Eloquent\Model $model + * @param Model $model * @throws \Illuminate\Contracts\Container\BindingResolutionException * @throws \RuntimeException */ @@ -1652,14 +1624,13 @@ class ModelsCommand extends Command } /** - * @param \Doctrine\DBAL\Schema\AbstractSchemaManager $schema + * @param Builder $schema * @param string $table - * @throws DBALException */ protected function setForeignKeys($schema, $table) { - foreach ($schema->listTableForeignKeys($table) as $foreignKeyConstraint) { - foreach ($foreignKeyConstraint->getLocalColumns() as $columnName) { + foreach ($schema->getForeignKeys($table) as $foreignKeyConstraint) { + foreach ($foreignKeyConstraint['columns'] as $columnName) { $this->foreignKeyConstraintsColumns[] = $columnName; } } diff --git a/src/Generator.php b/src/Generator.php index 61417e2..a509958 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -13,8 +13,13 @@ namespace Barryvdh\LaravelIdeHelper; use Illuminate\Foundation\AliasLoader; use Illuminate\Support\Collection; +use Illuminate\Support\Facades\Facade; use Illuminate\Support\Str; use Illuminate\Support\Traits\Macroable; +use PhpParser\Lexer\Emulative; +use PhpParser\Node\Stmt\Class_; +use PhpParser\Node\Stmt\Namespace_; +use PhpParser\Parser\Php7; use ReflectionClass; use Symfony\Component\Console\Output\OutputInterface; @@ -26,7 +31,7 @@ class Generator /** @var \Illuminate\View\Factory */ protected $view; - /** @var \Symfony\Component\Console\Output\OutputInterface */ + /** @var OutputInterface */ protected $output; protected $extra = []; @@ -37,7 +42,7 @@ class Generator /** * @param \Illuminate\Config\Repository $config * @param \Illuminate\View\Factory $view - * @param \Symfony\Component\Console\Output\OutputInterface $output + * @param OutputInterface $output * @param string $helpers */ public function __construct( @@ -75,6 +80,7 @@ class Generator return $this->view->make('helper') ->with('namespaces_by_extends_ns', $this->getAliasesByExtendsNamespace()) ->with('namespaces_by_alias_ns', $this->getAliasesByAliasNamespace()) + ->with('real_time_facades', $this->getRealTimeFacades()) ->with('helpers', $this->helpers) ->with('version', $app->version()) ->with('include_fluent', $this->config->get('ide-helper.include_fluent', true)) @@ -153,6 +159,11 @@ class Generator continue; } + // Skip the swoole + if ($facade == 'SwooleTW\Http\Server\Facades\Server' && $name == 'Server' && !class_exists('Swoole\Http\Server')) { + continue; + } + $magicMethods = array_key_exists($name, $this->magic) ? $this->magic[$name] : []; $alias = new Alias($this->config, $name, $facade, $magicMethods, $this->interfaces); if ($alias->isValid()) { @@ -168,6 +179,51 @@ class Generator return $aliases; } + protected function getRealTimeFacades() + { + $facades = []; + $realTimeFacadeFiles = glob(storage_path('framework/cache/facade-*.php')); + foreach ($realTimeFacadeFiles as $file) { + try { + $name = $this->getFullyQualifiedClassNameInFile($file); + $facades[$name] = $name; + } catch (\Exception $e) { + continue; + } + } + + return $facades; + } + + protected function getFullyQualifiedClassNameInFile(string $path) + { + $contents = file_get_contents($path); + + $parsers = new Php7(new Emulative()); + + $parsed = collect($parsers->parse($contents) ?: []); + + $namespace = $parsed->first(function ($node) { + return $node instanceof Namespace_; + }); + + if ($namespace) { + $name = $namespace->name->toString(); + + $class = collect($namespace->stmts)->first(function ($node) { + return $node instanceof Class_; + }); + + if ($class) { + $name .= '\\' . $class->name->toString(); + } + + return $name; + } + } + + + /** * Regroup aliases by namespace of extended classes * @@ -175,7 +231,9 @@ class Generator */ protected function getAliasesByExtendsNamespace() { - $aliases = $this->getValidAliases(); + $aliases = $this->getValidAliases()->filter(static function (Alias $alias) { + return is_subclass_of($alias->getExtends(), Facade::class); + }); $this->addMacroableClasses($aliases); diff --git a/src/Listeners/GenerateModelHelper.php b/src/Listeners/GenerateModelHelper.php index 86e2bd4..c448aef 100644 --- a/src/Listeners/GenerateModelHelper.php +++ b/src/Listeners/GenerateModelHelper.php @@ -16,15 +16,15 @@ class GenerateModelHelper */ public static $shouldRun = false; - /** @var \Illuminate\Contracts\Console\Kernel */ + /** @var Artisan */ protected $artisan; - /** @var \Illuminate\Contracts\Config\Repository */ + /** @var Config */ protected $config; /** - * @param \Illuminate\Contracts\Console\Kernel $artisan - * @param \Illuminate\Contracts\Config\Repository $config + * @param Artisan $artisan + * @param Config $config */ public function __construct(Artisan $artisan, Config $config) { diff --git a/src/Method.php b/src/Method.php index f7f7ffa..a46e3f2 100644 --- a/src/Method.php +++ b/src/Method.php @@ -22,7 +22,7 @@ use Illuminate\Support\Str; class Method { - /** @var \Barryvdh\Reflection\DocBlock */ + /** @var DocBlock */ protected $phpdoc; /** @var \ReflectionMethod */ diff --git a/src/UsesResolver.php b/src/UsesResolver.php index 205da9c..4900a12 100644 --- a/src/UsesResolver.php +++ b/src/UsesResolver.php @@ -64,7 +64,7 @@ class UsesResolver '\\' ); - $parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7); + $parser = (new ParserFactory())->createForHostVersion(); $namespaceData = null; foreach ($parser->parse($code) as $node) { diff --git a/tests/Console/ModelsCommand/AdvancedCasts/Models/AdvancedCast.php b/tests/Console/ModelsCommand/AdvancedCasts/Models/AdvancedCast.php new file mode 100644 index 0000000..4613056 --- /dev/null +++ b/tests/Console/ModelsCommand/AdvancedCasts/Models/AdvancedCast.php @@ -0,0 +1,29 @@ + 'date:Y-m-d', + 'cast_to_datetime_serialization' => 'datetime:Y-m-d H:i:s', + 'cast_to_custom_datetime' => 'custom_datetime:Y-m-d H:i:s', + 'cast_to_immutable_date' => 'immutable_date', + 'cast_to_immutable_custom_datetime' => 'immutable_custom_datetime:Y-m-d H:i:s', + 'cast_to_immutable_datetime' => 'immutable_datetime', + 'cast_to_timestamp' => 'timestamp', + 'cast_to_encrypted' => 'encrypted', + 'cast_to_encrypted_array' => 'encrypted:array', + 'cast_to_encrypted_collection' => 'encrypted:collection', + 'cast_to_encrypted_json' => 'encrypted:json', + 'cast_to_encrypted_object' => 'encrypted:object', + 'cast_to_as_collection' => AsCollection::class, + 'cast_to_as_array_object' => AsArrayObject::class, + ]; +} diff --git a/tests/Console/ModelsCommand/AdvancedCasts/Test.php b/tests/Console/ModelsCommand/AdvancedCasts/Test.php new file mode 100644 index 0000000..7e46e26 --- /dev/null +++ b/tests/Console/ModelsCommand/AdvancedCasts/Test.php @@ -0,0 +1,24 @@ +app->make(ModelsCommand::class); + + $tester = $this->runCommand($command, [ + '--write' => true, + ]); + + $this->assertSame(0, $tester->getStatusCode()); + $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); + $this->assertMatchesMockedSnapshot(); + } +} diff --git a/tests/Console/ModelsCommand/AdvancedCasts/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/AdvancedCasts/__snapshots__/Test__test__1.php new file mode 100644 index 0000000..2c29482 --- /dev/null +++ b/tests/Console/ModelsCommand/AdvancedCasts/__snapshots__/Test__test__1.php @@ -0,0 +1,65 @@ + 'date:Y-m-d', + 'cast_to_datetime_serialization' => 'datetime:Y-m-d H:i:s', + 'cast_to_custom_datetime' => 'custom_datetime:Y-m-d H:i:s', + 'cast_to_immutable_date' => 'immutable_date', + 'cast_to_immutable_custom_datetime' => 'immutable_custom_datetime:Y-m-d H:i:s', + 'cast_to_immutable_datetime' => 'immutable_datetime', + 'cast_to_timestamp' => 'timestamp', + 'cast_to_encrypted' => 'encrypted', + 'cast_to_encrypted_array' => 'encrypted:array', + 'cast_to_encrypted_collection' => 'encrypted:collection', + 'cast_to_encrypted_json' => 'encrypted:json', + 'cast_to_encrypted_object' => 'encrypted:object', + 'cast_to_as_collection' => AsCollection::class, + 'cast_to_as_array_object' => AsArrayObject::class, + ]; +} diff --git a/tests/Console/ModelsCommand/AllowGlobDirectory/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/AllowGlobDirectory/__snapshots__/Test__test__1.php index c34f0a8..725a26b 100644 --- a/tests/Console/ModelsCommand/AllowGlobDirectory/__snapshots__/Test__test__1.php +++ b/tests/Console/ModelsCommand/AllowGlobDirectory/__snapshots__/Test__test__1.php @@ -7,9 +7,9 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AllowGlobDirecto use Illuminate\Database\Eloquent\Model; /** - * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AllowGlobDirectory\Services\Post\Models\Post + * * - * @property integer $id + * @property int $id * @property string|null $char_nullable * @property string $char_not_nullable * @property string|null $string_nullable @@ -20,36 +20,34 @@ use Illuminate\Database\Eloquent\Model; * @property string $medium_text_not_nullable * @property string|null $long_text_nullable * @property string $long_text_not_nullable - * @property integer|null $integer_nullable - * @property integer $integer_not_nullable - * @property integer|null $tiny_integer_nullable - * @property integer $tiny_integer_not_nullable - * @property integer|null $small_integer_nullable - * @property integer $small_integer_not_nullable - * @property integer|null $medium_integer_nullable - * @property integer $medium_integer_not_nullable - * @property integer|null $big_integer_nullable - * @property integer $big_integer_not_nullable - * @property integer|null $unsigned_integer_nullable - * @property integer $unsigned_integer_not_nullable - * @property integer|null $unsigned_tiny_integer_nullable - * @property integer $unsigned_tiny_integer_not_nullable - * @property integer|null $unsigned_small_integer_nullable - * @property integer $unsigned_small_integer_not_nullable - * @property integer|null $unsigned_medium_integer_nullable - * @property integer $unsigned_medium_integer_not_nullable - * @property integer|null $unsigned_big_integer_nullable - * @property integer $unsigned_big_integer_not_nullable + * @property int|null $integer_nullable + * @property int $integer_not_nullable + * @property int|null $tiny_integer_nullable + * @property int $tiny_integer_not_nullable + * @property int|null $small_integer_nullable + * @property int $small_integer_not_nullable + * @property int|null $medium_integer_nullable + * @property int $medium_integer_not_nullable + * @property int|null $big_integer_nullable + * @property int $big_integer_not_nullable + * @property int|null $unsigned_integer_nullable + * @property int $unsigned_integer_not_nullable + * @property int|null $unsigned_tiny_integer_nullable + * @property int $unsigned_tiny_integer_not_nullable + * @property int|null $unsigned_small_integer_nullable + * @property int $unsigned_small_integer_not_nullable + * @property int|null $unsigned_medium_integer_nullable + * @property int $unsigned_medium_integer_not_nullable + * @property int|null $unsigned_big_integer_nullable + * @property int $unsigned_big_integer_not_nullable * @property float|null $float_nullable * @property float $float_not_nullable * @property float|null $double_nullable * @property float $double_not_nullable * @property string|null $decimal_nullable * @property string $decimal_not_nullable - * @property string|null $unsigned_decimal_nullable - * @property string $unsigned_decimal_not_nullable - * @property integer|null $boolean_nullable - * @property integer $boolean_not_nullable + * @property int|null $boolean_nullable + * @property int $boolean_not_nullable * @property string|null $enum_nullable * @property string $enum_not_nullable * @property string|null $json_nullable @@ -70,10 +68,10 @@ use Illuminate\Database\Eloquent\Model; * @property string $timestamp_not_nullable * @property string|null $timestamptz_nullable * @property string $timestamptz_not_nullable - * @property integer|null $year_nullable - * @property integer $year_not_nullable - * @property mixed|null $binary_nullable - * @property mixed $binary_not_nullable + * @property int|null $year_nullable + * @property int $year_not_nullable + * @property string|null $binary_nullable + * @property string $binary_not_nullable * @property string|null $uuid_nullable * @property string $uuid_not_nullable * @property string|null $ipaddress_nullable @@ -143,8 +141,6 @@ use Illuminate\Database\Eloquent\Model; * @method static \Illuminate\Database\Eloquent\Builder|Post whereTinyIntegerNullable($value) * @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedBigIntegerNotNullable($value) * @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedBigIntegerNullable($value) - * @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedDecimalNotNullable($value) - * @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedDecimalNullable($value) * @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedIntegerNotNullable($value) * @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedIntegerNullable($value) * @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedMediumIntegerNotNullable($value) diff --git a/tests/Console/ModelsCommand/ArrayCastsWithComment/Models/ArrayCastsWithComment.php b/tests/Console/ModelsCommand/ArrayCastsWithComment/Models/ArrayCastsWithComment.php new file mode 100644 index 0000000..b6bb6ed --- /dev/null +++ b/tests/Console/ModelsCommand/ArrayCastsWithComment/Models/ArrayCastsWithComment.php @@ -0,0 +1,43 @@ +|null $cast_to_array -- These three should not be duplicated + * @property array $cast_to_json some-description + * @property \Illuminate\Support\Collection $cast_to_collection some-description + * + * @property array|null $cast_to_encrypted_array -- These three are OK (no types) + * @property array $cast_to_encrypted_json some-description + * @property \Illuminate\Support\Collection $cast_to_encrypted_collection some-description + * + * @property string $cast_to_string -- The next three are OK (no description), this not included + * + * @property array|null $cast_to_immutable_date + * @property array $cast_to_immutable_date_serialization + * @property \Illuminate\Support\Collection $cast_to_immutable_custom_datetime + */ +class ArrayCastsWithComment extends Model +{ + protected $table = 'simple_casts'; + + protected $casts = [ + 'cast_to_array' => 'array', + 'cast_to_json' => 'json', + 'cast_to_collection' => 'collection', + + 'cast_to_encrypted_array' => 'array', + 'cast_to_encrypted_json' => 'json', + 'cast_to_encrypted_collection' => 'collection', + + 'cast_to_string' => 'string', + + 'cast_to_immutable_date' => 'array', + 'cast_to_immutable_date_serialization' => 'json', + 'cast_to_immutable_custom_datetime' => 'collection', + ]; +} diff --git a/tests/Console/ModelsCommand/ArrayCastsWithComment/Test.php b/tests/Console/ModelsCommand/ArrayCastsWithComment/Test.php new file mode 100644 index 0000000..a0be02e --- /dev/null +++ b/tests/Console/ModelsCommand/ArrayCastsWithComment/Test.php @@ -0,0 +1,28 @@ +app->make(ModelsCommand::class); + + $tester = $this->runCommand($command, [ + '--write' => true, + ]); + + $this->assertSame(0, $tester->getStatusCode()); + $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); + $this->assertMatchesMockedSnapshot(); + } +} diff --git a/tests/Console/ModelsCommand/ArrayCastsWithComment/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/ArrayCastsWithComment/__snapshots__/Test__test__1.php new file mode 100644 index 0000000..f4eaf6a --- /dev/null +++ b/tests/Console/ModelsCommand/ArrayCastsWithComment/__snapshots__/Test__test__1.php @@ -0,0 +1,97 @@ +|null $cast_to_array -- These three should not be duplicated + * @property array $cast_to_json some-description + * @property \Illuminate\Support\Collection $cast_to_collection some-description + * @property array|null $cast_to_encrypted_array -- These three are OK (no types) + * @property array $cast_to_encrypted_json some-description + * @property \Illuminate\Support\Collection $cast_to_encrypted_collection some-description + * @property string $cast_to_string -- The next three are OK (no description), this not included + * @property array|null $cast_to_immutable_date + * @property array $cast_to_immutable_date_serialization + * @property \Illuminate\Support\Collection $cast_to_immutable_custom_datetime + * @property string $cast_to_int + * @property string $cast_to_integer + * @property string $cast_to_real + * @property string $cast_to_float + * @property string $cast_to_double + * @property string $cast_to_decimal + * @property string $cast_to_bool + * @property string $cast_to_boolean + * @property string $cast_to_object + * @property array $cast_to_array + * @property array $cast_to_json + * @property \Illuminate\Support\Collection $cast_to_collection + * @property string $cast_to_date + * @property string $cast_to_datetime + * @property string $cast_to_date_serialization + * @property string $cast_to_datetime_serialization + * @property string $cast_to_custom_datetime + * @property string $cast_to_immutable_datetime + * @property string $cast_to_immutable_datetime_serialization + * @property string $cast_to_timestamp + * @property string $cast_to_encrypted + * @property string $cast_to_encrypted_object + * @method static \Illuminate\Database\Eloquent\Builder|ArrayCastsWithComment newModelQuery() + * @method static \Illuminate\Database\Eloquent\Builder|ArrayCastsWithComment newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|ArrayCastsWithComment query() + * @method static \Illuminate\Database\Eloquent\Builder|ArrayCastsWithComment whereCastToArray($value) + * @method static \Illuminate\Database\Eloquent\Builder|ArrayCastsWithComment whereCastToBool($value) + * @method static \Illuminate\Database\Eloquent\Builder|ArrayCastsWithComment whereCastToBoolean($value) + * @method static \Illuminate\Database\Eloquent\Builder|ArrayCastsWithComment whereCastToCollection($value) + * @method static \Illuminate\Database\Eloquent\Builder|ArrayCastsWithComment whereCastToCustomDatetime($value) + * @method static \Illuminate\Database\Eloquent\Builder|ArrayCastsWithComment whereCastToDate($value) + * @method static \Illuminate\Database\Eloquent\Builder|ArrayCastsWithComment whereCastToDateSerialization($value) + * @method static \Illuminate\Database\Eloquent\Builder|ArrayCastsWithComment whereCastToDatetime($value) + * @method static \Illuminate\Database\Eloquent\Builder|ArrayCastsWithComment whereCastToDatetimeSerialization($value) + * @method static \Illuminate\Database\Eloquent\Builder|ArrayCastsWithComment whereCastToDecimal($value) + * @method static \Illuminate\Database\Eloquent\Builder|ArrayCastsWithComment whereCastToDouble($value) + * @method static \Illuminate\Database\Eloquent\Builder|ArrayCastsWithComment whereCastToEncrypted($value) + * @method static \Illuminate\Database\Eloquent\Builder|ArrayCastsWithComment whereCastToEncryptedArray($value) + * @method static \Illuminate\Database\Eloquent\Builder|ArrayCastsWithComment whereCastToEncryptedCollection($value) + * @method static \Illuminate\Database\Eloquent\Builder|ArrayCastsWithComment whereCastToEncryptedJson($value) + * @method static \Illuminate\Database\Eloquent\Builder|ArrayCastsWithComment whereCastToEncryptedObject($value) + * @method static \Illuminate\Database\Eloquent\Builder|ArrayCastsWithComment whereCastToFloat($value) + * @method static \Illuminate\Database\Eloquent\Builder|ArrayCastsWithComment whereCastToImmutableCustomDatetime($value) + * @method static \Illuminate\Database\Eloquent\Builder|ArrayCastsWithComment whereCastToImmutableDate($value) + * @method static \Illuminate\Database\Eloquent\Builder|ArrayCastsWithComment whereCastToImmutableDateSerialization($value) + * @method static \Illuminate\Database\Eloquent\Builder|ArrayCastsWithComment whereCastToImmutableDatetime($value) + * @method static \Illuminate\Database\Eloquent\Builder|ArrayCastsWithComment whereCastToImmutableDatetimeSerialization($value) + * @method static \Illuminate\Database\Eloquent\Builder|ArrayCastsWithComment whereCastToInt($value) + * @method static \Illuminate\Database\Eloquent\Builder|ArrayCastsWithComment whereCastToInteger($value) + * @method static \Illuminate\Database\Eloquent\Builder|ArrayCastsWithComment whereCastToJson($value) + * @method static \Illuminate\Database\Eloquent\Builder|ArrayCastsWithComment whereCastToObject($value) + * @method static \Illuminate\Database\Eloquent\Builder|ArrayCastsWithComment whereCastToReal($value) + * @method static \Illuminate\Database\Eloquent\Builder|ArrayCastsWithComment whereCastToString($value) + * @method static \Illuminate\Database\Eloquent\Builder|ArrayCastsWithComment whereCastToTimestamp($value) + * @mixin \Eloquent + */ +class ArrayCastsWithComment extends Model +{ + protected $table = 'simple_casts'; + + protected $casts = [ + 'cast_to_array' => 'array', + 'cast_to_json' => 'json', + 'cast_to_collection' => 'collection', + + 'cast_to_encrypted_array' => 'array', + 'cast_to_encrypted_json' => 'json', + 'cast_to_encrypted_collection' => 'collection', + + 'cast_to_string' => 'string', + + 'cast_to_immutable_date' => 'array', + 'cast_to_immutable_date_serialization' => 'json', + 'cast_to_immutable_custom_datetime' => 'collection', + ]; +} diff --git a/tests/Console/ModelsCommand/Attributes/Models/Simple.php b/tests/Console/ModelsCommand/Attributes/Models/Simple.php index f64861b..56d1c7f 100644 --- a/tests/Console/ModelsCommand/Attributes/Models/Simple.php +++ b/tests/Console/ModelsCommand/Attributes/Models/Simple.php @@ -9,6 +9,7 @@ use Illuminate\Database\Eloquent\Model; class Simple extends Model { + // With a backed property protected function name(): Attribute { return new Attribute( @@ -16,18 +17,91 @@ class Simple extends Model return $name; }, function (?string $name): ?string { - return $name === null ? null : ucfirst($name); + return $name; } ); } + // Without backed properties + + protected function typeHintedGetAndSet(): Attribute + { + return new Attribute( + function (): ?string { + return $this->name; + }, + function (?string $name) { + $this->name = $name; + } + ); + } + + protected function divergingTypeHintedGetAndSet(): Attribute + { + return new Attribute( + function (): int { + return strlen($this->name); + }, + function (?string $name) { + $this->name = $name; + } + ); + } + + protected function typeHintedGet(): Attribute + { + return Attribute::get(function (): ?string { + return $this->name; + }); + } + + protected function typeHintedSet(): Attribute + { + return Attribute::set(function (?string $name) { + $this->name = $name; + }); + } + + protected function nonTypeHintedGetAndSet(): Attribute + { + return new Attribute( + function () { + return $this->name; + }, + function ($name) { + $this->name = $name; + } + ); + } + + protected function nonTypeHintedGet(): Attribute + { + return Attribute::get(function () { + return $this->name; + }); + } + + protected function nonTypeHintedSet(): Attribute + { + return Attribute::set(function ($name) { + $this->name = $name; + }); + } + + protected function parameterlessSet(): Attribute + { + return Attribute::set(function () { + $this->name = null; + }); + } + /** * ide-helper does not recognize this method being an Attribute * because the method has no actual return type; * phpdoc is ignored here deliberately due to performance reasons and also * isn't supported by Laravel itself. * - * @return \Illuminate\Database\Eloquent\Casts\Attribute + * @return Attribute */ protected function notAnAttribute() { diff --git a/tests/Console/ModelsCommand/Attributes/Test.php b/tests/Console/ModelsCommand/Attributes/Test.php index 32bdbfd..15a5663 100644 --- a/tests/Console/ModelsCommand/Attributes/Test.php +++ b/tests/Console/ModelsCommand/Attributes/Test.php @@ -9,15 +9,6 @@ use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand; class Test extends AbstractModelsCommand { - protected function setUp(): void - { - parent::setUp(); - - if (!class_exists('\Illuminate\Database\Eloquent\Casts\Attribute')) { - $this->markTestSkipped('This test requires Laravel 8.77 or newer'); - } - } - public function test(): void { $command = $this->app->make(ModelsCommand::class); diff --git a/tests/Console/ModelsCommand/Attributes/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/Attributes/__snapshots__/Test__test__1.php index df68639..032a1c6 100644 --- a/tests/Console/ModelsCommand/Attributes/__snapshots__/Test__test__1.php +++ b/tests/Console/ModelsCommand/Attributes/__snapshots__/Test__test__1.php @@ -8,10 +8,18 @@ use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Model; /** - * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Attributes\Models\Simple + * * - * @property integer $id + * @property int $id + * @property int $diverging_type_hinted_get_and_set * @property string|null $name + * @property-read mixed $non_type_hinted_get + * @property mixed $non_type_hinted_get_and_set + * @property-write mixed $non_type_hinted_set + * @property-write mixed $parameterless_set + * @property-read string|null $type_hinted_get + * @property string|null $type_hinted_get_and_set + * @property-write string|null $type_hinted_set * @method static \Illuminate\Database\Eloquent\Builder|Simple newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Simple newQuery() * @method static \Illuminate\Database\Eloquent\Builder|Simple query() @@ -20,6 +28,7 @@ use Illuminate\Database\Eloquent\Model; */ class Simple extends Model { + // With a backed property protected function name(): Attribute { return new Attribute( @@ -27,18 +36,91 @@ class Simple extends Model return $name; }, function (?string $name): ?string { - return $name === null ? null : ucfirst($name); + return $name; } ); } + // Without backed properties + + protected function typeHintedGetAndSet(): Attribute + { + return new Attribute( + function (): ?string { + return $this->name; + }, + function (?string $name) { + $this->name = $name; + } + ); + } + + protected function divergingTypeHintedGetAndSet(): Attribute + { + return new Attribute( + function (): int { + return strlen($this->name); + }, + function (?string $name) { + $this->name = $name; + } + ); + } + + protected function typeHintedGet(): Attribute + { + return Attribute::get(function (): ?string { + return $this->name; + }); + } + + protected function typeHintedSet(): Attribute + { + return Attribute::set(function (?string $name) { + $this->name = $name; + }); + } + + protected function nonTypeHintedGetAndSet(): Attribute + { + return new Attribute( + function () { + return $this->name; + }, + function ($name) { + $this->name = $name; + } + ); + } + + protected function nonTypeHintedGet(): Attribute + { + return Attribute::get(function () { + return $this->name; + }); + } + + protected function nonTypeHintedSet(): Attribute + { + return Attribute::set(function ($name) { + $this->name = $name; + }); + } + + protected function parameterlessSet(): Attribute + { + return Attribute::set(function () { + $this->name = null; + }); + } + /** * ide-helper does not recognize this method being an Attribute * because the method has no actual return type; * phpdoc is ignored here deliberately due to performance reasons and also * isn't supported by Laravel itself. * - * @return \Illuminate\Database\Eloquent\Casts\Attribute + * @return Attribute */ protected function notAnAttribute() { diff --git a/tests/Console/ModelsCommand/Comment/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/Comment/__snapshots__/Test__test__1.php index c3c9686..fa5ab5d 100644 --- a/tests/Console/ModelsCommand/Comment/__snapshots__/Test__test__1.php +++ b/tests/Console/ModelsCommand/Comment/__snapshots__/Test__test__1.php @@ -10,9 +10,9 @@ use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\Relations\MorphTo; /** - * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Comment\Models\Simple + * * - * @property integer $id + * @property int $id * @property string $both_same_name I'm a getter * @property string $both_without_getter_comment * @property-read string $faker_comment diff --git a/tests/Console/ModelsCommand/CustomCollection/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/CustomCollection/__snapshots__/Test__test__1.php index 0b10768..057aa78 100644 --- a/tests/Console/ModelsCommand/CustomCollection/__snapshots__/Test__test__1.php +++ b/tests/Console/ModelsCommand/CustomCollection/__snapshots__/Test__test__1.php @@ -9,9 +9,9 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; /** - * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomCollection\Models\Simple + * * - * @property integer $id + * @property int $id * @property-read SimpleCollection $relationHasMany * @property-read int|null $relation_has_many_count * @method static SimpleCollection all($columns = ['*']) diff --git a/tests/Console/ModelsCommand/CustomDate/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/CustomDate/__snapshots__/Test__test__1.php index cd0e846..6d7fc4a 100644 --- a/tests/Console/ModelsCommand/CustomDate/__snapshots__/Test__test__1.php +++ b/tests/Console/ModelsCommand/CustomDate/__snapshots__/Test__test__1.php @@ -7,7 +7,7 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomDate\Model use Illuminate\Database\Eloquent\Model; /** - * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\CustomDate\Models\CustomDate + * * * @property \Carbon\CarbonImmutable|null $created_at * @property \Carbon\CarbonImmutable|null $updated_at diff --git a/tests/Console/ModelsCommand/CustomPhpdocTags/Models/Simple.php b/tests/Console/ModelsCommand/CustomPhpdocTags/Models/Simple.php new file mode 100644 index 0000000..368ad1c --- /dev/null +++ b/tests/Console/ModelsCommand/CustomPhpdocTags/Models/Simple.php @@ -0,0 +1,19 @@ +app->make(ModelsCommand::class); + + $tester = $this->runCommand($command, [ + '--write' => true, + ]); + + $this->assertSame(0, $tester->getStatusCode()); + $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); + $this->assertMatchesMockedSnapshot(); + } +} diff --git a/tests/Console/ModelsCommand/CustomPhpdocTags/__snapshots__/Test__testNoSpaceAfterCustomPhpdocTag__1.php b/tests/Console/ModelsCommand/CustomPhpdocTags/__snapshots__/Test__testNoSpaceAfterCustomPhpdocTag__1.php new file mode 100644 index 0000000..801f533 --- /dev/null +++ b/tests/Console/ModelsCommand/CustomPhpdocTags/__snapshots__/Test__testNoSpaceAfterCustomPhpdocTag__1.php @@ -0,0 +1,24 @@ + true, ]); - if (PHP_VERSION_ID >= 80000) { - $errors = [ - 'Error resolving relation model of Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models\Dynamic:dynamicBelongsTo() : Attempt to read property "created_at" on null', - 'Error resolving relation model of Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models\Dynamic:dynamicHasMany() : Attempt to read property "created_at" on null', - 'Error resolving relation model of Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models\Dynamic:dynamicHasOne() : Attempt to read property "created_at" on null', - ]; - } else { - $errors = [ - "Error resolving relation model of Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models\Dynamic:dynamicBelongsTo() : Trying to get property 'created_at' of non-object", - "Error resolving relation model of Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models\Dynamic:dynamicHasMany() : Trying to get property 'created_at' of non-object", - "Error resolving relation model of Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models\Dynamic:dynamicHasOne() : Trying to get property 'created_at' of non-object", - ]; - } + $errors = [ + 'Error resolving relation model of Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models\Dynamic:dynamicBelongsTo() : Attempt to read property "created_at" on null', + 'Error resolving relation model of Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models\Dynamic:dynamicHasMany() : Attempt to read property "created_at" on null', + 'Error resolving relation model of Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models\Dynamic:dynamicHasOne() : Attempt to read property "created_at" on null', + ]; $this->assertSame(0, $tester->getStatusCode()); $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); diff --git a/tests/Console/ModelsCommand/DynamicRelations/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/DynamicRelations/__snapshots__/Test__test__1.php index 07a8447..2044204 100644 --- a/tests/Console/ModelsCommand/DynamicRelations/__snapshots__/Test__test__1.php +++ b/tests/Console/ModelsCommand/DynamicRelations/__snapshots__/Test__test__1.php @@ -10,7 +10,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasOne; /** - * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models\Dynamic + * * * @property-read \Illuminate\Database\Eloquent\Collection $regularHasMany * @property-read int|null $regular_has_many_count diff --git a/tests/Console/ModelsCommand/Factories/Test.php b/tests/Console/ModelsCommand/Factories/Test.php index 1e96e34..f601911 100644 --- a/tests/Console/ModelsCommand/Factories/Test.php +++ b/tests/Console/ModelsCommand/Factories/Test.php @@ -8,41 +8,12 @@ use Barryvdh\LaravelIdeHelper\Console\ModelsCommand; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand; use Closure; use Illuminate\Database\Eloquent\Factories\Factory; -use Illuminate\Foundation\Application; use Illuminate\Support\Str; class Test extends AbstractModelsCommand { - public function test_8(): void + public function testFactory(): void { - if (!version_compare(Application::VERSION, '8.2', '>=') || !version_compare(Application::VERSION, '9', '<')) { - $this->markTestSkipped( - 'This test only works in Laravel >= 8.2 and < 9' - ); - } - - Factory::guessFactoryNamesUsing(static::getFactoryNameResolver()); - - $command = $this->app->make(ModelsCommand::class); - - $tester = $this->runCommand($command, [ - '--write' => true, - ]); - - $this->assertSame(0, $tester->getStatusCode()); - $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); - $this->assertStringNotContainsString('not found', $tester->getDisplay()); - $this->assertMatchesMockedSnapshot(); - } - - public function test_9(): void - { - if (!version_compare(Application::VERSION, '9', '>=')) { - $this->markTestSkipped( - 'This test only works in Laravel >= 9' - ); - } - Factory::guessFactoryNamesUsing(static::getFactoryNameResolver()); $command = $this->app->make(ModelsCommand::class); diff --git a/tests/Console/ModelsCommand/Factories/__snapshots__/Test__test_9__1.php b/tests/Console/ModelsCommand/Factories/__snapshots__/Test__testFactory__1.php similarity index 88% rename from tests/Console/ModelsCommand/Factories/__snapshots__/Test__test_9__1.php rename to tests/Console/ModelsCommand/Factories/__snapshots__/Test__testFactory__1.php index 1ec977b..211aaba 100644 --- a/tests/Console/ModelsCommand/Factories/__snapshots__/Test__test_9__1.php +++ b/tests/Console/ModelsCommand/Factories/__snapshots__/Test__testFactory__1.php @@ -9,7 +9,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; /** - * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Models\ModelWithCustomNamespace + * * * @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\CustomSpace\ModelWithCustomNamespaceFactory factory($count = null, $state = []) * @method static \Illuminate\Database\Eloquent\Builder|ModelWithCustomNamespace newModelQuery() @@ -41,7 +41,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; /** - * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Models\ModelWithFactory + * * * @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Factories\ModelWithFactoryFactory factory($count = null, $state = []) * @method static \Illuminate\Database\Eloquent\Builder|ModelWithFactory newModelQuery() @@ -60,7 +60,7 @@ declare(strict_types=1); namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Models; /** - * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Models\ModelWithNestedFactory + * * * @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Factories\ModelWithNestedFactoryFactory factory($count = null, $state = []) * @method static \Illuminate\Database\Eloquent\Builder|ModelWithNestedFactory newModelQuery() @@ -81,7 +81,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; /** - * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Models\ModelWithoutFactory + * * * @method static \Illuminate\Database\Eloquent\Builder|ModelWithoutFactory newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|ModelWithoutFactory newQuery() diff --git a/tests/Console/ModelsCommand/Factories/__snapshots__/Test__test_8__1.php b/tests/Console/ModelsCommand/Factories/__snapshots__/Test__test_8__1.php deleted file mode 100644 index 6c70514..0000000 --- a/tests/Console/ModelsCommand/Factories/__snapshots__/Test__test_8__1.php +++ /dev/null @@ -1,94 +0,0 @@ -app->make(ModelsCommand::class); + + $tester = $this->runCommand($command, [ + '--write' => true, + ]); + + $this->assertSame(0, $tester->getStatusCode()); + $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); + $this->assertMatchesMockedSnapshot(); + } +} diff --git a/tests/Console/ModelsCommand/GenerateBasicPhpDocWithEnumDefaults/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/GenerateBasicPhpDocWithEnumDefaults/__snapshots__/Test__test__1.php new file mode 100644 index 0000000..8a22180 --- /dev/null +++ b/tests/Console/ModelsCommand/GenerateBasicPhpDocWithEnumDefaults/__snapshots__/Test__test__1.php @@ -0,0 +1,168 @@ +> $collection_with_nested_template * @method static \Illuminate\Database\Eloquent\Builder|WithCollection newModelQuery() diff --git a/tests/Console/ModelsCommand/GeneratePhpdocWithExternalEloquentBuilder/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/GeneratePhpdocWithExternalEloquentBuilder/__snapshots__/Test__test__1.php index c788ecb..d24d756 100644 --- a/tests/Console/ModelsCommand/GeneratePhpdocWithExternalEloquentBuilder/__snapshots__/Test__test__1.php +++ b/tests/Console/ModelsCommand/GeneratePhpdocWithExternalEloquentBuilder/__snapshots__/Test__test__1.php @@ -13,9 +13,9 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithExternalEloquentBuilder\Models{ /** - * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithExternalEloquentBuilder\Models\Post + * * - * @property integer $id + * @property int $id * @property string|null $char_nullable * @property string $char_not_nullable * @property string|null $string_nullable @@ -26,36 +26,34 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWi * @property string $medium_text_not_nullable * @property string|null $long_text_nullable * @property string $long_text_not_nullable - * @property integer|null $integer_nullable - * @property integer $integer_not_nullable - * @property integer|null $tiny_integer_nullable - * @property integer $tiny_integer_not_nullable - * @property integer|null $small_integer_nullable - * @property integer $small_integer_not_nullable - * @property integer|null $medium_integer_nullable - * @property integer $medium_integer_not_nullable - * @property integer|null $big_integer_nullable - * @property integer $big_integer_not_nullable - * @property integer|null $unsigned_integer_nullable - * @property integer $unsigned_integer_not_nullable - * @property integer|null $unsigned_tiny_integer_nullable - * @property integer $unsigned_tiny_integer_not_nullable - * @property integer|null $unsigned_small_integer_nullable - * @property integer $unsigned_small_integer_not_nullable - * @property integer|null $unsigned_medium_integer_nullable - * @property integer $unsigned_medium_integer_not_nullable - * @property integer|null $unsigned_big_integer_nullable - * @property integer $unsigned_big_integer_not_nullable + * @property int|null $integer_nullable + * @property int $integer_not_nullable + * @property int|null $tiny_integer_nullable + * @property int $tiny_integer_not_nullable + * @property int|null $small_integer_nullable + * @property int $small_integer_not_nullable + * @property int|null $medium_integer_nullable + * @property int $medium_integer_not_nullable + * @property int|null $big_integer_nullable + * @property int $big_integer_not_nullable + * @property int|null $unsigned_integer_nullable + * @property int $unsigned_integer_not_nullable + * @property int|null $unsigned_tiny_integer_nullable + * @property int $unsigned_tiny_integer_not_nullable + * @property int|null $unsigned_small_integer_nullable + * @property int $unsigned_small_integer_not_nullable + * @property int|null $unsigned_medium_integer_nullable + * @property int $unsigned_medium_integer_not_nullable + * @property int|null $unsigned_big_integer_nullable + * @property int $unsigned_big_integer_not_nullable * @property float|null $float_nullable * @property float $float_not_nullable * @property float|null $double_nullable * @property float $double_not_nullable * @property string|null $decimal_nullable * @property string $decimal_not_nullable - * @property string|null $unsigned_decimal_nullable - * @property string $unsigned_decimal_not_nullable - * @property integer|null $boolean_nullable - * @property integer $boolean_not_nullable + * @property int|null $boolean_nullable + * @property int $boolean_not_nullable * @property string|null $enum_nullable * @property string $enum_not_nullable * @property string|null $json_nullable @@ -76,10 +74,10 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWi * @property string $timestamp_not_nullable * @property string|null $timestamptz_nullable * @property string $timestamptz_not_nullable - * @property integer|null $year_nullable - * @property integer $year_not_nullable - * @property mixed|null $binary_nullable - * @property mixed $binary_not_nullable + * @property int|null $year_nullable + * @property int $year_not_nullable + * @property string|null $binary_nullable + * @property string $binary_not_nullable * @property string|null $uuid_nullable * @property string $uuid_not_nullable * @property string|null $ipaddress_nullable @@ -152,8 +150,6 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWi * @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithExternalEloquentBuilder\Builders\PostExternalQueryBuilder|Post whereTinyIntegerNullable($value) * @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithExternalEloquentBuilder\Builders\PostExternalQueryBuilder|Post whereUnsignedBigIntegerNotNullable($value) * @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithExternalEloquentBuilder\Builders\PostExternalQueryBuilder|Post whereUnsignedBigIntegerNullable($value) - * @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithExternalEloquentBuilder\Builders\PostExternalQueryBuilder|Post whereUnsignedDecimalNotNullable($value) - * @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithExternalEloquentBuilder\Builders\PostExternalQueryBuilder|Post whereUnsignedDecimalNullable($value) * @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithExternalEloquentBuilder\Builders\PostExternalQueryBuilder|Post whereUnsignedIntegerNotNullable($value) * @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithExternalEloquentBuilder\Builders\PostExternalQueryBuilder|Post whereUnsignedIntegerNullable($value) * @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithExternalEloquentBuilder\Builders\PostExternalQueryBuilder|Post whereUnsignedMediumIntegerNotNullable($value) diff --git a/tests/Console/ModelsCommand/GeneratePhpdocWithExternalEloquentBuilderWithFqn/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/GeneratePhpdocWithExternalEloquentBuilderWithFqn/__snapshots__/Test__test__1.php index c634636..fe55b17 100644 --- a/tests/Console/ModelsCommand/GeneratePhpdocWithExternalEloquentBuilderWithFqn/__snapshots__/Test__test__1.php +++ b/tests/Console/ModelsCommand/GeneratePhpdocWithExternalEloquentBuilderWithFqn/__snapshots__/Test__test__1.php @@ -8,9 +8,9 @@ use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithExte use Illuminate\Database\Eloquent\Model; /** - * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithExternalEloquentBuilderWithFqn\Models\Post + * * - * @property integer $id + * @property int $id * @property string|null $char_nullable * @property string $char_not_nullable * @property string|null $string_nullable @@ -21,36 +21,34 @@ use Illuminate\Database\Eloquent\Model; * @property string $medium_text_not_nullable * @property string|null $long_text_nullable * @property string $long_text_not_nullable - * @property integer|null $integer_nullable - * @property integer $integer_not_nullable - * @property integer|null $tiny_integer_nullable - * @property integer $tiny_integer_not_nullable - * @property integer|null $small_integer_nullable - * @property integer $small_integer_not_nullable - * @property integer|null $medium_integer_nullable - * @property integer $medium_integer_not_nullable - * @property integer|null $big_integer_nullable - * @property integer $big_integer_not_nullable - * @property integer|null $unsigned_integer_nullable - * @property integer $unsigned_integer_not_nullable - * @property integer|null $unsigned_tiny_integer_nullable - * @property integer $unsigned_tiny_integer_not_nullable - * @property integer|null $unsigned_small_integer_nullable - * @property integer $unsigned_small_integer_not_nullable - * @property integer|null $unsigned_medium_integer_nullable - * @property integer $unsigned_medium_integer_not_nullable - * @property integer|null $unsigned_big_integer_nullable - * @property integer $unsigned_big_integer_not_nullable + * @property int|null $integer_nullable + * @property int $integer_not_nullable + * @property int|null $tiny_integer_nullable + * @property int $tiny_integer_not_nullable + * @property int|null $small_integer_nullable + * @property int $small_integer_not_nullable + * @property int|null $medium_integer_nullable + * @property int $medium_integer_not_nullable + * @property int|null $big_integer_nullable + * @property int $big_integer_not_nullable + * @property int|null $unsigned_integer_nullable + * @property int $unsigned_integer_not_nullable + * @property int|null $unsigned_tiny_integer_nullable + * @property int $unsigned_tiny_integer_not_nullable + * @property int|null $unsigned_small_integer_nullable + * @property int $unsigned_small_integer_not_nullable + * @property int|null $unsigned_medium_integer_nullable + * @property int $unsigned_medium_integer_not_nullable + * @property int|null $unsigned_big_integer_nullable + * @property int $unsigned_big_integer_not_nullable * @property float|null $float_nullable * @property float $float_not_nullable * @property float|null $double_nullable * @property float $double_not_nullable * @property string|null $decimal_nullable * @property string $decimal_not_nullable - * @property string|null $unsigned_decimal_nullable - * @property string $unsigned_decimal_not_nullable - * @property integer|null $boolean_nullable - * @property integer $boolean_not_nullable + * @property int|null $boolean_nullable + * @property int $boolean_not_nullable * @property string|null $enum_nullable * @property string $enum_not_nullable * @property string|null $json_nullable @@ -71,10 +69,10 @@ use Illuminate\Database\Eloquent\Model; * @property string $timestamp_not_nullable * @property string|null $timestamptz_nullable * @property string $timestamptz_not_nullable - * @property integer|null $year_nullable - * @property integer $year_not_nullable - * @property mixed|null $binary_nullable - * @property mixed $binary_not_nullable + * @property int|null $year_nullable + * @property int $year_not_nullable + * @property string|null $binary_nullable + * @property string $binary_not_nullable * @property string|null $uuid_nullable * @property string $uuid_not_nullable * @property string|null $ipaddress_nullable @@ -147,8 +145,6 @@ use Illuminate\Database\Eloquent\Model; * @method static PostExternalQueryBuilder|Post whereTinyIntegerNullable($value) * @method static PostExternalQueryBuilder|Post whereUnsignedBigIntegerNotNullable($value) * @method static PostExternalQueryBuilder|Post whereUnsignedBigIntegerNullable($value) - * @method static PostExternalQueryBuilder|Post whereUnsignedDecimalNotNullable($value) - * @method static PostExternalQueryBuilder|Post whereUnsignedDecimalNullable($value) * @method static PostExternalQueryBuilder|Post whereUnsignedIntegerNotNullable($value) * @method static PostExternalQueryBuilder|Post whereUnsignedIntegerNullable($value) * @method static PostExternalQueryBuilder|Post whereUnsignedMediumIntegerNotNullable($value) diff --git a/tests/Console/ModelsCommand/GeneratePhpdocWithForcedFqn/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/GeneratePhpdocWithForcedFqn/__snapshots__/Test__test__1.php index 20b2628..5b29b8a 100644 --- a/tests/Console/ModelsCommand/GeneratePhpdocWithForcedFqn/__snapshots__/Test__test__1.php +++ b/tests/Console/ModelsCommand/GeneratePhpdocWithForcedFqn/__snapshots__/Test__test__1.php @@ -9,9 +9,9 @@ use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; /** - * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post + * * - * @property integer $id + * @property int $id * @property string|null $char_nullable * @property string $char_not_nullable * @property string|null $string_nullable @@ -22,36 +22,34 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @property string $medium_text_not_nullable * @property string|null $long_text_nullable * @property string $long_text_not_nullable - * @property integer|null $integer_nullable - * @property integer $integer_not_nullable - * @property integer|null $tiny_integer_nullable - * @property integer $tiny_integer_not_nullable - * @property integer|null $small_integer_nullable - * @property integer $small_integer_not_nullable - * @property integer|null $medium_integer_nullable - * @property integer $medium_integer_not_nullable - * @property integer|null $big_integer_nullable - * @property integer $big_integer_not_nullable - * @property integer|null $unsigned_integer_nullable - * @property integer $unsigned_integer_not_nullable - * @property integer|null $unsigned_tiny_integer_nullable - * @property integer $unsigned_tiny_integer_not_nullable - * @property integer|null $unsigned_small_integer_nullable - * @property integer $unsigned_small_integer_not_nullable - * @property integer|null $unsigned_medium_integer_nullable - * @property integer $unsigned_medium_integer_not_nullable - * @property integer|null $unsigned_big_integer_nullable - * @property integer $unsigned_big_integer_not_nullable + * @property int|null $integer_nullable + * @property int $integer_not_nullable + * @property int|null $tiny_integer_nullable + * @property int $tiny_integer_not_nullable + * @property int|null $small_integer_nullable + * @property int $small_integer_not_nullable + * @property int|null $medium_integer_nullable + * @property int $medium_integer_not_nullable + * @property int|null $big_integer_nullable + * @property int $big_integer_not_nullable + * @property int|null $unsigned_integer_nullable + * @property int $unsigned_integer_not_nullable + * @property int|null $unsigned_tiny_integer_nullable + * @property int $unsigned_tiny_integer_not_nullable + * @property int|null $unsigned_small_integer_nullable + * @property int $unsigned_small_integer_not_nullable + * @property int|null $unsigned_medium_integer_nullable + * @property int $unsigned_medium_integer_not_nullable + * @property int|null $unsigned_big_integer_nullable + * @property int $unsigned_big_integer_not_nullable * @property float|null $float_nullable * @property float $float_not_nullable * @property float|null $double_nullable * @property float $double_not_nullable * @property string|null $decimal_nullable * @property string $decimal_not_nullable - * @property string|null $unsigned_decimal_nullable - * @property string $unsigned_decimal_not_nullable - * @property integer|null $boolean_nullable - * @property integer $boolean_not_nullable + * @property int|null $boolean_nullable + * @property int $boolean_not_nullable * @property string|null $enum_nullable * @property string $enum_not_nullable * @property string|null $json_nullable @@ -72,10 +70,10 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @property string $timestamp_not_nullable * @property string|null $timestamptz_nullable * @property string $timestamptz_not_nullable - * @property integer|null $year_nullable - * @property integer $year_not_nullable - * @property mixed|null $binary_nullable - * @property mixed $binary_not_nullable + * @property int|null $year_nullable + * @property int $year_not_nullable + * @property string|null $binary_nullable + * @property string $binary_not_nullable * @property string|null $uuid_nullable * @property string $uuid_not_nullable * @property string|null $ipaddress_nullable @@ -149,8 +147,6 @@ use Illuminate\Database\Eloquent\SoftDeletes; * @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereTinyIntegerNullable($value) * @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereUnsignedBigIntegerNotNullable($value) * @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereUnsignedBigIntegerNullable($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereUnsignedDecimalNotNullable($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereUnsignedDecimalNullable($value) * @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereUnsignedIntegerNotNullable($value) * @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereUnsignedIntegerNullable($value) * @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereUnsignedMediumIntegerNotNullable($value) diff --git a/tests/Console/ModelsCommand/GeneratePhpdocWithFqn/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/GeneratePhpdocWithFqn/__snapshots__/Test__test__1.php index 989fd8a..b87f750 100644 --- a/tests/Console/ModelsCommand/GeneratePhpdocWithFqn/__snapshots__/Test__test__1.php +++ b/tests/Console/ModelsCommand/GeneratePhpdocWithFqn/__snapshots__/Test__test__1.php @@ -15,9 +15,9 @@ use Illuminate\Database\Query\Builder as QueryBuilder; use Illuminate\Support\Carbon; /** - * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithFqn\Models\Post + * * - * @property integer $id + * @property int $id * @property string|null $char_nullable * @property CastType $char_not_nullable * @property string|null $string_nullable @@ -28,36 +28,34 @@ use Illuminate\Support\Carbon; * @property string $medium_text_not_nullable * @property string|null $long_text_nullable * @property string $long_text_not_nullable - * @property integer|null $integer_nullable - * @property integer $integer_not_nullable - * @property integer|null $tiny_integer_nullable - * @property integer $tiny_integer_not_nullable - * @property integer|null $small_integer_nullable - * @property integer $small_integer_not_nullable - * @property integer|null $medium_integer_nullable - * @property integer $medium_integer_not_nullable - * @property integer|null $big_integer_nullable - * @property integer $big_integer_not_nullable - * @property integer|null $unsigned_integer_nullable - * @property integer $unsigned_integer_not_nullable - * @property integer|null $unsigned_tiny_integer_nullable - * @property integer $unsigned_tiny_integer_not_nullable - * @property integer|null $unsigned_small_integer_nullable - * @property integer $unsigned_small_integer_not_nullable - * @property integer|null $unsigned_medium_integer_nullable - * @property integer $unsigned_medium_integer_not_nullable - * @property integer|null $unsigned_big_integer_nullable - * @property integer $unsigned_big_integer_not_nullable + * @property int|null $integer_nullable + * @property int $integer_not_nullable + * @property int|null $tiny_integer_nullable + * @property int $tiny_integer_not_nullable + * @property int|null $small_integer_nullable + * @property int $small_integer_not_nullable + * @property int|null $medium_integer_nullable + * @property int $medium_integer_not_nullable + * @property int|null $big_integer_nullable + * @property int $big_integer_not_nullable + * @property int|null $unsigned_integer_nullable + * @property int $unsigned_integer_not_nullable + * @property int|null $unsigned_tiny_integer_nullable + * @property int $unsigned_tiny_integer_not_nullable + * @property int|null $unsigned_small_integer_nullable + * @property int $unsigned_small_integer_not_nullable + * @property int|null $unsigned_medium_integer_nullable + * @property int $unsigned_medium_integer_not_nullable + * @property int|null $unsigned_big_integer_nullable + * @property int $unsigned_big_integer_not_nullable * @property float|null $float_nullable * @property float $float_not_nullable * @property float|null $double_nullable * @property float $double_not_nullable * @property string|null $decimal_nullable * @property string $decimal_not_nullable - * @property string|null $unsigned_decimal_nullable - * @property string $unsigned_decimal_not_nullable - * @property integer|null $boolean_nullable - * @property integer $boolean_not_nullable + * @property int|null $boolean_nullable + * @property int $boolean_not_nullable * @property string|null $enum_nullable * @property string $enum_not_nullable * @property string|null $json_nullable @@ -78,10 +76,10 @@ use Illuminate\Support\Carbon; * @property string $timestamp_not_nullable * @property string|null $timestamptz_nullable * @property string $timestamptz_not_nullable - * @property integer|null $year_nullable - * @property integer $year_not_nullable - * @property mixed|null $binary_nullable - * @property mixed $binary_not_nullable + * @property int|null $year_nullable + * @property int $year_not_nullable + * @property string|null $binary_nullable + * @property string $binary_not_nullable * @property string|null $uuid_nullable * @property string $uuid_not_nullable * @property string|null $ipaddress_nullable @@ -155,8 +153,6 @@ use Illuminate\Support\Carbon; * @method static EloquentBuilder|Post whereTinyIntegerNullable($value) * @method static EloquentBuilder|Post whereUnsignedBigIntegerNotNullable($value) * @method static EloquentBuilder|Post whereUnsignedBigIntegerNullable($value) - * @method static EloquentBuilder|Post whereUnsignedDecimalNotNullable($value) - * @method static EloquentBuilder|Post whereUnsignedDecimalNullable($value) * @method static EloquentBuilder|Post whereUnsignedIntegerNotNullable($value) * @method static EloquentBuilder|Post whereUnsignedIntegerNullable($value) * @method static EloquentBuilder|Post whereUnsignedMediumIntegerNotNullable($value) diff --git a/tests/Console/ModelsCommand/GeneratePhpdocWithFqnInExternalFile/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/GeneratePhpdocWithFqnInExternalFile/__snapshots__/Test__test__1.php index afb323d..a23e112 100644 --- a/tests/Console/ModelsCommand/GeneratePhpdocWithFqnInExternalFile/__snapshots__/Test__test__1.php +++ b/tests/Console/ModelsCommand/GeneratePhpdocWithFqnInExternalFile/__snapshots__/Test__test__1.php @@ -13,9 +13,9 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithFqnInExternalFile\Models{ /** - * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithFqnInExternalFile\Models\Post + * * - * @property integer $id + * @property int $id * @property string|null $char_nullable * @property string $char_not_nullable * @property string|null $string_nullable @@ -26,36 +26,34 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWi * @property string $medium_text_not_nullable * @property string|null $long_text_nullable * @property string $long_text_not_nullable - * @property integer|null $integer_nullable - * @property integer $integer_not_nullable - * @property integer|null $tiny_integer_nullable - * @property integer $tiny_integer_not_nullable - * @property integer|null $small_integer_nullable - * @property integer $small_integer_not_nullable - * @property integer|null $medium_integer_nullable - * @property integer $medium_integer_not_nullable - * @property integer|null $big_integer_nullable - * @property integer $big_integer_not_nullable - * @property integer|null $unsigned_integer_nullable - * @property integer $unsigned_integer_not_nullable - * @property integer|null $unsigned_tiny_integer_nullable - * @property integer $unsigned_tiny_integer_not_nullable - * @property integer|null $unsigned_small_integer_nullable - * @property integer $unsigned_small_integer_not_nullable - * @property integer|null $unsigned_medium_integer_nullable - * @property integer $unsigned_medium_integer_not_nullable - * @property integer|null $unsigned_big_integer_nullable - * @property integer $unsigned_big_integer_not_nullable + * @property int|null $integer_nullable + * @property int $integer_not_nullable + * @property int|null $tiny_integer_nullable + * @property int $tiny_integer_not_nullable + * @property int|null $small_integer_nullable + * @property int $small_integer_not_nullable + * @property int|null $medium_integer_nullable + * @property int $medium_integer_not_nullable + * @property int|null $big_integer_nullable + * @property int $big_integer_not_nullable + * @property int|null $unsigned_integer_nullable + * @property int $unsigned_integer_not_nullable + * @property int|null $unsigned_tiny_integer_nullable + * @property int $unsigned_tiny_integer_not_nullable + * @property int|null $unsigned_small_integer_nullable + * @property int $unsigned_small_integer_not_nullable + * @property int|null $unsigned_medium_integer_nullable + * @property int $unsigned_medium_integer_not_nullable + * @property int|null $unsigned_big_integer_nullable + * @property int $unsigned_big_integer_not_nullable * @property float|null $float_nullable * @property float $float_not_nullable * @property float|null $double_nullable * @property float $double_not_nullable * @property string|null $decimal_nullable * @property string $decimal_not_nullable - * @property string|null $unsigned_decimal_nullable - * @property string $unsigned_decimal_not_nullable - * @property integer|null $boolean_nullable - * @property integer $boolean_not_nullable + * @property int|null $boolean_nullable + * @property int $boolean_not_nullable * @property string|null $enum_nullable * @property string $enum_not_nullable * @property string|null $json_nullable @@ -76,10 +74,10 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWi * @property string $timestamp_not_nullable * @property string|null $timestamptz_nullable * @property string $timestamptz_not_nullable - * @property integer|null $year_nullable - * @property integer $year_not_nullable - * @property mixed|null $binary_nullable - * @property mixed $binary_not_nullable + * @property int|null $year_nullable + * @property int $year_not_nullable + * @property string|null $binary_nullable + * @property string $binary_not_nullable * @property string|null $uuid_nullable * @property string $uuid_not_nullable * @property string|null $ipaddress_nullable @@ -149,8 +147,6 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWi * @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithFqnInExternalFile\Builders\EMaterialQueryBuilder|Post whereTinyIntegerNullable($value) * @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithFqnInExternalFile\Builders\EMaterialQueryBuilder|Post whereUnsignedBigIntegerNotNullable($value) * @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithFqnInExternalFile\Builders\EMaterialQueryBuilder|Post whereUnsignedBigIntegerNullable($value) - * @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithFqnInExternalFile\Builders\EMaterialQueryBuilder|Post whereUnsignedDecimalNotNullable($value) - * @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithFqnInExternalFile\Builders\EMaterialQueryBuilder|Post whereUnsignedDecimalNullable($value) * @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithFqnInExternalFile\Builders\EMaterialQueryBuilder|Post whereUnsignedIntegerNotNullable($value) * @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithFqnInExternalFile\Builders\EMaterialQueryBuilder|Post whereUnsignedIntegerNullable($value) * @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithFqnInExternalFile\Builders\EMaterialQueryBuilder|Post whereUnsignedMediumIntegerNotNullable($value) diff --git a/tests/Console/ModelsCommand/GeneratePhpdocWithMixin/Models/FinalPost.php b/tests/Console/ModelsCommand/GeneratePhpdocWithMixin/Models/FinalPost.php new file mode 100644 index 0000000..79cdff9 --- /dev/null +++ b/tests/Console/ModelsCommand/GeneratePhpdocWithMixin/Models/FinalPost.php @@ -0,0 +1,16 @@ +unsetMethod('query'); + $command->unsetMethod('newmodelquery'); } } diff --git a/tests/Console/ModelsCommand/ModelHooks/Test.php b/tests/Console/ModelsCommand/ModelHooks/Test.php index 05ffea2..339c9ef 100644 --- a/tests/Console/ModelsCommand/ModelHooks/Test.php +++ b/tests/Console/ModelsCommand/ModelHooks/Test.php @@ -71,13 +71,13 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ModelHooks\Model use Illuminate\Database\Eloquent\Model; /** - * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ModelHooks\Models\Simple + * * * @property int $id * @property-read string $custom * @method static \Illuminate\Database\Eloquent\Builder|Simple custom($custom) - * @method static \Illuminate\Database\Eloquent\Builder|Simple newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Simple newQuery() + * @method static \Illuminate\Database\Eloquent\Builder|Simple query() * @method static \Illuminate\Database\Eloquent\Builder|Simple whereId($value) * @mixin \Eloquent */ diff --git a/tests/Console/ModelsCommand/PHPStormNoInspection/__snapshots__/Test__testNoinspectionNotPresent__1.php b/tests/Console/ModelsCommand/PHPStormNoInspection/__snapshots__/Test__testNoinspectionNotPresent__1.php index 25c0e3b..1960bb6 100644 --- a/tests/Console/ModelsCommand/PHPStormNoInspection/__snapshots__/Test__testNoinspectionNotPresent__1.php +++ b/tests/Console/ModelsCommand/PHPStormNoInspection/__snapshots__/Test__testNoinspectionNotPresent__1.php @@ -7,9 +7,9 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\PHPStormNoInspec use Illuminate\Database\Eloquent\Model; /** - * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\PHPStormNoInspection\Models\Simple + * * - * @property integer $id + * @property int $id * @method static \Illuminate\Database\Eloquent\Builder|Simple newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Simple newQuery() * @method static \Illuminate\Database\Eloquent\Builder|Simple query() diff --git a/tests/Console/ModelsCommand/PHPStormNoInspection/__snapshots__/Test__testNoinspectionPresent__1.php b/tests/Console/ModelsCommand/PHPStormNoInspection/__snapshots__/Test__testNoinspectionPresent__1.php index 9cb1f27..e34fb0b 100644 --- a/tests/Console/ModelsCommand/PHPStormNoInspection/__snapshots__/Test__testNoinspectionPresent__1.php +++ b/tests/Console/ModelsCommand/PHPStormNoInspection/__snapshots__/Test__testNoinspectionPresent__1.php @@ -7,9 +7,9 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\PHPStormNoInspec use Illuminate\Database\Eloquent\Model; /** - * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\PHPStormNoInspection\Models\Simple + * * - * @property integer $id + * @property int $id * @method static \Illuminate\Database\Eloquent\Builder|Simple newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Simple newQuery() * @method static \Illuminate\Database\Eloquent\Builder|Simple query() diff --git a/tests/Console/ModelsCommand/RelationCountProperties/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/RelationCountProperties/__snapshots__/Test__test__1.php index 5e2a131..b5bc105 100644 --- a/tests/Console/ModelsCommand/RelationCountProperties/__snapshots__/Test__test__1.php +++ b/tests/Console/ModelsCommand/RelationCountProperties/__snapshots__/Test__test__1.php @@ -8,9 +8,9 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; /** - * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\RelationCountProperties\Models\Post + * * - * @property integer $id + * @property int $id * @property string|null $char_nullable * @property string $char_not_nullable * @property string|null $string_nullable @@ -21,36 +21,34 @@ use Illuminate\Database\Eloquent\Relations\HasMany; * @property string $medium_text_not_nullable * @property string|null $long_text_nullable * @property string $long_text_not_nullable - * @property integer|null $integer_nullable - * @property integer $integer_not_nullable - * @property integer|null $tiny_integer_nullable - * @property integer $tiny_integer_not_nullable - * @property integer|null $small_integer_nullable - * @property integer $small_integer_not_nullable - * @property integer|null $medium_integer_nullable - * @property integer $medium_integer_not_nullable - * @property integer|null $big_integer_nullable - * @property integer $big_integer_not_nullable - * @property integer|null $unsigned_integer_nullable - * @property integer $unsigned_integer_not_nullable - * @property integer|null $unsigned_tiny_integer_nullable - * @property integer $unsigned_tiny_integer_not_nullable - * @property integer|null $unsigned_small_integer_nullable - * @property integer $unsigned_small_integer_not_nullable - * @property integer|null $unsigned_medium_integer_nullable - * @property integer $unsigned_medium_integer_not_nullable - * @property integer|null $unsigned_big_integer_nullable - * @property integer $unsigned_big_integer_not_nullable + * @property int|null $integer_nullable + * @property int $integer_not_nullable + * @property int|null $tiny_integer_nullable + * @property int $tiny_integer_not_nullable + * @property int|null $small_integer_nullable + * @property int $small_integer_not_nullable + * @property int|null $medium_integer_nullable + * @property int $medium_integer_not_nullable + * @property int|null $big_integer_nullable + * @property int $big_integer_not_nullable + * @property int|null $unsigned_integer_nullable + * @property int $unsigned_integer_not_nullable + * @property int|null $unsigned_tiny_integer_nullable + * @property int $unsigned_tiny_integer_not_nullable + * @property int|null $unsigned_small_integer_nullable + * @property int $unsigned_small_integer_not_nullable + * @property int|null $unsigned_medium_integer_nullable + * @property int $unsigned_medium_integer_not_nullable + * @property int|null $unsigned_big_integer_nullable + * @property int $unsigned_big_integer_not_nullable * @property float|null $float_nullable * @property float $float_not_nullable * @property float|null $double_nullable * @property float $double_not_nullable * @property string|null $decimal_nullable * @property string $decimal_not_nullable - * @property string|null $unsigned_decimal_nullable - * @property string $unsigned_decimal_not_nullable - * @property integer|null $boolean_nullable - * @property integer $boolean_not_nullable + * @property int|null $boolean_nullable + * @property int $boolean_not_nullable * @property string|null $enum_nullable * @property string $enum_not_nullable * @property string|null $json_nullable @@ -71,10 +69,10 @@ use Illuminate\Database\Eloquent\Relations\HasMany; * @property string $timestamp_not_nullable * @property string|null $timestamptz_nullable * @property string $timestamptz_not_nullable - * @property integer|null $year_nullable - * @property integer $year_not_nullable - * @property mixed|null $binary_nullable - * @property mixed $binary_not_nullable + * @property int|null $year_nullable + * @property int $year_not_nullable + * @property string|null $binary_nullable + * @property string $binary_not_nullable * @property string|null $uuid_nullable * @property string $uuid_not_nullable * @property string|null $ipaddress_nullable @@ -145,8 +143,6 @@ use Illuminate\Database\Eloquent\Relations\HasMany; * @method static \Illuminate\Database\Eloquent\Builder|Post whereTinyIntegerNullable($value) * @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedBigIntegerNotNullable($value) * @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedBigIntegerNullable($value) - * @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedDecimalNotNullable($value) - * @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedDecimalNullable($value) * @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedIntegerNotNullable($value) * @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedIntegerNullable($value) * @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedMediumIntegerNotNullable($value) diff --git a/tests/Console/ModelsCommand/Relations/Models/CompositeBelongsToVariation.php b/tests/Console/ModelsCommand/Relations/Models/CompositeBelongsToVariation.php new file mode 100644 index 0000000..5fb041d --- /dev/null +++ b/tests/Console/ModelsCommand/Relations/Models/CompositeBelongsToVariation.php @@ -0,0 +1,41 @@ +belongsTo( + self::class, + ['not_null_column_with_foreign_key_constraint', 'not_null_column_with_foreign_key_constraint'], + ['not_null_column_with_foreign_key_constraint', 'not_null_column_with_foreign_key_constraint'], + ); + } + + public function nonNullableMixedWithoutForeignKeyConstraint(): BelongsTo + { + return $this->belongsTo( + self::class, + ['not_null_column_with_foreign_key_constraint', 'not_null_column_with_no_foreign_key_constraint'], + ['not_null_column_with_foreign_key_constraint', 'not_null_column_with_no_foreign_key_constraint'], + ); + } + + public function nullableMixedWithForeignKeyConstraint(): BelongsTo + { + return $this->belongsTo( + self::class, + ['nullable_column_with_no_foreign_key_constraint', 'not_null_column_with_foreign_key_constraint'], + ['nullable_column_with_no_foreign_key_constraint', 'not_null_column_with_foreign_key_constraint'], + ); + } +} diff --git a/tests/Console/ModelsCommand/Relations/Models/Simple.php b/tests/Console/ModelsCommand/Relations/Models/Simple.php index 12e8c87..bb8387c 100644 --- a/tests/Console/ModelsCommand/Relations/Models/Simple.php +++ b/tests/Console/ModelsCommand/Relations/Models/Simple.php @@ -107,4 +107,9 @@ class Simple extends Model { return $this->testToAnyMorphedRelation(Simple::class); } + + public function relationSampleToBadlyNamedNotManyRelation() + { + return $this->testToBadlyNamedNotManyRelation(Simple::class); + } } diff --git a/tests/Console/ModelsCommand/Relations/Test.php b/tests/Console/ModelsCommand/Relations/Test.php index fd94d23..3c5e41c 100644 --- a/tests/Console/ModelsCommand/Relations/Test.php +++ b/tests/Console/ModelsCommand/Relations/Test.php @@ -6,7 +6,9 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations; use Barryvdh\LaravelIdeHelper\Console\ModelsCommand; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand; +use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Types\SampleToAnyMorphedRelationType; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Types\SampleToAnyRelationType; +use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Types\SampleToBadlyNamedNotManyRelationType; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Types\SampleToManyRelationType; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Types\SampleToOneRelationType; use Illuminate\Support\Facades\Config; @@ -22,11 +24,13 @@ class Test extends AbstractModelsCommand 'testToManyRelation' => SampleToManyRelationType::class, 'testToAnyRelation' => SampleToAnyRelationType::class, 'testToAnyMorphedRelation' => SampleToAnyMorphedRelationType::class, + 'testToBadlyNamedNotManyRelation' => SampleToBadlyNamedNotManyRelationType::class, ]); Config::set('ide-helper.additional_relation_return_types', [ 'testToAnyRelation' => 'many', 'testToAnyMorphedRelation' => 'morphTo', + 'testToBadlyNamedNotManyRelation' => 'one', ]); } diff --git a/tests/Console/ModelsCommand/Relations/Traits/HasTestRelations.php b/tests/Console/ModelsCommand/Relations/Traits/HasTestRelations.php index 0d25260..d63b904 100644 --- a/tests/Console/ModelsCommand/Relations/Traits/HasTestRelations.php +++ b/tests/Console/ModelsCommand/Relations/Traits/HasTestRelations.php @@ -6,6 +6,7 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Traits use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Types\SampleToAnyMorphedRelationType; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Types\SampleToAnyRelationType; +use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Types\SampleToBadlyNamedNotManyRelationType; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Types\SampleToManyRelationType; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Types\SampleToOneRelationType; @@ -34,4 +35,10 @@ trait HasTestRelations $instance = $this->newRelatedInstance($related); return new SampleToAnyMorphedRelationType($instance->newQuery(), $this); } + + public function testToBadlyNamedNotManyRelation($related) + { + $instance = $this->newRelatedInstance($related); + return new SampleToBadlyNamedNotManyRelationType($instance->newQuery(), $this); + } } diff --git a/tests/Console/ModelsCommand/Relations/Types/SampleToBadlyNamedNotManyRelationType.php b/tests/Console/ModelsCommand/Relations/Types/SampleToBadlyNamedNotManyRelationType.php new file mode 100644 index 0000000..a8a753a --- /dev/null +++ b/tests/Console/ModelsCommand/Relations/Types/SampleToBadlyNamedNotManyRelationType.php @@ -0,0 +1,52 @@ +belongsTo( + self::class, + ['not_null_column_with_foreign_key_constraint', 'not_null_column_with_foreign_key_constraint'], + ['not_null_column_with_foreign_key_constraint', 'not_null_column_with_foreign_key_constraint'], + ); + } + + public function nonNullableMixedWithoutForeignKeyConstraint(): BelongsTo + { + return $this->belongsTo( + self::class, + ['not_null_column_with_foreign_key_constraint', 'not_null_column_with_no_foreign_key_constraint'], + ['not_null_column_with_foreign_key_constraint', 'not_null_column_with_no_foreign_key_constraint'], + ); + } + + public function nullableMixedWithForeignKeyConstraint(): BelongsTo + { + return $this->belongsTo( + self::class, + ['nullable_column_with_no_foreign_key_constraint', 'not_null_column_with_foreign_key_constraint'], + ['nullable_column_with_no_foreign_key_constraint', 'not_null_column_with_foreign_key_constraint'], + ); + } +} + $relationBelongsToMany @@ -97,6 +159,7 @@ use Illuminate\Database\Eloquent\Relations\MorphToMany; * @property-read Model|\Eloquent $relationSampleToAnyMorphedRelationType * @property-read \Illuminate\Database\Eloquent\Collection $relationSampleToAnyRelationType * @property-read int|null $relation_sample_to_any_relation_type_count + * @property-read Simple $relationSampleToBadlyNamedNotManyRelation * @property-read Simple $relationSampleToManyRelationType * @method static \Illuminate\Database\Eloquent\Builder|Simple newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Simple newQuery() @@ -195,4 +258,9 @@ class Simple extends Model { return $this->testToAnyMorphedRelation(Simple::class); } + + public function relationSampleToBadlyNamedNotManyRelation() + { + return $this->testToBadlyNamedNotManyRelation(Simple::class); + } } diff --git a/tests/Console/ModelsCommand/ResetAndSmartReset/Test.php b/tests/Console/ModelsCommand/ResetAndSmartReset/Test.php index 865684e..6ed8b80 100644 --- a/tests/Console/ModelsCommand/ResetAndSmartReset/Test.php +++ b/tests/Console/ModelsCommand/ResetAndSmartReset/Test.php @@ -35,18 +35,4 @@ class Test extends AbstractModelsCommand $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); $this->assertMatchesMockedSnapshot(); } - - public function testSmartReset(): void - { - $command = $this->app->make(ModelsCommand::class); - - $tester = $this->runCommand($command, [ - '--write' => true, - '--smart-reset' => true, - ]); - - $this->assertSame(0, $tester->getStatusCode()); - $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); - $this->assertMatchesMockedSnapshot(); - } } diff --git a/tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testNoReset__1.php b/tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testNoReset__1.php index 6e5b180..54df564 100644 --- a/tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testNoReset__1.php +++ b/tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testNoReset__1.php @@ -10,7 +10,7 @@ use Illuminate\Database\Eloquent\Model; * Text of existing phpdoc * * @property string $foo - * @property integer $id + * @property int $id * @method static \Illuminate\Database\Eloquent\Builder|Simple newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Simple newQuery() * @method static \Illuminate\Database\Eloquent\Builder|Simple query() diff --git a/tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testReset__1.php b/tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testReset__1.php index 08f1d06..de69023 100644 --- a/tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testReset__1.php +++ b/tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testReset__1.php @@ -7,9 +7,9 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ResetAndSmartRes use Illuminate\Database\Eloquent\Model; /** - * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\ResetAndSmartReset\Models\Simple + * Text of existing phpdoc * - * @property integer $id + * @property int $id * @method static \Illuminate\Database\Eloquent\Builder|Simple newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Simple newQuery() * @method static \Illuminate\Database\Eloquent\Builder|Simple query() diff --git a/tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testSmartReset__1.php b/tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testSmartReset__1.php index 3ba9c2b..de69023 100644 --- a/tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testSmartReset__1.php +++ b/tests/Console/ModelsCommand/ResetAndSmartReset/__snapshots__/Test__testSmartReset__1.php @@ -9,7 +9,7 @@ use Illuminate\Database\Eloquent\Model; /** * Text of existing phpdoc * - * @property integer $id + * @property int $id * @method static \Illuminate\Database\Eloquent\Builder|Simple newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Simple newQuery() * @method static \Illuminate\Database\Eloquent\Builder|Simple query() diff --git a/tests/Console/ModelsCommand/SimpleCasts/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/SimpleCasts/__snapshots__/Test__test__1.php index 91a4511..cfcec0b 100644 --- a/tests/Console/ModelsCommand/SimpleCasts/__snapshots__/Test__test__1.php +++ b/tests/Console/ModelsCommand/SimpleCasts/__snapshots__/Test__test__1.php @@ -7,17 +7,17 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\SimpleCasts\Mode use Illuminate\Database\Eloquent\Model; /** - * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\SimpleCasts\Models\SimpleCast + * * - * @property integer $cast_to_int - * @property integer $cast_to_integer + * @property int $cast_to_int + * @property int $cast_to_integer * @property float $cast_to_real * @property float $cast_to_float * @property float $cast_to_double * @property string $cast_to_decimal * @property string $cast_to_string - * @property boolean $cast_to_bool - * @property boolean $cast_to_boolean + * @property bool $cast_to_bool + * @property bool $cast_to_boolean * @property object $cast_to_object * @property array $cast_to_array * @property array $cast_to_json @@ -32,7 +32,7 @@ use Illuminate\Database\Eloquent\Model; * @property \Carbon\CarbonImmutable $cast_to_immutable_custom_datetime * @property \Carbon\CarbonImmutable $cast_to_immutable_datetime * @property \Carbon\CarbonImmutable $cast_to_immutable_datetime_serialization - * @property integer $cast_to_timestamp + * @property int $cast_to_timestamp * @property mixed $cast_to_encrypted * @property array $cast_to_encrypted_array * @property \Illuminate\Support\Collection $cast_to_encrypted_collection diff --git a/tests/Console/ModelsCommand/SoftDeletes/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/SoftDeletes/__snapshots__/Test__test__1.php index 0409634..1e89df1 100644 --- a/tests/Console/ModelsCommand/SoftDeletes/__snapshots__/Test__test__1.php +++ b/tests/Console/ModelsCommand/SoftDeletes/__snapshots__/Test__test__1.php @@ -8,9 +8,9 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; /** - * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\SoftDeletes\Models\Simple + * * - * @property integer $id + * @property int $id * @method static \Illuminate\Database\Eloquent\Builder|Simple newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|Simple newQuery() * @method static \Illuminate\Database\Eloquent\Builder|Simple onlyTrashed() diff --git a/tests/Console/ModelsCommand/UnionTypes/Test.php b/tests/Console/ModelsCommand/UnionTypes/Test.php index 58ba763..7ae68ab 100644 --- a/tests/Console/ModelsCommand/UnionTypes/Test.php +++ b/tests/Console/ModelsCommand/UnionTypes/Test.php @@ -9,15 +9,6 @@ use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand; class Test extends AbstractModelsCommand { - protected function setUp(): void - { - parent::setUp(); - - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('This test requires PHP 8.0 or higher'); - } - } - public function test(): void { $command = $this->app->make(ModelsCommand::class); diff --git a/tests/Console/ModelsCommand/UnionTypes/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/UnionTypes/__snapshots__/Test__test__1.php index 67f759e..fec632f 100644 --- a/tests/Console/ModelsCommand/UnionTypes/__snapshots__/Test__test__1.php +++ b/tests/Console/ModelsCommand/UnionTypes/__snapshots__/Test__test__1.php @@ -9,7 +9,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Query\Builder; /** - * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\UnionTypes\Models\UnionTypeModel + * * * @property-read string|int|null $foo * @property-read \Illuminate\Database\Eloquent\Collection $withUnionTypeReturn diff --git a/tests/Console/ModelsCommand/Variadic/__snapshots__/Test__test__1.php b/tests/Console/ModelsCommand/Variadic/__snapshots__/Test__test__1.php index dd1a3d3..ca6b7af 100644 --- a/tests/Console/ModelsCommand/Variadic/__snapshots__/Test__test__1.php +++ b/tests/Console/ModelsCommand/Variadic/__snapshots__/Test__test__1.php @@ -8,9 +8,9 @@ use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; /** - * Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Variadic\Models\Simple + * * - * @property integer $id + * @property int $id * @method static Builder|Simple newModelQuery() * @method static Builder|Simple newQuery() * @method static Builder|Simple query() diff --git a/tests/Console/ModelsCommand/migrations/____advanced_casts_table.php b/tests/Console/ModelsCommand/migrations/____advanced_casts_table.php new file mode 100644 index 0000000..3c6a392 --- /dev/null +++ b/tests/Console/ModelsCommand/migrations/____advanced_casts_table.php @@ -0,0 +1,30 @@ +string('cast_to_date_serialization'); + $table->string('cast_to_datetime_serialization'); + $table->string('cast_to_custom_datetime'); + $table->string('cast_to_immutable_date'); + $table->string('cast_to_immutable_custom_datetime'); + $table->string('cast_to_immutable_datetime'); + $table->string('cast_to_timestamp'); + $table->string('cast_to_encrypted'); + $table->string('cast_to_encrypted_array'); + $table->string('cast_to_encrypted_collection'); + $table->string('cast_to_encrypted_json'); + $table->string('cast_to_encrypted_object'); + $table->string('cast_to_as_collection'); + $table->string('cast_to_as_array_object'); + }); + } +} diff --git a/tests/Console/ModelsCommand/migrations/____posts_table.php b/tests/Console/ModelsCommand/migrations/____posts_table.php index ee81f61..511479c 100644 --- a/tests/Console/ModelsCommand/migrations/____posts_table.php +++ b/tests/Console/ModelsCommand/migrations/____posts_table.php @@ -67,9 +67,6 @@ class PostsTable extends Migration $table->decimal('decimal_nullable')->nullable(); $table->decimal('decimal_not_nullable'); - $table->unsignedDecimal('unsigned_decimal_nullable')->nullable(); - $table->unsignedDecimal('unsigned_decimal_not_nullable'); - $table->boolean('boolean_nullable')->nullable(); $table->boolean('boolean_not_nullable'); diff --git a/tests/MacroTest.php b/tests/MacroTest.php index a0fa904..cf1f79f 100644 --- a/tests/MacroTest.php +++ b/tests/MacroTest.php @@ -190,10 +190,6 @@ class MacroTest extends TestCase public function testInitPhpDocParamsWithUnionTypes(): void { - if (PHP_VERSION_ID < 80000) { - $this->markTestSkipped('This test requires PHP 8.0 or higher'); - } - $phpdoc = (new MacroMock())->getPhpDoc(eval(<<<'PHP' return new ReflectionFunction( /** @@ -231,7 +227,7 @@ class MacroTest extends TestCase { $reflectionMethod = new \ReflectionMethod(UrlGeneratorMacroClass::class, '__invoke'); - $macro = new Macro($reflectionMethod, UrlGenerator::class, new \ReflectionClass(UrlGenerator::class), 'macroName'); + $macro = new Macro($reflectionMethod, UrlGenerator::class, new ReflectionClass(UrlGenerator::class), 'macroName'); $this->assertInstanceOf(Macro::class, $macro); } @@ -243,7 +239,7 @@ class MacroTest extends TestCase { $reflectionMethod = new \ReflectionMethod(UrlGeneratorMacroClass::class, '__invoke'); - $macro = new Macro($reflectionMethod, 'URL', new \ReflectionClass(UrlGenerator::class), 'macroName'); + $macro = new Macro($reflectionMethod, 'URL', new ReflectionClass(UrlGenerator::class), 'macroName'); $output = <<<'DOC' /** * diff --git a/tests/RealTimeFacadesTest.php b/tests/RealTimeFacadesTest.php new file mode 100644 index 0000000..42895b8 --- /dev/null +++ b/tests/RealTimeFacadesTest.php @@ -0,0 +1,90 @@ +app['config'], $this->app['view'], null, false); + + // Clear aliases and macros to have a small output file + AliasLoader::getInstance()->setAliases([]); + Request::flushMacros(); + + // Generate the helper file and return the content + $content = $generator->generate(); + + $this->assertStringContainsString('namespace Facades\Illuminate\Foundation\Exceptions {', $content, 'Could not find Facades\Illuminate\Foundation\Exceptions namespace in the generated helper file.'); + $this->assertStringContainsString('namespace Facades\App\Exceptions {', $content, 'Could not find Facades\App\Exceptions namespace in the generated helper file.'); + + $parsed = collect((new Php7(new Emulative()))->parse($content) ?: []); + + // test the Facades\Illuminate\Foundation\Exceptions namespace in the generated helper file + $frameworkExceptionsNamespace = $parsed->first(function ($stmt) { + return ($stmt instanceof Namespace_) && $stmt->name->toString() === 'Facades\Illuminate\Foundation\Exceptions'; + }); + $this->assertNotNull($frameworkExceptionsNamespace, 'Could not find Facades\Illuminate\Foundation\Exceptions namespace'); + $this->assertSame('Facades\Illuminate\Foundation\Exceptions', $frameworkExceptionsNamespace->name->toString()); + $this->verifyNamespace($frameworkExceptionsNamespace, 'Illuminate\Foundation\Exceptions\Handler'); + + // test the Facades\App\Exceptions namespace in the generated helper file + $appExceptionsNamespace = $parsed->first(function ($stmt) { + return ($stmt instanceof Namespace_) && $stmt->name->toString() === 'Facades\App\Exceptions'; + }); + $this->assertNotNull($appExceptionsNamespace, 'Could not find Facades\App\Exceptions namespace'); + $this->assertSame('Facades\App\Exceptions', $appExceptionsNamespace->name->toString()); + $this->verifyNamespace($appExceptionsNamespace, 'App\Exceptions\Handler'); + } + + private function verifyNamespace(Namespace_ $namespace, $target) + { + $stmts = collect($namespace->stmts); + + $this->assertInstanceOf(Class_::class, $stmts[0], 'Expected instance of Class_'); + + $statement = $stmts[0]; + $this->assertArrayHasKey('comments', $statement->getAttributes()); + + $this->assertStringContainsString('@mixin \\' . $target, $statement->getAttributes()['comments'][0]->getText(), 'Mixin comment not found'); + $this->assertSame(class_basename($target), $statement->name->toString(), 'Class name not found'); + $this->assertSame($target, $statement->extends->toString(), 'Class extends not found'); + } + + protected function getPackageProviders($app) + { + return [IdeHelperServiceProvider::class]; + } +} diff --git a/tests/stubs/facade-0e0385307adf5db34c7986ecbd11646061356ec8.php b/tests/stubs/facade-0e0385307adf5db34c7986ecbd11646061356ec8.php new file mode 100644 index 0000000..6a8ad57 --- /dev/null +++ b/tests/stubs/facade-0e0385307adf5db34c7986ecbd11646061356ec8.php @@ -0,0 +1,21 @@ +