| Total Complexity | 3 |
| Total Lines | 50 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 13 | abstract class XApiActivityHookObserver extends HookObserver |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @var \XApiPlugin |
||
| 17 | */ |
||
| 18 | protected $plugin; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * XApiActivityHookObserver constructor. |
||
| 22 | */ |
||
| 23 | protected function __construct() |
||
| 24 | { |
||
| 25 | parent::__construct( |
||
| 26 | 'plugin/xapi/src/XApiPlugin.php', |
||
| 27 | 'xapi' |
||
| 28 | ); |
||
| 29 | |||
| 30 | $this->plugin = XApiPlugin::create(); |
||
| 31 | } |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @throws \Doctrine\ORM\ORMException |
||
| 35 | * @throws \Doctrine\ORM\OptimisticLockException |
||
| 36 | */ |
||
| 37 | protected function saveSharedStatement(Statement $statement): XApiSharedStatement |
||
| 38 | { |
||
| 39 | $statementSerialized = $this->serializeStatement($statement); |
||
| 40 | |||
| 41 | $sharedStmt = new XApiSharedStatement( |
||
| 42 | json_decode($statementSerialized, true) |
||
| 43 | ); |
||
| 44 | |||
| 45 | $em = Database::getManager(); |
||
| 46 | $em->persist($sharedStmt); |
||
| 47 | $em->flush(); |
||
| 48 | |||
| 49 | return $sharedStmt; |
||
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Serialize a statement to JSON. |
||
| 54 | * |
||
| 55 | * @return string |
||
| 56 | */ |
||
| 57 | private function serializeStatement(Statement $statement) |
||
| 63 | } |
||
| 64 | } |
||
| 65 |