Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@
"ext-json": "*",
"barryvdh/reflection-docblock": "^2.3",
"composer/class-map-generator": "^1.0",
"illuminate/console": "^11.15 || ^12",
"illuminate/database": "^11.15 || ^12",
"illuminate/filesystem": "^11.15 || ^12",
"illuminate/support": "^11.15 || ^12"
"illuminate/console": "^11.15 || ^12.4.1",
"illuminate/database": "^11.15 || ^12.4.1",
"illuminate/filesystem": "^11.15 || ^12.4.1",
"illuminate/support": "^11.15 || ^12.4.1"
},
"require-dev": {
"ext-pdo_sqlite": "*",
"friendsofphp/php-cs-fixer": "^3",
"illuminate/config": "^11.15 || ^12",
"illuminate/view": "^11.15 || ^12",
"illuminate/config": "^11.15 || ^12.4.1",
"illuminate/view": "^11.15 || ^12.4.1",
"mockery/mockery": "^1.4",
"orchestra/testbench": "^9.2 || ^10",
"phpunit/phpunit": "^10.5 || ^11.5.3",
Expand Down
4 changes: 2 additions & 2 deletions resources/views/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<?php foreach ($namespaces_by_extends_ns as $namespace => $aliases) : ?>
namespace <?= $namespace === '__root' ? '' : trim($namespace, '\\') ?> {
<?php foreach ($aliases as $alias) : ?>
<?php echo trim($alias->getDocComment($s1)) . "\n{$s1}" . $alias->getClassType() ?> <?= $alias->getExtendsClass() ?><?php if($alias->shouldExtendParentClass()): ?> extends <?= $alias->getParentClass() ?><?php endif; ?> {
<?php echo trim($alias->getDocComment($s1)) . "\n{$s1}" . $alias->getClassType() ?> <?= $alias->getExtendsClass() ?><?php if ($alias->shouldExtendParentClass()): ?> extends <?= $alias->getParentClass() ?><?php endif; ?> {
<?php foreach ($alias->getMethods() as $method) : ?>
<?= trim($method->getDocComment($s2)) . "\n{$s2}" ?>public static function <?= $method->getName() ?>(<?= $method->getParamsWithDefault() ?>)
{<?php if ($method->getDeclaringClass() !== $method->getRoot()) : ?>
Expand Down Expand Up @@ -76,7 +76,7 @@

<?php endforeach; ?>

<?php foreach($real_time_facades as $name): ?>
<?php foreach ($real_time_facades as $name): ?>
<?php $nested = explode('\\', str_replace('\\' . class_basename($name), '', $name)); ?>
namespace <?php echo implode('\\', $nested); ?> {
/**
Expand Down
2 changes: 1 addition & 1 deletion resources/views/meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@

<?php if (isset($expectedArgumentSets)): ?>
<?php foreach ($expectedArgumentSets as $name => $argumentsList) : ?>
registerArgumentsSet('<?= $name ?>', <?php foreach ($argumentsList as $i => $arg) : ?><?php if($i % 5 == 0) {
registerArgumentsSet('<?= $name ?>', <?php foreach ($argumentsList as $i => $arg) : ?><?php if ($i % 5 == 0) {
echo "\n";
} ?><?= var_export($arg, true); ?>,<?php endforeach; ?>);
<?php endforeach; ?>
Expand Down
6 changes: 4 additions & 2 deletions src/Console/ModelsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -669,9 +669,11 @@ public function getPropertiesFromMethods($model)
$comment = $this->getCommentFromDocBlock($reflection);
$this->setProperty($name, null, null, true, $comment);
}
} elseif (Str::startsWith($method, 'scope') && $method !== 'scopeQuery' && $method !== 'scope' && $method !== 'scopes') {
} elseif (!empty($reflection->getAttributes('Illuminate\Database\Eloquent\Attributes\Scope')) || (Str::startsWith($method, 'scope') && $method !== 'scopeQuery' && $method !== 'scope' && $method !== 'scopes')) {
$scopeUsingAttribute = !empty($reflection->getAttributes('Illuminate\Database\Eloquent\Attributes\Scope'));

//Magic scope<name>Attribute
$name = Str::camel(substr($method, 5));
$name = $scopeUsingAttribute ? $method : Str::camel(substr($method, 5));
if (!empty($name)) {
$comment = $this->getCommentFromDocBlock($reflection);
$args = $this->getParameters($reflection);
Expand Down
33 changes: 33 additions & 0 deletions tests/Console/ModelsCommand/QueryScopes/Models/Comment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\QueryScopes\Models;

use Illuminate\Database\Eloquent\Attributes\Scope;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

class Comment extends Model
{
/**
* @comment Scope using the 'Scope' attribute
* @param Builder $query
* @return void
*/
#[Scope]
protected function local(Builder $query): void
{
$query->where('ip_address', '127.0.0.1');
}

/**
* @comment Scope using the 'scope' prefix
* @param Builder $query
* @return void
*/
protected function scopeSystem(Builder $query): void
{
$query->where('system', true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,49 @@

namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\QueryScopes\Models;

use Illuminate\Database\Eloquent\Attributes\Scope;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

/**
*
*
* @method static Builder<static>|Comment local() Scope using the 'Scope' attribute
* @method static Builder<static>|Comment newModelQuery()
* @method static Builder<static>|Comment newQuery()
* @method static Builder<static>|Comment query()
* @method static Builder<static>|Comment system() Scope using the 'scope' prefix
* @mixin \Eloquent
*/
class Comment extends Model
{
/**
* @comment Scope using the 'Scope' attribute
* @param Builder $query
* @return void
*/
#[Scope]
protected function local(Builder $query): void
{
$query->where('ip_address', '127.0.0.1');
}

/**
* @comment Scope using the 'scope' prefix
* @param Builder $query
* @return void
*/
protected function scopeSystem(Builder $query): void
{
$query->where('system', true);
}
}
<?php

declare(strict_types=1);

namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\QueryScopes\Models;

/**
*
*
Expand Down