| Conditions | 4 |
| Paths | 9 |
| Total Lines | 30 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 20 |
| CRAP Score | 4.0016 |
| Changes | 0 | ||
| 1 | <?php |
||
| 21 | 1 | public function execute() |
|
| 22 | { |
||
| 23 | 1 | $classMetaData = $this->getMatchedRoute()->getClassMetaData(); |
|
| 24 | 1 | $em = $this->getEntityManager(); |
|
| 25 | |||
| 26 | 1 | $entityClass = $classMetaData->getClassName(); |
|
| 27 | 1 | $object = new $entityClass; |
|
| 28 | |||
| 29 | 1 | $this->runHandle($object); |
|
| 30 | try { |
||
| 31 | 1 | $em->persist($object); |
|
| 32 | 1 | $em->flush($object); |
|
| 33 | |||
| 34 | 1 | $this->getResponse()->setStatusCode(Response::STATUS_CODE_201); |
|
| 35 | 1 | if (($location = $this->getMatchedRoute()->getOriginLocation( |
|
| 36 | 1 | $object, |
|
| 37 | 1 | $this->getRequest()->getUrl(), |
|
| 38 | 1 | $this->getEntityManager() |
|
| 39 | 1 | )) !== false |
|
| 40 | 1 | ) { |
|
| 41 | 1 | $this->getResponse()->setHttpHeader('Location', $location); |
|
| 42 | 1 | } |
|
| 43 | |||
| 44 | 1 | $resultSet = ResultSet::create(['location' => ($location) ? $location : 'unknown'], 'response'); |
|
| 45 | 1 | } catch (\Exception $e) { |
|
| 46 | return $this->handleError($e, Response::STATUS_CODE_500); |
||
| 47 | } |
||
| 48 | |||
| 49 | 1 | return $resultSet; |
|
| 50 | } |
||
| 51 | } |
||
| 52 |