Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
PageNotFoundController
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 index
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * Page Not Found Controller (404)
5 *
6 * This Source Code Form is subject to the terms of the Mozilla Public License,
7 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
8 * obtain one at https://mozilla.org/MPL/2.0/.
9 *
10 * @package   phpMyFAQ
11 * @author    Thorsten Rinne <thorsten@phpmyfaq.de>
12 * @copyright 2019-2025 phpMyFAQ Team
13 * @license   https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
14 * @link      https://www.phpmyfaq.de
15 * @since     2019-01-25
16 */
17
18declare(strict_types=1);
19
20namespace phpMyFAQ\Controller\Frontend;
21
22use Exception;
23use phpMyFAQ\Enums\SessionActionType;
24use phpMyFAQ\Translation;
25use phpMyFAQ\User\UserSession;
26use Symfony\Component\HttpFoundation\Request;
27use Symfony\Component\HttpFoundation\Response;
28use Symfony\Component\Routing\Attribute\Route;
29
30final class PageNotFoundController extends AbstractFrontController
31{
32    public function __construct(
33        private readonly UserSession $faqSession,
34    ) {
35        parent::__construct();
36    }
37
38    /**
39     * Handles the 404 Not Found page
40     * @throws Exception
41     */
42    #[Route(path: '/404.html', name: 'public.404', methods: ['GET'])]
43    public function index(Request $request): Response
44    {
45        $this->faqSession->setCurrentUser($this->currentUser);
46        $this->faqSession->userTracking(SessionActionType::NOT_FOUND->value, 0);
47
48        $response = $this->render('404.twig', [
49            ...$this->getHeader($request),
50            'title' => sprintf('%s - %s', Translation::getString(key: 'msgError404'), $this->configuration->getTitle()),
51        ]);
52
53        $response->setStatusCode(Response::HTTP_NOT_FOUND);
54
55        return $response;
56    }
57}