• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

klinge / sl-webapp / 19065177774

04 Nov 2025 10:12AM UTC coverage: 75.865% (-0.08%) from 75.944%
19065177774

push

github

klinge
Temp reverting back to phpstan lvl 5

1688 of 2225 relevant lines covered (75.87%)

3.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.12
/App/Controllers/BaseController.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace App\Controllers;
6

7
use App\Services\UrlGeneratorService;
8
use App\Traits\JsonResponder;
9
use App\Utils\Session;
10
use Psr\Http\Message\ServerRequestInterface;
11
use Psr\Http\Message\ResponseInterface;
12
use Laminas\Diactoros\Response;
13
use Monolog\Logger;
14
use League\Container\Container;
15

16
class BaseController
17
{
18
    //Add the JsonResponder trait
19
    use JsonResponder;
20

21
    protected ServerRequestInterface $request;
22
    /** @var array<string, mixed> */
23
    protected array $sessionData;
24
    protected UrlGeneratorService $urlGenerator;
25
    protected Logger $logger;
26
    protected Container $container;
27

28
    public function __construct(UrlGeneratorService $urlGenerator, ServerRequestInterface $request, Logger $logger, Container $container)
29
    {
30
        $this->urlGenerator = $urlGenerator;
44✔
31
        $this->request = $request;
44✔
32
        $this->logger = $logger;
44✔
33
        $this->container = $container;
44✔
34
        $this->initializeSessionData();
44✔
35
    }
36

37
    protected function initializeSessionData(): void
38
    {
39
        $this->sessionData = [
44✔
40
            'isLoggedIn' => Session::isLoggedIn(),
44✔
41
            'userId' => Session::get('user_id'),
44✔
42
            'fornamn' => Session::get('fornamn'),
44✔
43
            'isAdmin' => Session::isAdmin()
44✔
44
        ];
44✔
45
    }
46

47
    protected function setCsrfToken(): void
48
    {
49
        $token = bin2hex(random_bytes(32));
3✔
50
        Session::set('csrf_token', $token);
3✔
51
    }
52

53
    protected function validateCsrfToken(string $token): bool
54
    {
55
        return Session::get('csrf_token') && hash_equals(Session::get('csrf_token'), $token);
×
56
    }
57

58
    /**
59
     * Creates a URL for the given route name with optional parameters.
60
     *
61
     * @param string $routeName The name of the route
62
     * @param array<string, mixed> $params Optional route parameters (e.g., ['id' => 123])
63
     * @return string The generated URL path
64
     */
65
    protected function createUrl(string $routeName, array $params = []): string
66
    {
67
        return $this->urlGenerator->createUrl($routeName, $params);
23✔
68
    }
69

70
    protected function notFoundResponse(): ResponseInterface
71
    {
72
        $response = new Response();
1✔
73
        return $response->withStatus(404);
1✔
74
    }
75
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc