QuotaHandler::getQuota()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
nc 2
nop 2
dl 0
loc 11
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace XoopsModules\Extgallery;
4
5
/**
6
 * ExtGallery Class Manager
7
 *
8
 * You may not change or alter any portion of this comment or credits
9
 * of supporting developers from this source code or any supporting source code
10
 * which is considered copyrighted (c) material of the original comment or credit authors.
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 *
15
 * @copyright   {@link https://xoops.org/ XOOPS Project}
16
 * @license     GNU GPL 2 (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
17
 * @author      Zoullou (http://www.zoullou.net)
18
 * @package     ExtGallery
19
 */
20
21
use XoopsModules\Extgallery;
22
23
/**
24
 * Class Extgallery\QuotaHandler
25
 */
26
class QuotaHandler extends Extgallery\PersistableObjectHandler
27
{
28
    /**
29
     * Extgallery\QuotaHandler constructor.
30
     * @param \XoopsDatabase|null $db
31
     */
32
    public function __construct(\XoopsDatabase $db = null)
33
    {
34
        parent::__construct($db, 'extgallery_quota', 'Extgallery\Quota', 'quota_id');
0 ignored issues
show
Bug introduced by
It seems like $db can also be of type null; however, parameter $db of XoopsModules\Extgallery\...tHandler::__construct() does only seem to accept XoopsDatabase, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

34
        parent::__construct(/** @scrutinizer ignore-type */ $db, 'extgallery_quota', 'Extgallery\Quota', 'quota_id');
Loading history...
35
    }
36
37
    /**
38
     * @param $data
39
     *
40
     * @return bool
41
     */
42
    public function createQuota($data)
43
    {
44
        $quota = $this->create();
45
        $quota->setVars($data);
46
47
        return $this->insert($quota, true);
48
    }
49
50
    /**
51
     * @return bool
52
     */
53
    public function deleteQuota()
54
    {
55
        $criteria = new \Criteria('quota_name', 'private');
56
57
        return $this->deleteAll($criteria);
58
    }
59
60
    /**
61
     * @param $groupid
62
     * @param $quotaName
63
     *
64
     * @return \XoopsObject
65
     */
66
    public function getQuota($groupid, $quotaName)
67
    {
68
        $criteria = new \CriteriaCompo();
69
        $criteria->add(new \Criteria('groupid', $groupid));
70
        $criteria->add(new \Criteria('quota_name', $quotaName));
71
        $ret = $this->getObjects($criteria);
72
        if (empty($ret)) {
73
            return $this->create();
74
        }
75
76
        return $ret[0];
77
    }
78
}
79