mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 10:07:12 +00:00
Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2535f8e6ab | ||
|
|
16548fc878 | ||
|
|
872b470d9b | ||
|
|
04c1a8d444 | ||
|
|
c290af858d | ||
|
|
f64ff9c0b1 | ||
|
|
f3ad134242 | ||
|
|
9d14b019f6 | ||
|
|
f4656256fc | ||
|
|
cc9ed4423b | ||
|
|
512612f22f | ||
|
|
115068e57b | ||
|
|
a8b34ad228 |
@@ -19,25 +19,13 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
php: [8.3, 8.2, 8.1, 8.0, 7.4, 7.3]
|
php: [8.3, 8.2, 8.1, 8.0]
|
||||||
laravel: [10.*, 9.*, 8.*]
|
laravel: [10.*, 9.*]
|
||||||
exclude:
|
exclude:
|
||||||
- php: 8.0
|
- php: 8.0
|
||||||
laravel: 10.*
|
laravel: 10.*
|
||||||
- php: 7.4
|
|
||||||
laravel: 10.*
|
|
||||||
- php: 7.3
|
|
||||||
laravel: 10.*
|
|
||||||
- php: 8.3
|
- php: 8.3
|
||||||
laravel: 9.*
|
laravel: 9.*
|
||||||
- php: 7.4
|
|
||||||
laravel: 9.*
|
|
||||||
- php: 7.3
|
|
||||||
laravel: 9.*
|
|
||||||
- php: 8.3
|
|
||||||
laravel: 8.*
|
|
||||||
- php: 8.2
|
|
||||||
laravel: 8.*
|
|
||||||
name: P${{ matrix.php }} - Laravel${{ matrix.laravel }}
|
name: P${{ matrix.php }} - Laravel${{ matrix.laravel }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ jobs:
|
|||||||
- name: Setup PHP
|
- name: Setup PHP
|
||||||
uses: shivammathur/setup-php@v2
|
uses: shivammathur/setup-php@v2
|
||||||
with:
|
with:
|
||||||
php-version: 8.0
|
php-version: 8.1
|
||||||
coverage: none
|
coverage: none
|
||||||
extensions: pdo_sqlite
|
extensions: pdo_sqlite
|
||||||
|
|
||||||
|
|||||||
@@ -20,26 +20,14 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-20.04, windows-2019]
|
os: [ubuntu-20.04, windows-2019]
|
||||||
php: [8.3, 8.2, 8.1, 8.0, 7.4, 7.3]
|
php: [8.3, 8.2, 8.1, 8.0]
|
||||||
laravel: [8.*, 9.*, 10.*]
|
laravel: [9.*, 10.*]
|
||||||
dependency-version: [prefer-lowest, prefer-stable]
|
dependency-version: [prefer-lowest, prefer-stable]
|
||||||
exclude:
|
exclude:
|
||||||
- php: 8.0
|
- php: 8.0
|
||||||
laravel: 10.*
|
laravel: 10.*
|
||||||
- php: 7.4
|
|
||||||
laravel: 10.*
|
|
||||||
- php: 7.3
|
|
||||||
laravel: 10.*
|
|
||||||
- php: 8.0
|
- php: 8.0
|
||||||
dependency-version: prefer-lowest
|
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
|
|
||||||
steps:
|
steps:
|
||||||
- name: Set git to use LF
|
- name: Set git to use LF
|
||||||
if: ${{ matrix.os == 'windows-2019' }}
|
if: ${{ matrix.os == 'windows-2019' }}
|
||||||
|
|||||||
+3
-3
@@ -1,8 +1,8 @@
|
|||||||
.phpunit.result.cache
|
.phpunit.result.cache
|
||||||
|
|
||||||
/.idea
|
/.idea
|
||||||
/.php_cs
|
/.php-cs-fixer.cache
|
||||||
/.php_cs.cache
|
/.php-cs-fixer.php
|
||||||
/.php_cs.tests.cache
|
/.php-cs-fixer.tests.cache
|
||||||
/composer.lock
|
/composer.lock
|
||||||
/vendor
|
/vendor
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ return [
|
|||||||
],
|
],
|
||||||
'return_type_declaration' => true,
|
'return_type_declaration' => true,
|
||||||
'short_scalar_cast' => true,
|
'short_scalar_cast' => true,
|
||||||
'single_blank_line_before_namespace' => true,
|
|
||||||
'single_trait_insert_per_statement' => true,
|
'single_trait_insert_per_statement' => true,
|
||||||
'ternary_operator_spaces' => true,
|
'ternary_operator_spaces' => true,
|
||||||
'visibility_required' => [
|
'visibility_required' => [
|
||||||
@@ -56,7 +55,7 @@ return [
|
|||||||
'no_unused_imports' => true,
|
'no_unused_imports' => true,
|
||||||
'single_quote' => true,
|
'single_quote' => true,
|
||||||
'space_after_semicolon' => true,
|
'space_after_semicolon' => true,
|
||||||
'trailing_comma_in_multiline_array' => true,
|
'trailing_comma_in_multiline' => true,
|
||||||
'trim_array_spaces' => true,
|
'trim_array_spaces' => true,
|
||||||
'unary_operator_spaces' => true,
|
'unary_operator_spaces' => true,
|
||||||
'whitespace_after_comma_in_array' => true,
|
'whitespace_after_comma_in_array' => true,
|
||||||
@@ -5,10 +5,10 @@ $finder = PhpCsFixer\Finder::create()
|
|||||||
->in(__DIR__)
|
->in(__DIR__)
|
||||||
->exclude('tests');
|
->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)
|
->setFinder($finder)
|
||||||
->setRules($config)
|
->setRules($config)
|
||||||
->setRiskyAllowed(true)
|
->setRiskyAllowed(true)
|
||||||
->setCacheFile(__DIR__ . '/.php_cs.cache');
|
->setCacheFile(__DIR__ . '/.php-cs-fixer.cache');
|
||||||
@@ -5,7 +5,7 @@ $finder = PhpCsFixer\Finder::create()
|
|||||||
->in(__DIR__ . '/tests')
|
->in(__DIR__ . '/tests')
|
||||||
->exclude('__snapshots__');
|
->exclude('__snapshots__');
|
||||||
|
|
||||||
$config = require __DIR__ . '/.php_cs.common.php';
|
$config = require __DIR__ . '/.php-cs-fixer.common.php';
|
||||||
|
|
||||||
// Additional rules for tests
|
// Additional rules for tests
|
||||||
$config = array_merge(
|
$config = array_merge(
|
||||||
@@ -15,8 +15,8 @@ $config = array_merge(
|
|||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
return PhpCsFixer\Config::create()
|
return (new PhpCsFixer\Config())
|
||||||
->setFinder($finder)
|
->setFinder($finder)
|
||||||
->setRules($config)
|
->setRules($config)
|
||||||
->setRiskyAllowed(true)
|
->setRiskyAllowed(true)
|
||||||
->setCacheFile(__DIR__ . '/.php_cs.tests.cache');
|
->setCacheFile(__DIR__ . '/.php-cs-fixer.tests.cache');
|
||||||
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
|
|||||||
[Next release](https://github.com/barryvdh/laravel-ide-helper/compare/v2.14.0...master)
|
[Next release](https://github.com/barryvdh/laravel-ide-helper/compare/v2.14.0...master)
|
||||||
--------------
|
--------------
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- 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)
|
||||||
|
|
||||||
2024-02-05, 2.14.0
|
2024-02-05, 2.14.0
|
||||||
------------------
|
------------------
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
This package generates helper files that enable your IDE to provide accurate autocompletion.
|
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.
|
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+
|
It supports Laravel 9+ and PHP 8.0+
|
||||||
|
|
||||||
- [Installation](#installation)
|
- [Installation](#installation)
|
||||||
- [Usage](#usage)
|
- [Usage](#usage)
|
||||||
@@ -72,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!_
|
_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: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)
|
- `php artisan ide-helper:meta` - [PhpStorm Meta file](#phpstorm-meta-for-container-instances)
|
||||||
|
|
||||||
|
|
||||||
@@ -113,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.
|
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.
|
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.
|
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.
|
The `Illuminate/Support/helpers.php` is already set up, but you can add/remove your own files in the config file.
|
||||||
|
|
||||||
@@ -145,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.
|
> 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.
|
Writing to the models should keep the existing comments and only append new properties/methods. It will not update changed 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.
|
With the `--reset (-R)` option, the whole existing PHPDoc is replaced, including any comments that have been made. The `--smart-reset` option will instead keep the 'text' part of the phpdoc comment, and just replace all the property/method defininitions.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
php artisan ide-helper:models "App\Models\Post"
|
php artisan ide-helper:models "App\Models\Post"
|
||||||
|
|||||||
+12
-12
@@ -20,26 +20,26 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^7.3 || ^8.0",
|
"php": "^8.0",
|
||||||
"ext-json": "*",
|
"ext-json": "*",
|
||||||
"barryvdh/reflection-docblock": "^2.0.6",
|
"barryvdh/reflection-docblock": "^2.0.6",
|
||||||
"composer/class-map-generator": "^1.0",
|
"composer/class-map-generator": "^1.0",
|
||||||
"doctrine/dbal": "^2.6 || ^3",
|
"doctrine/dbal": "^2.6 || ^3.1.4",
|
||||||
"illuminate/console": "^8 || ^9 || ^10",
|
"illuminate/console": "^9 || ^10",
|
||||||
"illuminate/filesystem": "^8 || ^9 || ^10",
|
"illuminate/filesystem": "^9 || ^10",
|
||||||
"illuminate/support": "^8 || ^9 || ^10",
|
"illuminate/support": "^9 || ^10",
|
||||||
"nikic/php-parser": "^4.18 || ^5",
|
"nikic/php-parser": "^4.18 || ^5",
|
||||||
"phpdocumentor/type-resolver": "^1.1.0"
|
"phpdocumentor/type-resolver": "^1.1.0"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"ext-pdo_sqlite": "*",
|
"ext-pdo_sqlite": "*",
|
||||||
"friendsofphp/php-cs-fixer": "^2",
|
"friendsofphp/php-cs-fixer": "^3",
|
||||||
"illuminate/config": "^8 || ^9 || ^10",
|
"illuminate/config": "^9 || ^10",
|
||||||
"illuminate/view": "^8 || ^9 || ^10",
|
"illuminate/view": "^9 || ^10",
|
||||||
"mockery/mockery": "^1.4",
|
"mockery/mockery": "^1.4",
|
||||||
"orchestra/testbench": "^6 || ^7 || ^8",
|
"orchestra/testbench": "^7 || ^8",
|
||||||
"phpunit/phpunit": "^8.5 || ^9",
|
"phpunit/phpunit": "^9",
|
||||||
"spatie/phpunit-snapshot-assertions": "^3 || ^4",
|
"spatie/phpunit-snapshot-assertions": "^4",
|
||||||
"vimeo/psalm": "^5.4"
|
"vimeo/psalm": "^5.4"
|
||||||
},
|
},
|
||||||
"suggest": {
|
"suggest": {
|
||||||
@@ -81,7 +81,7 @@
|
|||||||
],
|
],
|
||||||
"fix-style": [
|
"fix-style": [
|
||||||
"php-cs-fixer fix",
|
"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",
|
"psalm-set-baseline": "psalm --set-baseline=psalm-baseline.xml",
|
||||||
"test": "phpunit",
|
"test": "phpunit",
|
||||||
|
|||||||
@@ -16,4 +16,9 @@
|
|||||||
<code>\Storage</code>
|
<code>\Storage</code>
|
||||||
</UndefinedClass>
|
</UndefinedClass>
|
||||||
</file>
|
</file>
|
||||||
|
<file src="src/Console/ModelsCommand.php">
|
||||||
|
<UndefinedClass occurrences="1">
|
||||||
|
<code>\UnitEnum</code>
|
||||||
|
</UndefinedClass>
|
||||||
|
</file>
|
||||||
</files>
|
</files>
|
||||||
|
|||||||
+21
-13
@@ -8,6 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
/* @noinspection ALL */
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
// phpcs:ignoreFile
|
// phpcs:ignoreFile
|
||||||
|
|
||||||
@@ -22,15 +23,12 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
<?php foreach ($namespaces_by_extends_ns as $namespace => $aliases) : ?>
|
<?php foreach ($namespaces_by_extends_ns as $namespace => $aliases) : ?>
|
||||||
<?php if ($namespace == '\Illuminate\Database\Eloquent') :
|
namespace <?= $namespace == '__root' ? '' : trim($namespace, '\\') ?> {
|
||||||
continue;
|
|
||||||
endif; ?>
|
|
||||||
namespace <?= $namespace == '__root' ? '' : trim($namespace, '\\') ?> {
|
|
||||||
<?php foreach ($aliases as $alias) : ?>
|
<?php foreach ($aliases as $alias) : ?>
|
||||||
<?= trim($alias->getDocComment(' ')) ?>
|
<?= trim($alias->getDocComment(' ')) ?>
|
||||||
<?= $alias->getClassType() ?> <?= $alias->getExtendsClass() ?> {
|
<?= $alias->getClassType() ?> <?= $alias->getExtendsClass() ?> {
|
||||||
<?php foreach ($alias->getMethods() as $method) : ?>
|
<?php foreach ($alias->getMethods() as $method) : ?>
|
||||||
<?= trim($method->getDocComment(' ')) ?>
|
<?= trim($method->getDocComment(' ')) ?>
|
||||||
public static function <?= $method->getName() ?>(<?= $method->getParamsWithDefault() ?>)
|
public static function <?= $method->getName() ?>(<?= $method->getParamsWithDefault() ?>)
|
||||||
{<?php if ($method->getDeclaringClass() !== $method->getRoot()) : ?>
|
{<?php if ($method->getDeclaringClass() !== $method->getRoot()) : ?>
|
||||||
//Method inherited from <?= $method->getDeclaringClass() ?>
|
//Method inherited from <?= $method->getDeclaringClass() ?>
|
||||||
@@ -41,19 +39,19 @@ namespace <?= $namespace == '__root' ? '' : trim($namespace, '\\') ?> {
|
|||||||
<?php endif?>
|
<?php endif?>
|
||||||
<?= $method->shouldReturn() ? 'return ' : '' ?><?= $method->getRootMethodCall() ?>;
|
<?= $method->shouldReturn() ? 'return ' : '' ?><?= $method->getRootMethodCall() ?>;
|
||||||
}
|
}
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
}
|
}
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
}
|
}
|
||||||
|
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
|
||||||
<?php foreach ($namespaces_by_alias_ns as $namespace => $aliases) : ?>
|
<?php foreach ($namespaces_by_alias_ns as $namespace => $aliases) : ?>
|
||||||
namespace <?= $namespace == '__root' ? '' : trim($namespace, '\\') ?> {
|
namespace <?= $namespace == '__root' ? '' : trim($namespace, '\\') ?> {
|
||||||
<?php foreach ($aliases as $alias) : ?>
|
<?php foreach ($aliases as $alias) : ?>
|
||||||
<?= $alias->getClassType() ?> <?= $alias->getShortName() ?> extends <?= $alias->getExtends() ?> {<?php if ($alias->getExtendsNamespace() == '\Illuminate\Database\Eloquent') : ?>
|
<?= $alias->getClassType() ?> <?= $alias->getShortName() ?> extends <?= $alias->getExtends() ?> {<?php if ($alias->getExtendsNamespace() == '\Illuminate\Database\Eloquent') : ?>
|
||||||
<?php foreach ($alias->getMethods() as $method) : ?>
|
<?php foreach ($alias->getMethods() as $method) : ?>
|
||||||
<?= trim($method->getDocComment(' ')) ?>
|
<?= trim($method->getDocComment(' ')) ?>
|
||||||
public static function <?= $method->getName() ?>(<?= $method->getParamsWithDefault() ?>)
|
public static function <?= $method->getName() ?>(<?= $method->getParamsWithDefault() ?>)
|
||||||
{<?php if ($method->getDeclaringClass() !== $method->getRoot()) : ?>
|
{<?php if ($method->getDeclaringClass() !== $method->getRoot()) : ?>
|
||||||
//Method inherited from <?= $method->getDeclaringClass() ?>
|
//Method inherited from <?= $method->getDeclaringClass() ?>
|
||||||
@@ -66,14 +64,24 @@ namespace <?= $namespace == '__root' ? '' : trim($namespace, '\\') ?> {
|
|||||||
}
|
}
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
<?php endif; ?>}
|
<?php endif; ?>}
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
}
|
}
|
||||||
|
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
|
||||||
|
<?php foreach($real_time_facades as $name): ?>
|
||||||
|
<?php $nested = explode('\\', str_replace('\\' . class_basename($name), '', $name)); ?>
|
||||||
|
namespace <?php echo implode('\\', $nested); ?> {
|
||||||
|
/**
|
||||||
|
* @mixin <?= str_replace('Facades', '', $name) ?>
|
||||||
|
*/
|
||||||
|
class <?= class_basename($name) ?> extends <?= str_replace('Facades', '', $name) ?> {}
|
||||||
|
}
|
||||||
|
<?php endforeach; ?>
|
||||||
|
|
||||||
<?php if ($helpers) : ?>
|
<?php if ($helpers) : ?>
|
||||||
namespace {
|
namespace {
|
||||||
<?= $helpers ?>
|
<?= $helpers ?>
|
||||||
}
|
}
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
<?= '<?php' ?>
|
<?= '<?php' ?>
|
||||||
|
|
||||||
|
/* @noinspection ALL */
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
|
// phpcs:ignoreFile
|
||||||
|
|
||||||
namespace PHPSTORM_META {
|
namespace PHPSTORM_META {
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -329,7 +329,7 @@ class Alias
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$method = new \ReflectionMethod($className, $name);
|
$method = new \ReflectionMethod($className, $name);
|
||||||
$class = new \ReflectionClass($className);
|
$class = new ReflectionClass($className);
|
||||||
|
|
||||||
if (!in_array($magic, $this->usedMethods)) {
|
if (!in_array($magic, $this->usedMethods)) {
|
||||||
if ($class !== $this->root) {
|
if ($class !== $this->root) {
|
||||||
@@ -348,7 +348,7 @@ class Alias
|
|||||||
protected function detectMethods()
|
protected function detectMethods()
|
||||||
{
|
{
|
||||||
foreach ($this->classes as $class) {
|
foreach ($this->classes as $class) {
|
||||||
$reflection = new \ReflectionClass($class);
|
$reflection = new ReflectionClass($class);
|
||||||
|
|
||||||
$methods = $reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
|
$methods = $reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
|
||||||
if ($methods) {
|
if ($methods) {
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class GeneratorCommand extends Command
|
|||||||
/** @var \Illuminate\Config\Repository */
|
/** @var \Illuminate\Config\Repository */
|
||||||
protected $config;
|
protected $config;
|
||||||
|
|
||||||
/** @var \Illuminate\Filesystem\Filesystem */
|
/** @var Filesystem */
|
||||||
protected $files;
|
protected $files;
|
||||||
|
|
||||||
/** @var \Illuminate\View\Factory */
|
/** @var \Illuminate\View\Factory */
|
||||||
@@ -54,7 +54,7 @@ class GeneratorCommand extends Command
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Config\Repository $config
|
* @param \Illuminate\Config\Repository $config
|
||||||
* @param \Illuminate\Filesystem\Filesystem $files
|
* @param Filesystem $files
|
||||||
* @param \Illuminate\View\Factory $view
|
* @param \Illuminate\View\Factory $view
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
|
|||||||
@@ -266,6 +266,7 @@ class ModelsCommand extends Command
|
|||||||
}
|
}
|
||||||
$this->properties = [];
|
$this->properties = [];
|
||||||
$this->methods = [];
|
$this->methods = [];
|
||||||
|
$this->foreignKeyConstraintsColumns = [];
|
||||||
if (class_exists($name)) {
|
if (class_exists($name)) {
|
||||||
try {
|
try {
|
||||||
// handle abstract classes, interfaces, ...
|
// handle abstract classes, interfaces, ...
|
||||||
@@ -354,7 +355,7 @@ class ModelsCommand extends Command
|
|||||||
/**
|
/**
|
||||||
* cast the properties's type from $casts.
|
* cast the properties's type from $casts.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Database\Eloquent\Model $model
|
* @param Model $model
|
||||||
*/
|
*/
|
||||||
public function castPropertiesType($model)
|
public function castPropertiesType($model)
|
||||||
{
|
{
|
||||||
@@ -498,7 +499,7 @@ class ModelsCommand extends Command
|
|||||||
/**
|
/**
|
||||||
* Load the properties from the database table.
|
* Load the properties from the database table.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Database\Eloquent\Model $model
|
* @param Model $model
|
||||||
*
|
*
|
||||||
* @throws DBALException If custom field failed to register
|
* @throws DBALException If custom field failed to register
|
||||||
*/
|
*/
|
||||||
@@ -602,7 +603,7 @@ class ModelsCommand extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Illuminate\Database\Eloquent\Model $model
|
* @param Model $model
|
||||||
*/
|
*/
|
||||||
public function getPropertiesFromMethods($model)
|
public function getPropertiesFromMethods($model)
|
||||||
{
|
{
|
||||||
@@ -777,7 +778,7 @@ class ModelsCommand extends Command
|
|||||||
'int|null',
|
'int|null',
|
||||||
true,
|
true,
|
||||||
false
|
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 (
|
} elseif (
|
||||||
@@ -1099,6 +1100,8 @@ class ModelsCommand extends Command
|
|||||||
$default = 'null';
|
$default = 'null';
|
||||||
} elseif (is_int($default)) {
|
} elseif (is_int($default)) {
|
||||||
//$default = $default;
|
//$default = $default;
|
||||||
|
} elseif ($default instanceof \UnitEnum) {
|
||||||
|
$default = '\\' . get_class($default) . '::' . $default->name;
|
||||||
} else {
|
} else {
|
||||||
$default = "'" . trim($default) . "'";
|
$default = "'" . trim($default) . "'";
|
||||||
}
|
}
|
||||||
@@ -1126,7 +1129,7 @@ class ModelsCommand extends Command
|
|||||||
return '\Illuminate\Database\Eloquent\Collection';
|
return '\Illuminate\Database\Eloquent\Collection';
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var \Illuminate\Database\Eloquent\Model $model */
|
/** @var Model $model */
|
||||||
$model = new $className();
|
$model = new $className();
|
||||||
return '\\' . get_class($model->newCollection());
|
return '\\' . get_class($model->newCollection());
|
||||||
}
|
}
|
||||||
@@ -1285,7 +1288,7 @@ class ModelsCommand extends Command
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates methods provided by the SoftDeletes trait
|
* Generates methods provided by the SoftDeletes trait
|
||||||
* @param \Illuminate\Database\Eloquent\Model $model
|
* @param Model $model
|
||||||
*/
|
*/
|
||||||
protected function getSoftDeleteMethods($model)
|
protected function getSoftDeleteMethods($model)
|
||||||
{
|
{
|
||||||
@@ -1302,7 +1305,7 @@ class ModelsCommand extends Command
|
|||||||
/**
|
/**
|
||||||
* Generate factory method from "HasFactory" trait.
|
* Generate factory method from "HasFactory" trait.
|
||||||
*
|
*
|
||||||
* @param \Illuminate\Database\Eloquent\Model $model
|
* @param Model $model
|
||||||
*/
|
*/
|
||||||
protected function getFactoryMethods($model)
|
protected function getFactoryMethods($model)
|
||||||
{
|
{
|
||||||
@@ -1330,16 +1333,12 @@ class ModelsCommand extends Command
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (version_compare($this->laravel->version(), '9', '>=')) {
|
$this->setMethod('factory', $factory, ['$count = null, $state = []']);
|
||||||
$this->setMethod('factory', $factory, ['$count = null, $state = []']);
|
|
||||||
} else {
|
|
||||||
$this->setMethod('factory', $factory, ['...$parameters']);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates methods that return collections
|
* Generates methods that return collections
|
||||||
* @param \Illuminate\Database\Eloquent\Model $model
|
* @param Model $model
|
||||||
*/
|
*/
|
||||||
protected function getCollectionMethods($model)
|
protected function getCollectionMethods($model)
|
||||||
{
|
{
|
||||||
@@ -1382,7 +1381,7 @@ class ModelsCommand extends Command
|
|||||||
return $type;
|
return $type;
|
||||||
}
|
}
|
||||||
|
|
||||||
$reflection = new \ReflectionClass($type);
|
$reflection = new ReflectionClass($type);
|
||||||
|
|
||||||
if (!$reflection->implementsInterface(Castable::class)) {
|
if (!$reflection->implementsInterface(Castable::class)) {
|
||||||
return $type;
|
return $type;
|
||||||
@@ -1414,7 +1413,7 @@ class ModelsCommand extends Command
|
|||||||
return $type;
|
return $type;
|
||||||
}
|
}
|
||||||
|
|
||||||
$reflection = new \ReflectionClass($type);
|
$reflection = new ReflectionClass($type);
|
||||||
|
|
||||||
if (!$reflection->implementsInterface(CastsAttributes::class)) {
|
if (!$reflection->implementsInterface(CastsAttributes::class)) {
|
||||||
return $type;
|
return $type;
|
||||||
@@ -1620,7 +1619,7 @@ class ModelsCommand extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Illuminate\Database\Eloquent\Model $model
|
* @param Model $model
|
||||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||||
* @throws \RuntimeException
|
* @throws \RuntimeException
|
||||||
*/
|
*/
|
||||||
|
|||||||
+61
-3
@@ -13,8 +13,13 @@ namespace Barryvdh\LaravelIdeHelper;
|
|||||||
|
|
||||||
use Illuminate\Foundation\AliasLoader;
|
use Illuminate\Foundation\AliasLoader;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
use Illuminate\Support\Facades\Facade;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Illuminate\Support\Traits\Macroable;
|
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 ReflectionClass;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
@@ -26,7 +31,7 @@ class Generator
|
|||||||
/** @var \Illuminate\View\Factory */
|
/** @var \Illuminate\View\Factory */
|
||||||
protected $view;
|
protected $view;
|
||||||
|
|
||||||
/** @var \Symfony\Component\Console\Output\OutputInterface */
|
/** @var OutputInterface */
|
||||||
protected $output;
|
protected $output;
|
||||||
|
|
||||||
protected $extra = [];
|
protected $extra = [];
|
||||||
@@ -37,7 +42,7 @@ class Generator
|
|||||||
/**
|
/**
|
||||||
* @param \Illuminate\Config\Repository $config
|
* @param \Illuminate\Config\Repository $config
|
||||||
* @param \Illuminate\View\Factory $view
|
* @param \Illuminate\View\Factory $view
|
||||||
* @param \Symfony\Component\Console\Output\OutputInterface $output
|
* @param OutputInterface $output
|
||||||
* @param string $helpers
|
* @param string $helpers
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
@@ -75,6 +80,7 @@ class Generator
|
|||||||
return $this->view->make('helper')
|
return $this->view->make('helper')
|
||||||
->with('namespaces_by_extends_ns', $this->getAliasesByExtendsNamespace())
|
->with('namespaces_by_extends_ns', $this->getAliasesByExtendsNamespace())
|
||||||
->with('namespaces_by_alias_ns', $this->getAliasesByAliasNamespace())
|
->with('namespaces_by_alias_ns', $this->getAliasesByAliasNamespace())
|
||||||
|
->with('real_time_facades', $this->getRealTimeFacades())
|
||||||
->with('helpers', $this->helpers)
|
->with('helpers', $this->helpers)
|
||||||
->with('version', $app->version())
|
->with('version', $app->version())
|
||||||
->with('include_fluent', $this->config->get('ide-helper.include_fluent', true))
|
->with('include_fluent', $this->config->get('ide-helper.include_fluent', true))
|
||||||
@@ -153,6 +159,11 @@ class Generator
|
|||||||
continue;
|
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] : [];
|
$magicMethods = array_key_exists($name, $this->magic) ? $this->magic[$name] : [];
|
||||||
$alias = new Alias($this->config, $name, $facade, $magicMethods, $this->interfaces);
|
$alias = new Alias($this->config, $name, $facade, $magicMethods, $this->interfaces);
|
||||||
if ($alias->isValid()) {
|
if ($alias->isValid()) {
|
||||||
@@ -168,6 +179,51 @@ class Generator
|
|||||||
return $aliases;
|
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
|
* Regroup aliases by namespace of extended classes
|
||||||
*
|
*
|
||||||
@@ -175,7 +231,9 @@ class Generator
|
|||||||
*/
|
*/
|
||||||
protected function getAliasesByExtendsNamespace()
|
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);
|
$this->addMacroableClasses($aliases);
|
||||||
|
|
||||||
|
|||||||
@@ -16,15 +16,15 @@ class GenerateModelHelper
|
|||||||
*/
|
*/
|
||||||
public static $shouldRun = false;
|
public static $shouldRun = false;
|
||||||
|
|
||||||
/** @var \Illuminate\Contracts\Console\Kernel */
|
/** @var Artisan */
|
||||||
protected $artisan;
|
protected $artisan;
|
||||||
|
|
||||||
/** @var \Illuminate\Contracts\Config\Repository */
|
/** @var Config */
|
||||||
protected $config;
|
protected $config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Illuminate\Contracts\Console\Kernel $artisan
|
* @param Artisan $artisan
|
||||||
* @param \Illuminate\Contracts\Config\Repository $config
|
* @param Config $config
|
||||||
*/
|
*/
|
||||||
public function __construct(Artisan $artisan, Config $config)
|
public function __construct(Artisan $artisan, Config $config)
|
||||||
{
|
{
|
||||||
|
|||||||
+1
-1
@@ -22,7 +22,7 @@ use Illuminate\Support\Str;
|
|||||||
|
|
||||||
class Method
|
class Method
|
||||||
{
|
{
|
||||||
/** @var \Barryvdh\Reflection\DocBlock */
|
/** @var DocBlock */
|
||||||
protected $phpdoc;
|
protected $phpdoc;
|
||||||
|
|
||||||
/** @var \ReflectionMethod */
|
/** @var \ReflectionMethod */
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class Simple extends Model
|
|||||||
* phpdoc is ignored here deliberately due to performance reasons and also
|
* phpdoc is ignored here deliberately due to performance reasons and also
|
||||||
* isn't supported by Laravel itself.
|
* isn't supported by Laravel itself.
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Database\Eloquent\Casts\Attribute
|
* @return Attribute
|
||||||
*/
|
*/
|
||||||
protected function notAnAttribute()
|
protected function notAnAttribute()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,15 +9,6 @@ use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
|||||||
|
|
||||||
class Test extends 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
|
public function test(): void
|
||||||
{
|
{
|
||||||
$command = $this->app->make(ModelsCommand::class);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ class Simple extends Model
|
|||||||
* phpdoc is ignored here deliberately due to performance reasons and also
|
* phpdoc is ignored here deliberately due to performance reasons and also
|
||||||
* isn't supported by Laravel itself.
|
* isn't supported by Laravel itself.
|
||||||
*
|
*
|
||||||
* @return \Illuminate\Database\Eloquent\Casts\Attribute
|
* @return Attribute
|
||||||
*/
|
*/
|
||||||
protected function notAnAttribute()
|
protected function notAnAttribute()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,19 +17,11 @@ class Test extends AbstractModelsCommand
|
|||||||
'--write' => true,
|
'--write' => true,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (PHP_VERSION_ID >= 80000) {
|
$errors = [
|
||||||
$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: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: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',
|
||||||
'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",
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->assertSame(0, $tester->getStatusCode());
|
$this->assertSame(0, $tester->getStatusCode());
|
||||||
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
|
||||||
|
|||||||
@@ -8,41 +8,12 @@ use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
|||||||
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
||||||
use Closure;
|
use Closure;
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
use Illuminate\Foundation\Application;
|
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class Test extends AbstractModelsCommand
|
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());
|
Factory::guessFactoryNamesUsing(static::getFactoryNameResolver());
|
||||||
|
|
||||||
$command = $this->app->make(ModelsCommand::class);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|||||||
@@ -1,94 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Models;
|
|
||||||
|
|
||||||
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\CustomSpace\ModelWithCustomNamespaceFactory;
|
|
||||||
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(...$parameters)
|
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithCustomNamespace newModelQuery()
|
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithCustomNamespace newQuery()
|
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithCustomNamespace query()
|
|
||||||
* @mixin \Eloquent
|
|
||||||
*/
|
|
||||||
class ModelWithCustomNamespace extends Model
|
|
||||||
{
|
|
||||||
use HasFactory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new factory instance for the model.
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Database\Eloquent\Factories\Factory
|
|
||||||
*/
|
|
||||||
protected static function newFactory()
|
|
||||||
{
|
|
||||||
return ModelWithCustomNamespaceFactory::new();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Models;
|
|
||||||
|
|
||||||
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(...$parameters)
|
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithFactory newModelQuery()
|
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithFactory newQuery()
|
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithFactory query()
|
|
||||||
* @mixin \Eloquent
|
|
||||||
*/
|
|
||||||
class ModelWithFactory extends Model
|
|
||||||
{
|
|
||||||
use HasFactory;
|
|
||||||
}
|
|
||||||
<?php
|
|
||||||
|
|
||||||
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(...$parameters)
|
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithNestedFactory newModelQuery()
|
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithNestedFactory newQuery()
|
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithNestedFactory query()
|
|
||||||
* @mixin \Eloquent
|
|
||||||
*/
|
|
||||||
class ModelWithNestedFactory extends ModelWithFactory
|
|
||||||
{
|
|
||||||
}
|
|
||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Models;
|
|
||||||
|
|
||||||
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()
|
|
||||||
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithoutFactory query()
|
|
||||||
* @mixin \Eloquent
|
|
||||||
*/
|
|
||||||
class ModelWithoutFactory extends Model
|
|
||||||
{
|
|
||||||
use HasFactory;
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpDocWithEnumDefaults\Enums;
|
||||||
|
|
||||||
|
enum PostStatus
|
||||||
|
{
|
||||||
|
case Published;
|
||||||
|
|
||||||
|
case Unpublished;
|
||||||
|
|
||||||
|
case Archived;
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpDocWithEnumDefaults\Models;
|
||||||
|
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpDocWithEnumDefaults\Enums\PostStatus;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Post extends Model
|
||||||
|
{
|
||||||
|
public function scopeHasStatus(Builder $query, ?PostStatus $status = PostStatus::Published)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpDocWithEnumDefaults;
|
||||||
|
|
||||||
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
||||||
|
|
||||||
|
class Test extends AbstractModelsCommand
|
||||||
|
{
|
||||||
|
public function test(): void
|
||||||
|
{
|
||||||
|
if (!version_compare(PHP_VERSION, '8.1', '>=')) {
|
||||||
|
$this->markTestSkipped(
|
||||||
|
'This test only works in PHP >= 8.1'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$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->assertMatchesMockedSnapshot();
|
||||||
|
}
|
||||||
|
}
|
||||||
+172
@@ -0,0 +1,172 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpDocWithEnumDefaults\Models;
|
||||||
|
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpDocWithEnumDefaults\Enums\PostStatus;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpDocWithEnumDefaults\Models\Post
|
||||||
|
*
|
||||||
|
* @property integer $id
|
||||||
|
* @property string|null $char_nullable
|
||||||
|
* @property string $char_not_nullable
|
||||||
|
* @property string|null $string_nullable
|
||||||
|
* @property string $string_not_nullable
|
||||||
|
* @property string|null $text_nullable
|
||||||
|
* @property string $text_not_nullable
|
||||||
|
* @property string|null $medium_text_nullable
|
||||||
|
* @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 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 string|null $enum_nullable
|
||||||
|
* @property string $enum_not_nullable
|
||||||
|
* @property string|null $json_nullable
|
||||||
|
* @property string $json_not_nullable
|
||||||
|
* @property string|null $jsonb_nullable
|
||||||
|
* @property string $jsonb_not_nullable
|
||||||
|
* @property string|null $date_nullable
|
||||||
|
* @property string $date_not_nullable
|
||||||
|
* @property string|null $datetime_nullable
|
||||||
|
* @property string $datetime_not_nullable
|
||||||
|
* @property string|null $datetimetz_nullable
|
||||||
|
* @property string $datetimetz_not_nullable
|
||||||
|
* @property string|null $time_nullable
|
||||||
|
* @property string $time_not_nullable
|
||||||
|
* @property string|null $timetz_nullable
|
||||||
|
* @property string $timetz_not_nullable
|
||||||
|
* @property string|null $timestamp_nullable
|
||||||
|
* @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 string|null $uuid_nullable
|
||||||
|
* @property string $uuid_not_nullable
|
||||||
|
* @property string|null $ipaddress_nullable
|
||||||
|
* @property string $ipaddress_not_nullable
|
||||||
|
* @property string|null $macaddress_nullable
|
||||||
|
* @property string $macaddress_not_nullable
|
||||||
|
* @property \Illuminate\Support\Carbon|null $created_at
|
||||||
|
* @property \Illuminate\Support\Carbon|null $updated_at
|
||||||
|
* @method static Builder|Post hasStatus(?\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpDocWithEnumDefaults\Enums\PostStatus $status = \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpDocWithEnumDefaults\Enums\PostStatus::Published)
|
||||||
|
* @method static Builder|Post newModelQuery()
|
||||||
|
* @method static Builder|Post newQuery()
|
||||||
|
* @method static Builder|Post query()
|
||||||
|
* @method static Builder|Post whereBigIntegerNotNullable($value)
|
||||||
|
* @method static Builder|Post whereBigIntegerNullable($value)
|
||||||
|
* @method static Builder|Post whereBinaryNotNullable($value)
|
||||||
|
* @method static Builder|Post whereBinaryNullable($value)
|
||||||
|
* @method static Builder|Post whereBooleanNotNullable($value)
|
||||||
|
* @method static Builder|Post whereBooleanNullable($value)
|
||||||
|
* @method static Builder|Post whereCharNotNullable($value)
|
||||||
|
* @method static Builder|Post whereCharNullable($value)
|
||||||
|
* @method static Builder|Post whereCreatedAt($value)
|
||||||
|
* @method static Builder|Post whereDateNotNullable($value)
|
||||||
|
* @method static Builder|Post whereDateNullable($value)
|
||||||
|
* @method static Builder|Post whereDatetimeNotNullable($value)
|
||||||
|
* @method static Builder|Post whereDatetimeNullable($value)
|
||||||
|
* @method static Builder|Post whereDatetimetzNotNullable($value)
|
||||||
|
* @method static Builder|Post whereDatetimetzNullable($value)
|
||||||
|
* @method static Builder|Post whereDecimalNotNullable($value)
|
||||||
|
* @method static Builder|Post whereDecimalNullable($value)
|
||||||
|
* @method static Builder|Post whereDoubleNotNullable($value)
|
||||||
|
* @method static Builder|Post whereDoubleNullable($value)
|
||||||
|
* @method static Builder|Post whereEnumNotNullable($value)
|
||||||
|
* @method static Builder|Post whereEnumNullable($value)
|
||||||
|
* @method static Builder|Post whereFloatNotNullable($value)
|
||||||
|
* @method static Builder|Post whereFloatNullable($value)
|
||||||
|
* @method static Builder|Post whereId($value)
|
||||||
|
* @method static Builder|Post whereIntegerNotNullable($value)
|
||||||
|
* @method static Builder|Post whereIntegerNullable($value)
|
||||||
|
* @method static Builder|Post whereIpaddressNotNullable($value)
|
||||||
|
* @method static Builder|Post whereIpaddressNullable($value)
|
||||||
|
* @method static Builder|Post whereJsonNotNullable($value)
|
||||||
|
* @method static Builder|Post whereJsonNullable($value)
|
||||||
|
* @method static Builder|Post whereJsonbNotNullable($value)
|
||||||
|
* @method static Builder|Post whereJsonbNullable($value)
|
||||||
|
* @method static Builder|Post whereLongTextNotNullable($value)
|
||||||
|
* @method static Builder|Post whereLongTextNullable($value)
|
||||||
|
* @method static Builder|Post whereMacaddressNotNullable($value)
|
||||||
|
* @method static Builder|Post whereMacaddressNullable($value)
|
||||||
|
* @method static Builder|Post whereMediumIntegerNotNullable($value)
|
||||||
|
* @method static Builder|Post whereMediumIntegerNullable($value)
|
||||||
|
* @method static Builder|Post whereMediumTextNotNullable($value)
|
||||||
|
* @method static Builder|Post whereMediumTextNullable($value)
|
||||||
|
* @method static Builder|Post whereSmallIntegerNotNullable($value)
|
||||||
|
* @method static Builder|Post whereSmallIntegerNullable($value)
|
||||||
|
* @method static Builder|Post whereStringNotNullable($value)
|
||||||
|
* @method static Builder|Post whereStringNullable($value)
|
||||||
|
* @method static Builder|Post whereTextNotNullable($value)
|
||||||
|
* @method static Builder|Post whereTextNullable($value)
|
||||||
|
* @method static Builder|Post whereTimeNotNullable($value)
|
||||||
|
* @method static Builder|Post whereTimeNullable($value)
|
||||||
|
* @method static Builder|Post whereTimestampNotNullable($value)
|
||||||
|
* @method static Builder|Post whereTimestampNullable($value)
|
||||||
|
* @method static Builder|Post whereTimestamptzNotNullable($value)
|
||||||
|
* @method static Builder|Post whereTimestamptzNullable($value)
|
||||||
|
* @method static Builder|Post whereTimetzNotNullable($value)
|
||||||
|
* @method static Builder|Post whereTimetzNullable($value)
|
||||||
|
* @method static Builder|Post whereTinyIntegerNotNullable($value)
|
||||||
|
* @method static Builder|Post whereTinyIntegerNullable($value)
|
||||||
|
* @method static Builder|Post whereUnsignedBigIntegerNotNullable($value)
|
||||||
|
* @method static Builder|Post whereUnsignedBigIntegerNullable($value)
|
||||||
|
* @method static Builder|Post whereUnsignedDecimalNotNullable($value)
|
||||||
|
* @method static Builder|Post whereUnsignedDecimalNullable($value)
|
||||||
|
* @method static Builder|Post whereUnsignedIntegerNotNullable($value)
|
||||||
|
* @method static Builder|Post whereUnsignedIntegerNullable($value)
|
||||||
|
* @method static Builder|Post whereUnsignedMediumIntegerNotNullable($value)
|
||||||
|
* @method static Builder|Post whereUnsignedMediumIntegerNullable($value)
|
||||||
|
* @method static Builder|Post whereUnsignedSmallIntegerNotNullable($value)
|
||||||
|
* @method static Builder|Post whereUnsignedSmallIntegerNullable($value)
|
||||||
|
* @method static Builder|Post whereUnsignedTinyIntegerNotNullable($value)
|
||||||
|
* @method static Builder|Post whereUnsignedTinyIntegerNullable($value)
|
||||||
|
* @method static Builder|Post whereUpdatedAt($value)
|
||||||
|
* @method static Builder|Post whereUuidNotNullable($value)
|
||||||
|
* @method static Builder|Post whereUuidNullable($value)
|
||||||
|
* @method static Builder|Post whereYearNotNullable($value)
|
||||||
|
* @method static Builder|Post whereYearNullable($value)
|
||||||
|
* @mixin \Eloquent
|
||||||
|
*/
|
||||||
|
class Post extends Model
|
||||||
|
{
|
||||||
|
public function scopeHasStatus(Builder $query, ?PostStatus $status = PostStatus::Published)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -11,7 +11,7 @@ class CastableReturnsAnonymousCaster implements Castable
|
|||||||
{
|
{
|
||||||
public static function castUsing(array $arguments)
|
public static function castUsing(array $arguments)
|
||||||
{
|
{
|
||||||
return new class() implements CastsAttributes {
|
return new class () implements CastsAttributes {
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
* @return CastedProperty
|
* @return CastedProperty
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class CastableWithoutReturnType implements Castable
|
|||||||
{
|
{
|
||||||
public static function castUsing(array $arguments)
|
public static function castUsing(array $arguments)
|
||||||
{
|
{
|
||||||
return new class() implements CastsAttributes {
|
return new class () implements CastsAttributes {
|
||||||
public function get($model, string $key, $value, array $attributes)
|
public function get($model, string $key, $value, array $attributes)
|
||||||
{
|
{
|
||||||
return new CastedProperty();
|
return new CastedProperty();
|
||||||
|
|||||||
+1
-1
@@ -10,7 +10,7 @@ class CustomCasterWithDocblockReturnFqn implements CastsAttributes
|
|||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
* @return \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CastedProperty
|
* @return CastedProperty
|
||||||
*/
|
*/
|
||||||
public function get($model, string $key, $value, array $attributes)
|
public function get($model, string $key, $value, array $attributes)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,15 +9,6 @@ use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
|||||||
|
|
||||||
class Test extends 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
|
public function test(): void
|
||||||
{
|
{
|
||||||
$command = $this->app->make(ModelsCommand::class);
|
$command = $this->app->make(ModelsCommand::class);
|
||||||
|
|||||||
+2
-6
@@ -190,10 +190,6 @@ class MacroTest extends TestCase
|
|||||||
|
|
||||||
public function testInitPhpDocParamsWithUnionTypes(): void
|
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'
|
$phpdoc = (new MacroMock())->getPhpDoc(eval(<<<'PHP'
|
||||||
return new ReflectionFunction(
|
return new ReflectionFunction(
|
||||||
/**
|
/**
|
||||||
@@ -231,7 +227,7 @@ class MacroTest extends TestCase
|
|||||||
{
|
{
|
||||||
$reflectionMethod = new \ReflectionMethod(UrlGeneratorMacroClass::class, '__invoke');
|
$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);
|
$this->assertInstanceOf(Macro::class, $macro);
|
||||||
}
|
}
|
||||||
@@ -243,7 +239,7 @@ class MacroTest extends TestCase
|
|||||||
{
|
{
|
||||||
$reflectionMethod = new \ReflectionMethod(UrlGeneratorMacroClass::class, '__invoke');
|
$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'
|
$output = <<<'DOC'
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -0,0 +1,90 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests;
|
||||||
|
|
||||||
|
use Barryvdh\LaravelIdeHelper\Generator;
|
||||||
|
use Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider;
|
||||||
|
use Illuminate\Foundation\AliasLoader;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\View;
|
||||||
|
use PhpParser\Lexer\Emulative;
|
||||||
|
use PhpParser\Node\Stmt\Class_;
|
||||||
|
use PhpParser\Node\Stmt\Namespace_;
|
||||||
|
use PhpParser\Parser\Php7;
|
||||||
|
|
||||||
|
class RealTimeFacadesTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testRealTimeFacades()
|
||||||
|
{
|
||||||
|
// Add the views path to the view finder so the generator actually generates the file
|
||||||
|
View::addLocation(__DIR__ . '/../resources/views');
|
||||||
|
|
||||||
|
// Clear cached real-time facades
|
||||||
|
$cachedFacades = glob(storage_path('framework/cache/facade-*.php'));
|
||||||
|
foreach ($cachedFacades as $cachedFacade) {
|
||||||
|
unlink($cachedFacade);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy stubs to storage path as if the real-time facades were cached by the framework
|
||||||
|
copy(
|
||||||
|
__DIR__ . '/stubs/facade-0e0385307adf5db34c7986ecbd11646061356ec8.php',
|
||||||
|
storage_path('framework/cache/facade-0e0385307adf5db34c7986ecbd11646061356ec8.php')
|
||||||
|
);
|
||||||
|
copy(
|
||||||
|
__DIR__ . '/stubs/facade-9431b04ec1494fc71a1bc848f020044aba2af7b1.php',
|
||||||
|
storage_path('framework/cache/facade-9431b04ec1494fc71a1bc848f020044aba2af7b1.php')
|
||||||
|
);
|
||||||
|
|
||||||
|
// new instance of the generator which we test
|
||||||
|
$generator = new Generator($this->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];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Facades\Illuminate\Foundation\Exceptions;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Facade;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see \Illuminate\Foundation\Exceptions\Handler
|
||||||
|
*/
|
||||||
|
class Handler extends Facade
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the registered name of the component.
|
||||||
|
*/
|
||||||
|
protected static function getFacadeAccessor(): string
|
||||||
|
{
|
||||||
|
return 'Illuminate\Foundation\Exceptions\Handler';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Facades\App\Exceptions;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Facade;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see \App\Exceptions\Handler
|
||||||
|
*/
|
||||||
|
class Handler extends Facade
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the registered name of the component.
|
||||||
|
*/
|
||||||
|
protected static function getFacadeAccessor(): string
|
||||||
|
{
|
||||||
|
return 'App\Exceptions\Handler';
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user