Skip to content

Commit 6632627

Browse files
committed
feat(legacy-create-video): [golden-master] extract save method
1 parent 1c8b15d commit 6632627

File tree

1 file changed

+18
-11
lines changed
  • exercises/legacy_create_video/solutions/codely_php-symfony_golden-master/src/AppBundle/Application

1 file changed

+18
-11
lines changed

exercises/legacy_create_video/solutions/codely_php-symfony_golden-master/src/AppBundle/Application/VideoCreator.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,8 @@ public function createVideo($title, $url, $courseId): array
2020
{
2121
$title = $this->sanitizeTitle($title);
2222

23-
$sql = "INSERT INTO video (title, url, course_id)
24-
VALUES (\"{$title}\",
25-
\"{$url}\",
26-
{$courseId}
27-
)";
23+
$videoId = $this->save($title, $url, $courseId);
2824

29-
// Prepare doctrine statement
30-
$stmt = $this->connection->prepare($sql);
31-
$stmt->execute();
32-
33-
// IMPORTANT: Obtaining the video id. Take care, it's done without another query :)
34-
$videoId = $this->connection->lastInsertId();
3525
return array($title, $videoId);
3626
}
3727

@@ -48,4 +38,21 @@ private function sanitizeTitle(string $title): string
4838
}
4939
return $title;
5040
}
41+
42+
private function save(string $title, $url, $courseId): string
43+
{
44+
$sql = "INSERT INTO video (title, url, course_id)
45+
VALUES (\"{$title}\",
46+
\"{$url}\",
47+
{$courseId}
48+
)";
49+
50+
// Prepare doctrine statement
51+
$stmt = $this->connection->prepare($sql);
52+
$stmt->execute();
53+
54+
// IMPORTANT: Obtaining the video id. Take care, it's done without another query :)
55+
$videoId = $this->connection->lastInsertId();
56+
return $videoId;
57+
}
5158
}

0 commit comments

Comments
 (0)