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

daycry / auth / 16343465380

17 Jul 2025 11:07AM UTC coverage: 59.224% (-0.6%) from 59.854%
16343465380

push

github

web-flow
Merge pull request #23 from daycry/development

Improvements

57 of 292 new or added lines in 16 files covered. (19.52%)

6 existing lines in 4 files now uncovered.

1939 of 3274 relevant lines covered (59.22%)

22.81 hits per line

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

60.0
/src/Services/RequestLogger.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * This file is part of Daycry Auth.
7
 *
8
 * (c) Daycry <daycry9@proton.me>
9
 *
10
 * For the full copyright and license information, please view
11
 * the LICENSE file that was distributed with this source code.
12
 */
13

14
namespace Daycry\Auth\Services;
15

16
use CodeIgniter\HTTP\ResponseInterface;
17
use CodeIgniter\Router\Router;
18
use Config\Services;
19
use Daycry\Auth\Interfaces\AuthController;
20
use Daycry\Auth\Libraries\Logger;
21
use ReflectionClass;
22

23
/**
24
 * Service for handling request logging in Auth controllers
25
 *
26
 * Extracts logging logic from BaseControllerTrait to follow SRP
27
 */
28
class RequestLogger
29
{
30
    protected Logger $logger;
31
    protected Router $router;
32
    protected bool $isRequestAuthorized = true;
33

34
    public function __construct()
35
    {
36
        $this->logger = Services::log();
15✔
37
        $this->router = Services::router();
15✔
38
    }
39

40
    /**
41
     * Set whether the request is authorized
42
     */
43
    public function setRequestAuthorized(bool $authorized): self
44
    {
NEW
45
        $this->isRequestAuthorized = $authorized;
×
46

NEW
47
        return $this;
×
48
    }
49

50
    /**
51
     * Get current authorization status
52
     */
53
    public function isRequestAuthorized(): bool
54
    {
55
        return $this->isRequestAuthorized;
6✔
56
    }
57

58
    /**
59
     * Log the request with proper authorization status
60
     */
61
    public function logRequest(ResponseInterface $response): void
62
    {
63
        $controllerName = $this->router->controllerName();
6✔
64

65
        // Only check if controller class exists to avoid errors in tests
66
        if ($controllerName && class_exists($controllerName)) {
6✔
NEW
67
            $reflectionClass = new ReflectionClass($controllerName);
×
68

NEW
69
            if ($reflectionClass->implementsInterface(AuthController::class)) {
×
NEW
70
                $this->logger->setLogAuthorized(false);
×
71
            }
72
        }
73

74
        $this->logger
6✔
75
            ->setAuthorized($this->isRequestAuthorized)
6✔
76
            ->setResponseCode($response->getStatusCode())
6✔
77
            ->save();
6✔
78
    }
79

80
    /**
81
     * Static method to get a new instance
82
     */
83
    public static function getInstance(): self
84
    {
NEW
85
        return new self();
×
86
    }
87
}
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