• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 13859510620

14 Mar 2025 03:07PM UTC coverage: 9.544% (-14.0%) from 23.51%
13859510620

push

github

soyuka
Merge 4.1

14 of 204 new or added lines in 25 files covered. (6.86%)

9 existing lines in 4 files now uncovered.

13387 of 140267 relevant lines covered (9.54%)

25.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Laravel/Eloquent/Extension/FilterQueryExtension.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\Laravel\Eloquent\Extension;
15

16
use ApiPlatform\Laravel\Eloquent\Filter\FilterInterface;
17
use ApiPlatform\Metadata\CollectionOperationInterface;
18
use ApiPlatform\Metadata\Operation;
19
use ApiPlatform\State\ParameterNotFound;
20
use Illuminate\Database\Eloquent\Builder;
21
use Illuminate\Database\Eloquent\Model;
22
use Psr\Container\ContainerInterface;
23

24
final readonly class FilterQueryExtension implements QueryExtensionInterface
25
{
26
    public function __construct(
27
        private ContainerInterface $filterLocator,
28
    ) {
29
    }
×
30

31
    /**
32
     * @param Builder<Model>        $builder
33
     * @param array<string, string> $uriVariables
34
     * @param array<string, mixed>  $context
35
     *
36
     * @return Builder<Model>
37
     */
38
    public function apply(Builder $builder, array $uriVariables, Operation $operation, $context = []): Builder
39
    {
NEW
40
        if (!$operation instanceof CollectionOperationInterface) {
×
NEW
41
            return $builder;
×
42
        }
43

44
        $context['uri_variables'] = $uriVariables;
×
45
        $context['operation'] = $operation;
×
46

47
        foreach ($operation->getParameters() ?? [] as $parameter) {
×
48
            if (null === ($values = $parameter->getValue()) || $values instanceof ParameterNotFound) {
×
49
                continue;
×
50
            }
51

52
            if (null === ($filterId = $parameter->getFilter())) {
×
53
                continue;
×
54
            }
55

56
            $filter = $filterId instanceof FilterInterface ? $filterId : ($this->filterLocator->has($filterId) ? $this->filterLocator->get($filterId) : null);
×
57
            if ($filter instanceof FilterInterface) {
×
58
                $builder = $filter->apply($builder, $values, $parameter, $context + ($parameter->getFilterContext() ?? []));
×
59
            }
60
        }
61

62
        return $builder;
×
63
    }
64
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc