| Conditions | 3 |
| Paths | 4 |
| Total Lines | 21 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 6 |
| CRAP Score | 3.8449 |
| Changes | 0 | ||
| 1 | <?php |
||
| 54 | 9 | public function transactional($func) |
|
| 55 | { |
||
| 56 | 9 | if (!is_callable($func)) { |
|
| 57 | throw new \InvalidArgumentException('Expected argument of type "callable", got "' . gettype($func) . '"'); |
||
| 58 | } |
||
| 59 | |||
| 60 | 9 | $this->beginTransaction(); |
|
| 61 | |||
| 62 | try { |
||
| 63 | 9 | $return = call_user_func($func, $this); |
|
| 64 | |||
| 65 | 9 | $this->commitTransaction(); |
|
| 66 | |||
| 67 | 9 | return $return; |
|
| 68 | } catch (\Exception $e) { |
||
| 69 | $this->entityManager->close(); |
||
| 70 | $this->rollbackTransaction(); |
||
| 71 | |||
| 72 | throw $e; |
||
| 73 | } |
||
| 74 | } |
||
| 75 | } |
||
| 76 |