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

api-platform / core / 9710836697

28 Jun 2024 09:35AM UTC coverage: 63.285% (+1.2%) from 62.122%
9710836697

push

github

soyuka
docs: changelog v3.3.7

11104 of 17546 relevant lines covered (63.29%)

52.26 hits per line

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

81.82
/src/Metadata/Util/ResourceClassInfoTrait.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\Metadata\Util;
15

16
use ApiPlatform\Api\ResourceClassResolverInterface as LegacyResourceClassResolverInterface;
17
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
18
use ApiPlatform\Metadata\ResourceClassResolverInterface;
19

20
/**
21
 * Retrieves information about a resource class.
22
 *
23
 * @internal
24
 */
25
trait ResourceClassInfoTrait
26
{
27
    use ClassInfoTrait;
28

29
    /**
30
     * @var LegacyResourceClassResolverInterface|ResourceClassResolverInterface|null
31
     */
32
    private $resourceClassResolver;
33
    private ?ResourceMetadataCollectionFactoryInterface $resourceMetadataFactory = null;
34

35
    /**
36
     * Gets the resource class of the given object.
37
     *
38
     * @param bool $strict If true, object class is expected to be a resource class
39
     *
40
     * @return string|null The resource class, or null if object class is not a resource class
41
     */
42
    private function getResourceClass(object $object, bool $strict = false): ?string
43
    {
44
        $objectClass = $this->getObjectClass($object);
211✔
45

46
        if (null === $this->resourceClassResolver) {
211✔
47
            return $objectClass;
×
48
        }
49

50
        if (!$strict && !$this->resourceClassResolver->isResourceClass($objectClass)) {
211✔
51
            return null;
4✔
52
        }
53

54
        return $this->resourceClassResolver->getResourceClass($object);
211✔
55
    }
56

57
    private function isResourceClass(string $class): bool
58
    {
59
        if ($this->resourceClassResolver instanceof ResourceClassResolverInterface) {
319✔
60
            return $this->resourceClassResolver->isResourceClass($class);
267✔
61
        }
62

63
        if ($this->resourceMetadataFactory) {
52✔
64
            return \count($this->resourceMetadataFactory->create($class)) > 0;
52✔
65
        }
66

67
        // assume that it's a resource class
68
        return true;
×
69
    }
70
}
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