Debian Codegraph @

lib/3rdParty/composer/symfony/serializer/Mapping/Factory/ClassResolverTrait.php

raw symbols SCIP
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <[email protected]>
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 namespace Symfony\Component\Serializer\Mapping\Factory;
13
14 use Symfony\Component\Serializer\Exception\InvalidArgumentException;
15
16 /**
17 * Resolves a class name.
18 *
19 * @internal
20 *
21 * @author Kévin Dunglas <[email protected]>
22 */
23 trait ClassResolverTrait
24 {
25 /**
26 * Gets a class name for a given class or instance.
27 *
28 * @throws InvalidArgumentException If the class does not exist
29 */
30 private function getClass(object|string $value): string
31 {
32 if (\is_string($value)) {
33 if (!class_exists($value) && !interface_exists($value, false)) {
34 throw new InvalidArgumentException(\sprintf('The class or interface "%s" does not exist.', $value));
35 }
36
37 return ltrim($value, '\\');
38 }
39
40 return $value::class;
41 }
42 }