WhatsNewMapper::getChanges()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 10
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 15
rs 9.9332
1
<?php
2
declare(strict_types=1);
3
/**
4
 * Audioplayer
5
 *
6
 * This file is licensed under the Affero General Public License version 3 or
7
 * later. See the LICENSE.md file.
8
 *
9
 * @author Marcel Scherello <[email protected]>
10
 * @author Arthur Schiwon <[email protected]>
11
 * @author Christoph Wurst <[email protected]>
12
 * @copyright 2020 Marcel Scherello
13
 */
14
15
namespace OCA\audioplayer\WhatsNew;
16
17
use OCP\AppFramework\Db\DoesNotExistException;
18
use OCP\AppFramework\Db\QBMapper;
19
use OCP\DB\QueryBuilder\IQueryBuilder;
20
use OCP\IDBConnection;
21
use OCP\ILogger;
22
23
class WhatsNewMapper extends QBMapper
24
{
25
    public const TABLE_NAME = 'audioplayer_whats_new';
26
    private $logger;
27
28
    public function __construct(
29
        ILogger $logger,
30
        IDBConnection $db
31
    )
32
    {
33
        parent::__construct($db, self::TABLE_NAME);
34
        $this->logger = $logger;
35
    }
36
37
    /**
38
     * @throws DoesNotExistException
39
     */
40
    public function getChanges(string $version): WhatsNewResult
41
    {
42
        /* @var $qb IQueryBuilder */
43
        $qb = $this->db->getQueryBuilder();
44
        $result = $qb->select('*')
45
            ->from(self::TABLE_NAME)
46
            ->where($qb->expr()->eq('version', $qb->createNamedParameter($version)))
47
            ->execute();
48
49
        $data = $result->fetch();
50
        $result->closeCursor();
51
        if ($data === false) {
52
            throw new DoesNotExistException('Changes info is not present');
53
        }
54
        return WhatsNewResult::fromRow($data);
55
    }
56
}