1: <?php declare(strict_types=1);
2:
3: namespace Salient\Sync\Reflection;
4:
5: use Salient\Contract\Sync\SyncEntityInterface;
6: use ReflectionClass;
7:
8: /**
9: * @template TEntity of SyncEntityInterface
10: *
11: * @extends ReflectionClass<TEntity>
12: */
13: class ReflectionSyncEntity extends ReflectionClass
14: {
15: use SyncReflectionTrait;
16:
17: /**
18: * @param TEntity|class-string<TEntity> $entity
19: */
20: public function __construct($entity)
21: {
22: $this->assertImplements($entity, SyncEntityInterface::class);
23: parent::__construct($entity);
24: }
25:
26: /**
27: * Get the plural form of the entity's short name
28: *
29: * Returns `null` if {@see SyncEntityInterface::getPlural()} returns `null`
30: * or the short name of the entity.
31: */
32: public function getPluralName(): ?string
33: {
34: /** @var string|null */
35: $plural = $this->getMethod('getPlural')->invoke(null);
36: if ($plural !== null && !strcasecmp($plural, $this->getShortName())) {
37: return null;
38: }
39: return $plural;
40: }
41: }
42: