FavoriteHandler   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 80
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getCountFavorite() 0 5 1
A getAllFavorite() 0 5 1
A __construct() 0 3 1
A get() 0 3 1
A getFavoriteCriteria() 0 7 1
A create() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
6
namespace XoopsModules\Wgfilemanager;
7
8
/*
9
 You may not change or alter any portion of this comment or credits
10
 of supporting developers from this source code or any supporting source code
11
 which is considered copyrighted (c) material of the original comment or credit authors.
12
13
 This program is distributed in the hope that it will be useful,
14
 but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
*/
17
18
/**
19
 * wgFileManager module for xoops
20
 *
21
 * @copyright    2021 XOOPS Project (https://xoops.org)
22
 * @license      GPL 2.0 or later
23
 * @package      wgfilemanager
24
 * @since        1.0
25
 * @min_xoops    2.5.9
26
 * @author       Goffy - Wedega - Email:[email protected] - Website:https://xoops.wedega.com
27
 */
28
29
use XoopsModules\Wgfilemanager;
30
31
32
/**
33
 * Class Object Handler Favorite
34
 */
35
class FavoriteHandler extends \XoopsPersistableObjectHandler
36
{
37
    /**
38
     * Constructor
39
     *
40
     * @param \XoopsDatabase $db
41
     */
42
    public function __construct(\XoopsDatabase $db)
43
    {
44
        parent::__construct($db, 'wgfilemanager_favorite', Favorite::class, 'id', 'extension');
45
    }
46
47
    /**
48
     * @param bool $isNew
49
     *
50
     * @return object
51
     */
52
    public function create($isNew = true)
53
    {
54
        return parent::create($isNew);
55
    }
56
57
    /**
58
     * retrieve a field
59
     *
60
     * @param int $id field id
61
     * @param null $fields fields
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $fields is correct as it would always require null to be passed?
Loading history...
62
     * @return \XoopsObject|null reference to the {@link Get} object
63
     */
64
    public function get($id = null, $fields = null)
65
    {
66
        return parent::get($id, $fields);
67
    }
68
69
    /**
70
     * Get Count File in the database
71
     * @param int    $start
72
     * @param int    $limit
73
     * @param string $sort
74
     * @param string $order
75
     * @return int
76
     */
77
    public function getCountFavorite($start = 0, $limit = 0, $sort = 'id', $order = 'ASC')
78
    {
79
        $crCountFavorite = new \CriteriaCompo();
80
        $crCountFavorite = $this->getFavoriteCriteria($crCountFavorite, $start, $limit, $sort, $order);
81
        return $this->getCount($crCountFavorite);
0 ignored issues
show
Bug introduced by
$crCountFavorite of type integer is incompatible with the type CriteriaElement|null expected by parameter $criteria of XoopsPersistableObjectHandler::getCount(). ( Ignorable by Annotation )

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

81
        return $this->getCount(/** @scrutinizer ignore-type */ $crCountFavorite);
Loading history...
82
    }
83
84
    /**
85
     * Get All Favorite in the database
86
     * @param int    $start
87
     * @param int    $limit
88
     * @param string $sort
89
     * @param string $order
90
     * @return array
91
     */
92
    public function getAllFavorite($start = 0, $limit = 0, $sort = 'id', $order = 'ASC')
93
    {
94
        $crAllFavorite = new \CriteriaCompo();
95
        $crAllFavorite = $this->getFavoriteCriteria($crAllFavorite, $start, $limit, $sort, $order);
96
        return $this->getAll($crAllFavorite);
0 ignored issues
show
Bug introduced by
$crAllFavorite of type integer is incompatible with the type CriteriaElement|null expected by parameter $criteria of XoopsPersistableObjectHandler::getAll(). ( Ignorable by Annotation )

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

96
        return $this->getAll(/** @scrutinizer ignore-type */ $crAllFavorite);
Loading history...
97
    }
98
99
    /**
100
     * Get Criteria Favorite
101
     * @param        $crFavorite
102
     * @param int    $start
103
     * @param int    $limit
104
     * @param string $sort
105
     * @param string $order
106
     * @return int
107
     */
108
    private function getFavoriteCriteria($crFavorite, $start, $limit, $sort, $order)
109
    {
110
        $crFavorite->setStart($start);
111
        $crFavorite->setLimit($limit);
112
        $crFavorite->setSort($sort);
113
        $crFavorite->setOrder($order);
114
        return $crFavorite;
115
    }
116
}
117