Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
Session
100.00% covered (success)
100.00%
19 / 19
100.00% covered (success)
100.00%
5 / 5
5
100.00% covered (success)
100.00%
1 / 1
 getEntityMapping
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 addConditionSessionId
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 addConditionSessionName
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 addConditionSessionDeleteInterval
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
 postProcess
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace BO\Zmsbackend\Session\Repository;
4
5class Session extends \BO\Zmsbackend\Query\Base
6{
7    /**
8     * @var String TABLE mysql table reference
9     */
10    const string TABLE = 'sessiondata';
11
12    /**
13     * No resolving required here
14     */
15    protected $resolveLevel = 0;
16
17    const string QUERY_WRITE = '
18        REPLACE INTO
19            sessiondata
20        SET
21            sessionid=?,
22            sessionname=?,
23            sessioncontent=?
24    ';
25
26    const string QUERY_DELETE = '
27        DELETE FROM
28            sessiondata
29        WHERE
30            sessionid=? AND
31            sessionname=?
32    ';
33
34    /**
35     * @psalm-api
36     *
37     * @return string[]
38     *
39     */
40    public function getEntityMapping(): array
41    {
42        return [
43            'id' => 'session.sessionid',
44            'name' => 'session.sessionname',
45            'content' => 'session.sessioncontent'
46        ];
47    }
48
49    public function addConditionSessionId($sessionId): static
50    {
51        $this->query->where('session.sessionid', '=', $sessionId);
52        return $this;
53    }
54
55    public function addConditionSessionName(string $sessionName): static
56    {
57        $this->query->where('session.sessionname', '=', $sessionName);
58        return $this;
59    }
60
61    public function addConditionSessionDeleteInterval(int $deleteInSeconds): static
62    {
63        $this->query->where(
64            self::expression(
65                'UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(`session`.`ts`)'
66            ),
67            '>=',
68            $deleteInSeconds
69        );
70        return $this;
71    }
72
73    /**
74     * postProcess data if necessary
75     *
76     */
77    #[\Override]
78    public function postProcess($data)
79    {
80        $data[$this->getPrefixed('content')] = json_decode($data[$this->getPrefixed('content')], 1);
81        return $data;
82    }
83}