Passed
Pull Request — master (#6127)
by Angel Fernando Quiroz
08:24
created

XApiActivityTrait::saveSharedStatement()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 13
rs 10
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
declare(strict_types=1);
6
7
use Doctrine\ORM\Exception\ORMException;
8
use Doctrine\ORM\OptimisticLockException;
9
10
trait XApiActivityTrait
11
{
12
    /**
13
     * @throws OptimisticLockException
14
     * @throws ORMException
15
     */
16
    protected function saveSharedStatement(Statement $statement): SharedStatement
17
    {
18
        $statementSerialized = $this->serializeStatement($statement);
19
20
        $sharedStmt = new SharedStatement(
21
            json_decode($statementSerialized, true)
22
        );
23
24
        $em = Database::getManager();
25
        $em->persist($sharedStmt);
26
        $em->flush();
27
28
        return $sharedStmt;
29
    }
30
31
    private function serializeStatement(Statement $statement)
32
    {
33
        $serializer = Serializer::createSerializer();
34
        $statementSerializer = new StatementSerializer($serializer);
35
36
        return $statementSerializer->serializeStatement($statement);
37
    }
38
}