1 00:00:00,780 --> 00:00:05,170 I don't know about you but I'm tired of writing out the response for our system. 2 00:00:05,170 --> 00:00:07,710 I want to do a little refactoring in this video 3 00:00:07,710 --> 00:00:10,615 to extract this out into its own function. 4 00:00:10,615 --> 00:00:13,740 Refactoring improves the internal structure of your code 5 00:00:13,740 --> 00:00:16,440 without changing the external behavior. 6 00:00:16,440 --> 00:00:21,170 If you find yourself writing the same thing over and over, it's probably a good 7 00:00:21,170 --> 00:00:26,050 indication that you have an area of code that could benefit from refactoring, 8 00:00:26,050 --> 00:00:31,180 making it easier to maintain that code in the future in a lot of our files. 9 00:00:31,180 --> 00:00:34,910 We have three lines that are repeated all over the place. 10 00:00:34,910 --> 00:00:39,110 Why don't we extract this into a redirect you know functions file. 11 00:00:39,110 --> 00:00:42,290 Let's copy the lines from our vote.php file and 12 00:00:42,290 --> 00:00:43,730 move them into our functions file. 13 00:00:46,690 --> 00:00:50,600 We'll create a new function and name it redirect. 14 00:00:52,950 --> 00:00:54,935 Then we'll pass in the path. 15 00:01:04,520 --> 00:01:07,650 Now we can change books.php to the path. 16 00:01:09,400 --> 00:01:13,849 Now let's change the vote file to substitute our new redirect function that 17 00:01:13,849 --> 00:01:14,901 we just created. 18 00:01:22,762 --> 00:01:24,020 Redirect to books. 19 00:01:25,830 --> 00:01:28,310 And then remove the last two lines. 20 00:01:28,310 --> 00:01:32,652 Let's test out our voting once more just to make sure that everything still works. 21 00:01:38,766 --> 00:01:39,700 Great. 22 00:01:39,700 --> 00:01:42,450 Why don't you take the next steps on your own and 23 00:01:42,450 --> 00:01:45,710 change all of the three redirects to our new redirect function.