Passed
Push — master ( e5a5fc...7fb567 )
by Michael
04:04 queued 11s
created

ReadforumHandler::synchronization()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php namespace XoopsModules\Newbb;
2
3
//
4
//  ------------------------------------------------------------------------ //
5
//                XOOPS - PHP Content Management System                      //
6
//                  Copyright (c) 2000-2016 XOOPS.org                        //
7
//                       <https://xoops.org/>                             //
8
//  ------------------------------------------------------------------------ //
9
//  This program is free software; you can redistribute it and/or modify     //
10
//  it under the terms of the GNU General Public License as published by     //
11
//  the Free Software Foundation; either version 2 of the License, or        //
12
//  (at your option) any later version.                                      //
13
//                                                                           //
14
//  You may not change or alter any portion of this comment or credits       //
15
//  of supporting developers from this source code or any supporting         //
16
//  source code which is considered copyrighted (c) material of the          //
17
//  original comment or credit authors.                                      //
18
//                                                                           //
19
//  This program is distributed in the hope that it will be useful,          //
20
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
21
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
22
//  GNU General Public License for more details.                             //
23
//                                                                           //
24
//  You should have received a copy of the GNU General Public License        //
25
//  along with this program; if not, write to the Free Software              //
26
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
27
//  ------------------------------------------------------------------------ //
28
//  Author: phppp (D.J., [email protected])                                  //
29
//  URL: https://xoops.org                                                    //
30
//  Project: Article Project                                                 //
31
//  ------------------------------------------------------------------------ //
32
33
use XoopsModules\Newbb;
34
35
require_once __DIR__ . '/Read.php';
36
37
/**
38
 * A handler for read/unread handling
39
 *
40
 * @package       newbb
41
 *
42
 * @author        D.J. (phppp, http://xoopsforge.com)
43
 * @copyright     copyright (c) 2005 XOOPS.org
44
 */
45
46
/**
47
 * Class ReadforumHandler
48
 */
49
class ReadforumHandler extends Newbb\ReadHandler
50
{
51
    /**
52
     * @param \XoopsDatabase|null $db
53
     */
54
    public function __construct(\XoopsDatabase $db = null)
55
    {
56
        parent::__construct($db, 'forum');
0 ignored issues
show
Bug introduced by
It seems like $db can also be of type null; however, parameter $db of XoopsModules\Newbb\ReadHandler::__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

56
        parent::__construct(/** @scrutinizer ignore-type */ $db, 'forum');
Loading history...
57
    }
58
59
    /**
60
     * clean orphan items from database
61
     *
62
     * @param  string $table_link
63
     * @param  string $field_link
64
     * @param  string $field_object
65
     * @return bool   true on success
66
     */
67
    public function cleanOrphan($table_link = '', $field_link = '', $field_object = '') //cleanOrphan()
68
    {
69
        parent::cleanOrphan($this->db->prefix('newbb_posts'), 'post_id');
70
71
        return parent::cleanOrphan($this->db->prefix('newbb_forums'), 'forum_id', 'read_item');
72
    }
73
74
    /**
75
     * @param  int  $status
76
     * @param  null $uid
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $uid is correct as it would always require null to be passed?
Loading history...
77
     * @return bool
78
     */
79
    public function setReadItems($status = 0, $uid = null)
80
    {
81
        if (empty($this->mode)) {
82
            return true;
83
        }
84
85
        if (1 == $this->mode) {
86
            return $this->setReadItemsCookie($status);
0 ignored issues
show
Bug introduced by
The call to XoopsModules\Newbb\Readf...r::setReadItemsCookie() has too few arguments starting with items. ( Ignorable by Annotation )

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

86
            return $this->/** @scrutinizer ignore-call */ setReadItemsCookie($status);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
87
        } else {
88
            return $this->setReadItemsDb($status, $uid);
89
        }
90
    }
91
92
    /**
93
     * @param $status
94
     * @param $items
95
     * @return bool
96
     */
97
    public function setReadItemsCookie($status, $items)
0 ignored issues
show
Unused Code introduced by
The parameter $items is not used and could be removed. ( Ignorable by Annotation )

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

97
    public function setReadItemsCookie($status, /** @scrutinizer ignore-unused */ $items)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
98
    {
99
        $cookie_name = 'LF';
100
        $items       = [];
101
        if (!empty($status)) {
102
            /** @var Newbb\ForumHandler $itemHandler */
103
            $itemHandler = Newbb\Helper::getInstance()->getHandler('Forum');
104
            $items_id    = $itemHandler->getIds();
105
            foreach ($items_id as $key) {
106
                $items[$key] = time();
107
            }
108
        }
109
        newbbSetCookie($cookie_name, $items);
110
111
        return true;
112
    }
113
114
    /**
115
     * @param $status
116
     * @param $uid
117
     * @return bool
118
     */
119
    public function setReadItemsDb($status, $uid)
120
    {
121
        if (empty($uid)) {
122
            if (is_object($GLOBALS['xoopsUser'])) {
123
                $uid = $GLOBALS['xoopsUser']->getVar('uid');
124
            } else {
125
                return false;
126
            }
127
        }
128
        if (empty($status)) {
129
            $this->deleteAll(new \Criteria('uid', $uid));
130
131
            return true;
132
        }
133
134
        /** @var Newbb\ForumHandler $itemHandler */
135
        $itemHandler = Newbb\Helper::getInstance()->getHandler('Forum');
136
        $itemsObject = $itemHandler->getAll(null, ['forum_last_post_id']);
137
        foreach (array_keys($itemsObject) as $key) {
138
            $this->setReadDb($key, $itemsObject[$key]->getVar('forum_last_post_id'), $uid);
139
        }
140
        unset($itemsObject);
141
142
        return true;
143
    }
144
145
    /**
146
     *
147
     */
148
    public function synchronization()
149
    {
150
        //        return;
151
    }
152
}
153