PeerFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 16
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A createByEntity() 0 11 3
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