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

api-platform / core / 9838795518

08 Jul 2024 11:33AM UTC coverage: 64.239% (+0.07%) from 64.173%
9838795518

push

github

web-flow
Merge pull request #6459 from soyuka/main

Merge 3.4

154 of 179 new or added lines in 24 files covered. (86.03%)

36 existing lines in 12 files now uncovered.

11326 of 17631 relevant lines covered (64.24%)

68.24 hits per line

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

33.33
/src/ParameterValidator/FilterLocatorTrait.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\ParameterValidator;
15

16
use ApiPlatform\Metadata\Exception\InvalidArgumentException;
17
use ApiPlatform\Metadata\FilterInterface;
18
use Psr\Container\ContainerInterface;
19

20
/**
21
 * Manipulates filters with a backward compatibility between the new filter locator and the deprecated filter collection.
22
 *
23
 * @author Baptiste Meyer <baptiste.meyer@gmail.com>
24
 *
25
 * @deprecated
26
 *
27
 * @internal
28
 */
29
trait FilterLocatorTrait
30
{
31
    private ?ContainerInterface $filterLocator = null;
32

33
    /**
34
     * Sets a filter locator with a backward compatibility.
35
     */
36
    private function setFilterLocator(?ContainerInterface $filterLocator, bool $allowNull = false): void
37
    {
38
        if ($filterLocator instanceof ContainerInterface || (null === $filterLocator && $allowNull)) {
428✔
39
            $this->filterLocator = $filterLocator;
428✔
40
        } else {
41
            throw new InvalidArgumentException(sprintf('The "$filterLocator" argument is expected to be an implementation of the "%s" interface%s.', ContainerInterface::class, $allowNull ? ' or null' : ''));
×
42
        }
43
    }
44

45
    /**
46
     * Gets a filter with a backward compatibility.
47
     */
48
    private function getFilter(string $filterId): ?FilterInterface
49
    {
UNCOV
50
        if ($this->filterLocator && $this->filterLocator->has($filterId)) {
×
UNCOV
51
            return $this->filterLocator->get($filterId);
×
52
        }
53

54
        return null;
×
55
    }
56
}
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

© 2026 Coveralls, Inc