| Conditions | 5 |
| Paths | 4 |
| Total Lines | 22 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 5.2 |
| Changes | 0 | ||
| 1 | <?php |
||
| 34 | 2 | public function createOrganization(array $data): Organization |
|
| 35 | { |
||
| 36 | 2 | if (empty($data['name'])) { |
|
| 37 | throw new BadRequestHttpException('organizations.invalid_name'); |
||
| 38 | } |
||
| 39 | 2 | if (empty($data['type']) || !in_array($data['type'], Organization::getTypes())) { |
|
| 40 | throw new BadRequestHttpException('organizations.invalid_type'); |
||
| 41 | } |
||
| 42 | 2 | if (!isset($data['description'])) { |
|
| 43 | throw new BadRequestHttpException('organization.invalid_description'); |
||
| 44 | } |
||
| 45 | $organization = |
||
| 46 | 2 | (new Organization()) |
|
| 47 | 2 | ->setName($data['name']) |
|
| 48 | 2 | ->setSlug($this->slugger->slugify($data['name'])) |
|
| 49 | 2 | ->setType($data['type']) |
|
| 50 | 2 | ->setDescription($data['description']) |
|
| 51 | ; |
||
| 52 | 2 | $this->em->persist($organization); |
|
| 53 | 2 | $this->em->flush(); |
|
| 54 | |||
| 55 | 2 | return $organization; |
|
| 56 | } |
||
| 58 |