Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
14.29% covered (danger)
14.29%
3 / 21
33.33% covered (danger)
33.33%
1 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
PermissionSetMapper
14.29% covered (danger)
14.29%
3 / 21
33.33% covered (danger)
33.33%
1 / 3
28.67
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getById
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 1
6
 findByIds
20.00% covered (danger)
20.00%
2 / 10
0.00% covered (danger)
0.00%
0 / 1
7.61
1<?php
2
3declare(strict_types=1);
4/**
5 * SPDX-FileCopyrightText: 2026 LibreCode coop and contributors
6 * SPDX-License-Identifier: AGPL-3.0-or-later
7 */
8
9namespace OCA\Libresign\Db;
10
11use OCP\AppFramework\Db\DoesNotExistException;
12use OCP\DB\QueryBuilder\IQueryBuilder;
13use OCP\ICacheFactory;
14use OCP\IDBConnection;
15
16/**
17 * @template-extends CachedQBMapper<PermissionSet>
18 */
19class PermissionSetMapper extends CachedQBMapper {
20    public function __construct(IDBConnection $db, ICacheFactory $cacheFactory) {
21        parent::__construct($db, $cacheFactory, 'libresign_permission_set');
22    }
23
24    /**
25     * @throws DoesNotExistException
26     */
27    public function getById(int $id): PermissionSet {
28        $cached = $this->cacheGet('id:' . $id);
29        if ($cached instanceof PermissionSet) {
30            return $cached;
31        }
32
33        $qb = $this->db->getQueryBuilder();
34        $qb->select('*')
35            ->from($this->getTableName())
36            ->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
37
38        /** @var PermissionSet */
39        $entity = $this->findEntity($qb);
40        $this->cacheEntity($entity);
41        return $entity;
42    }
43
44    /**
45     * @param list<int> $ids
46     * @return list<PermissionSet>
47     */
48    public function findByIds(array $ids): array {
49        if ($ids === []) {
50            return [];
51        }
52
53        $qb = $this->db->getQueryBuilder();
54        $qb->select('*')
55            ->from($this->getTableName())
56            ->where($qb->expr()->in('id', $qb->createNamedParameter($ids, IQueryBuilder::PARAM_INT_ARRAY)));
57
58        /** @var list<PermissionSet> */
59        $entities = $this->findEntities($qb);
60        foreach ($entities as $entity) {
61            $this->cacheEntity($entity);
62        }
63
64        return $entities;
65    }
66}