| Total Complexity | 8 |
| Total Lines | 41 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 9 | class PostPreference |
||
| 10 | { |
||
| 11 | public static function trackVisitedPost(Request $request, $post_id) |
||
| 12 | { |
||
| 13 | $visited_posts = array(); |
||
| 14 | if (isset($post_id)) { |
||
| 15 | if (self::checkCookieConsent()) { |
||
| 16 | if (self::getCookie($request) !== null) { |
||
| 17 | $visited_posts = self::getCookie($request); |
||
| 18 | array_push($visited_posts, $post_id); |
||
| 19 | } else { |
||
| 20 | array_push($visited_posts, $post_id); |
||
| 21 | self::setCookie(json_encode($visited_posts)); |
||
| 22 | } |
||
| 23 | } |
||
| 24 | } |
||
| 25 | } |
||
| 26 | |||
| 27 | |||
| 28 | // Get Visited Posts ID |
||
| 29 | public static function getVisitedPostsID(Request $request) |
||
| 30 | { |
||
| 31 | return self::getCookie($request); |
||
| 32 | } |
||
| 33 | |||
| 34 | // Check Cookie Consent |
||
| 35 | protected static function checkCookieConsent(): bool |
||
| 36 | { |
||
| 37 | return (bool) Cookie::get('laravel_cookie_consent'); |
||
| 38 | } |
||
| 39 | |||
| 40 | protected static function setCookie($value) |
||
| 41 | { |
||
| 42 | $response = new Response('Set Cookie'); |
||
| 43 | $response->withCookie(cookie()->forever('visited_posts', $value)); |
||
| 44 | return $response; |
||
| 45 | } |
||
| 46 | |||
| 47 | protected static function getCookie(Request $request) |
||
| 50 | } |
||
| 51 | } |
||
| 52 |