PeerFactory::createByEntity()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Zored\Telegram\Entity\Control\Peer;
6
7
use Zored\Telegram\Entity\Control\Peer\Exception\PeerFactoryException;
8
use Zored\Telegram\Entity\General\AbstractEntity;
9
10
class PeerFactory
11
{
12
    /**
13
     * @throws PeerFactoryException
14
     */
15
    public static function createByEntity(AbstractEntity $entity): PeerInterface
16
    {
17
        if ($entity instanceof \Zored\Telegram\Entity\User) {
18
            return new User($entity->getId());
19
        }
20
21
        if ($entity instanceof \Zored\Telegram\Entity\Chat) {
22
            return new Channel($entity->getId());
23
        }
24
25
        throw PeerFactoryException::becauseNoPeerFound($entity);
26
    }
27
}
28