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

codeigniter4 / CodeIgniter4 / 12739860967

13 Jan 2025 03:03AM UTC coverage: 84.454%. Remained the same
12739860967

push

github

web-flow
chore: add more trailing commas in more places (#9395)

* Apply to parameters

* Apply to array destructuring

* Apply to match

* Apply for arguments

337 of 397 new or added lines in 117 files covered. (84.89%)

1 existing line in 1 file now uncovered.

20464 of 24231 relevant lines covered (84.45%)

189.67 hits per line

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

42.11
/system/Session/Handlers/BaseHandler.php
1
<?php
2

3
declare(strict_types=1);
4

5
/**
6
 * This file is part of CodeIgniter 4 framework.
7
 *
8
 * (c) CodeIgniter Foundation <admin@codeigniter.com>
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 CodeIgniter\Session\Handlers;
15

16
use Config\Cookie as CookieConfig;
17
use Config\Session as SessionConfig;
18
use Psr\Log\LoggerAwareTrait;
19
use SessionHandlerInterface;
20

21
/**
22
 * Base class for session handling
23
 */
24
abstract class BaseHandler implements SessionHandlerInterface
25
{
26
    use LoggerAwareTrait;
27

28
    /**
29
     * The Data fingerprint.
30
     *
31
     * @var string
32
     */
33
    protected $fingerprint;
34

35
    /**
36
     * Lock placeholder.
37
     *
38
     * @var bool|string
39
     */
40
    protected $lock = false;
41

42
    /**
43
     * Cookie prefix
44
     *
45
     * The Config\Cookie::$prefix setting is completely ignored.
46
     * See https://codeigniter.com/user_guide/libraries/sessions.html#session-preferences
47
     *
48
     * @var string
49
     */
50
    protected $cookiePrefix = '';
51

52
    /**
53
     * Cookie domain
54
     *
55
     * @var string
56
     */
57
    protected $cookieDomain = '';
58

59
    /**
60
     * Cookie path
61
     *
62
     * @var string
63
     */
64
    protected $cookiePath = '/';
65

66
    /**
67
     * Cookie secure?
68
     *
69
     * @var bool
70
     */
71
    protected $cookieSecure = false;
72

73
    /**
74
     * Cookie name to use
75
     *
76
     * @var string
77
     */
78
    protected $cookieName;
79

80
    /**
81
     * Match IP addresses for cookies?
82
     *
83
     * @var bool
84
     */
85
    protected $matchIP = false;
86

87
    /**
88
     * Current session ID
89
     *
90
     * @var string|null
91
     */
92
    protected $sessionID;
93

94
    /**
95
     * The 'save path' for the session
96
     * varies between
97
     *
98
     * @var array|string
99
     */
100
    protected $savePath;
101

102
    /**
103
     * User's IP address.
104
     *
105
     * @var string
106
     */
107
    protected $ipAddress;
108

109
    public function __construct(SessionConfig $config, string $ipAddress)
110
    {
111
        // Store Session configurations
112
        $this->cookieName = $config->cookieName;
6,442✔
113
        $this->matchIP    = $config->matchIP;
6,442✔
114
        $this->savePath   = $config->savePath;
6,442✔
115

116
        $cookie = config(CookieConfig::class);
6,442✔
117

118
        // Session cookies have no prefix.
119
        $this->cookieDomain = $cookie->domain;
6,442✔
120
        $this->cookiePath   = $cookie->path;
6,442✔
121
        $this->cookieSecure = $cookie->secure;
6,442✔
122

123
        $this->ipAddress = $ipAddress;
6,442✔
124
    }
125

126
    /**
127
     * Internal method to force removal of a cookie by the client
128
     * when session_destroy() is called.
129
     */
130
    protected function destroyCookie(): bool
131
    {
132
        return setcookie(
×
133
            $this->cookieName,
×
134
            '',
×
NEW
135
            ['expires' => 1, 'path' => $this->cookiePath, 'domain' => $this->cookieDomain, 'secure' => $this->cookieSecure, 'httponly' => true],
×
136
        );
×
137
    }
138

139
    /**
140
     * A dummy method allowing drivers with no locking functionality
141
     * (databases other than PostgreSQL and MySQL) to act as if they
142
     * do acquire a lock.
143
     */
144
    protected function lockSession(string $sessionID): bool
145
    {
146
        $this->lock = true;
×
147

148
        return true;
×
149
    }
150

151
    /**
152
     * Releases the lock, if any.
153
     */
154
    protected function releaseLock(): bool
155
    {
156
        $this->lock = false;
×
157

158
        return true;
×
159
    }
160

161
    /**
162
     * Drivers other than the 'files' one don't (need to) use the
163
     * session.save_path INI setting, but that leads to confusing
164
     * error messages emitted by PHP when open() or write() fail,
165
     * as the message contains session.save_path ...
166
     *
167
     * To work around the problem, the drivers will call this method
168
     * so that the INI is set just in time for the error message to
169
     * be properly generated.
170
     */
171
    protected function fail(): bool
172
    {
173
        ini_set('session.save_path', $this->savePath);
×
174

175
        return false;
×
176
    }
177
}
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

© 2025 Coveralls, Inc