1010use Rancoud \Database \Database as DB ;
1111use Rancoud \Database \DatabaseException ;
1212
13- /**
14- * Class Database.
15- */
1613class Database implements \SessionHandlerInterface, \SessionUpdateTimestampHandlerInterface
1714{
1815 protected DB $ db ;
@@ -21,12 +18,8 @@ class Database implements \SessionHandlerInterface, \SessionUpdateTimestampHandl
2118
2219 protected int $ lengthSessionID = 127 ;
2320
24- /**
25- * @param array|Configurator $configuration
26- *
27- * @throws SessionException
28- */
29- public function setNewDatabase ($ configuration ): void
21+ /** @throws SessionException */
22+ public function setNewDatabase (array |Configurator $ configuration ): void
3023 {
3124 try {
3225 if ($ configuration instanceof Configurator) {
@@ -64,11 +57,7 @@ public function getLengthSessionID(): int
6457 return $ this ->lengthSessionID ;
6558 }
6659
67- /**
68- * @param string $path
69- * @param string $name
70- */
71- public function open ($ path , $ name ): bool
60+ public function open (string $ path , string $ name ): bool
7261 {
7362 return true ;
7463 }
@@ -78,12 +67,8 @@ public function close(): bool
7867 return true ;
7968 }
8069
81- /**
82- * @param string $id
83- *
84- * @throws SessionException
85- */
86- public function read ($ id ): string
70+ /** @throws SessionException */
71+ public function read (string $ id ): string
8772 {
8873 try {
8974 $ sql = 'SELECT content FROM sessions WHERE id = :id ' ;
@@ -95,13 +80,8 @@ public function read($id): string
9580 }
9681 }
9782
98- /**
99- * @param string $id
100- * @param string $data
101- *
102- * @throws SessionException
103- */
104- public function write ($ id , $ data ): bool
83+ /** @throws SessionException */
84+ public function write (string $ id , string $ data ): bool
10585 {
10686 try {
10787 $ sql = 'REPLACE INTO sessions VALUES(:id, :id_user, UTC_TIMESTAMP(), :content) ' ;
@@ -115,12 +95,8 @@ public function write($id, $data): bool
11595 }
11696 }
11797
118- /**
119- * @param string $id
120- *
121- * @throws SessionException
122- */
123- public function destroy ($ id ): bool
98+ /** @throws SessionException */
99+ public function destroy (string $ id ): bool
124100 {
125101 try {
126102 $ sql = 'DELETE FROM sessions WHERE id = :id ' ;
@@ -133,13 +109,9 @@ public function destroy($id): bool
133109 }
134110 }
135111
136- /**
137- * @param int $max_lifetime
138- *
139- * @throws SessionException
140- */
112+ /** @throws SessionException */
141113 #[\ReturnTypeWillChange]
142- public function gc ($ max_lifetime ): bool
114+ public function gc (int $ max_lifetime ): bool
143115 {
144116 try {
145117 $ sql = 'DELETE FROM sessions WHERE DATE_ADD(last_access, INTERVAL :seconds second) < UTC_TIMESTAMP() ' ;
@@ -155,13 +127,9 @@ public function gc($max_lifetime): bool
155127 /**
156128 * Checks format and id exists, if not session_id will be regenerate.
157129 *
158- * @param string $id
159- *
160130 * @throws SessionException
161- *
162- * @noinspection PhpMissingParamTypeInspection
163131 */
164- public function validateId ($ id ): bool
132+ public function validateId (string $ id ): bool
165133 {
166134 try {
167135 if (\preg_match ('/^[a-zA-Z0-9-]{ ' . $ this ->lengthSessionID . '}+$/ ' , $ id ) !== 1 ) {
@@ -181,14 +149,9 @@ public function validateId($id): bool
181149 /**
182150 * Updates the timestamp of a session when its data didn't change.
183151 *
184- * @param string $id
185- * @param string $data
186- *
187152 * @throws SessionException
188- *
189- * @noinspection PhpMissingParamTypeInspection
190153 */
191- public function updateTimestamp ($ id , $ data ): bool
154+ public function updateTimestamp (string $ id , string $ data ): bool
192155 {
193156 return $ this ->write ($ id , $ data );
194157 }
0 commit comments