Passed
Branch master (6e2713)
by Zangra
14:31
created

GeodisJsonApi   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 23
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setConfig() 0 3 1
A request() 0 5 1
A persist() 0 4 1
A __construct() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace GeodisBundle\Service;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use GeodisBundle\Domain\Base\Model;
7
use GeodisBundle\Service\DAO\Connection;
8
9
class GeodisJsonApi extends GeodisManager
10
{
11
    public function __construct(EntityManagerInterface $em)
12
    {
13
        parent::__construct($em);
14
    }
15
16
    public function setConfig($config): void
17
    {
18
        parent::setConfig($config);
19
    }
20
21
    private function request(string $method, string $service, array|string|null $body = null): mixed
22
    {
23
        Connection::setContentType('json');
24
25
        return Connection::Request($method, $service, $body);
26
    }
27
28
    public function persist(Model $entity, string $service): mixed
29
    {
30
        $json = $entity->toJson();
31
        return $this->request('POST', $service, $json);
32
    }
33
}
34