Skip to content

Commit 92bbcc3

Browse files
committed
feat(legacy-create-video): [golden-master] extract sanitizeTitle method
1 parent 69f0b2d commit 92bbcc3

File tree

1 file changed

+15
-9
lines changed
  • exercises/legacy_create_video/solutions/codely_php-symfony_golden-master/src/AppBundle/Controller

1 file changed

+15
-9
lines changed

exercises/legacy_create_video/solutions/codely_php-symfony_golden-master/src/AppBundle/Controller/VideoController.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,7 @@ public function postVideoAction(Request $request)
2121
$url = $request->get('url');
2222
$courseId = $request->get('course_id');
2323

24-
if (strpos($title, "hexagonal")) {
25-
$title = str_replace("hexagonal", "Hexagonal", $title);
26-
}
27-
if (strpos($title, "solid")) {
28-
$title = str_replace("solid", "SOLID", $title);
29-
}
30-
if (strpos($title, "tdd")) {
31-
$title = str_replace("tdd", "TDD", $title);
32-
}
24+
$title = $this->sanitizeTitle($title);
3325

3426
$sql = "INSERT INTO video (title, url, course_id)
3527
VALUES (\"{$title}\",
@@ -53,4 +45,18 @@ public function postVideoAction(Request $request)
5345
'course_id' => $courseId,
5446
];
5547
}
48+
49+
private function sanitizeTitle(string $title): string
50+
{
51+
if (strpos($title, "hexagonal")) {
52+
$title = str_replace("hexagonal", "Hexagonal", $title);
53+
}
54+
if (strpos($title, "solid")) {
55+
$title = str_replace("solid", "SOLID", $title);
56+
}
57+
if (strpos($title, "tdd")) {
58+
$title = str_replace("tdd", "TDD", $title);
59+
}
60+
return $title;
61+
}
5662
}

0 commit comments

Comments
 (0)