EventNotMemberHandler   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 25
c 0
b 0
f 0
dl 0
loc 73
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getNbMember() 0 5 1
A __construct() 0 6 2
A getMembers() 0 19 3
A deleteEventNotMember() 0 3 1
A createEventNotMember() 0 8 2
1
<?php
2
3
namespace XoopsModules\Extcal;
4
5
/*
6
 * You may not change or alter any portion of this comment or credits
7
 * of supporting developers from this source code or any supporting source code
8
 * which is considered copyrighted (c) material of the original comment or credit authors.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 */
14
15
/**
16
 * @copyright    {@link https://xoops.org/ XOOPS Project}
17
 * @license      {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
18
 * @package      extcal
19
 * @since
20
 * @author       XOOPS Development Team,
21
 */
22
23
use XoopsModules\Extcal\{Helper
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, XoopsModules\Extcal\Helper. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
24
};
25
26
// // require_once __DIR__ . '/ExtcalPersistableObjectHandler.php';
27
28
/**
29
 * Class EventNotMemberHandler.
30
 */
31
class EventNotMemberHandler extends ExtcalPersistableObjectHandler
32
{
33
    /**
34
     * @param \XoopsDatabase|null $db
35
     */
36
    public function __construct(\XoopsDatabase $db = null)
37
    {
38
        if (null === $db) {
39
            $db = \XoopsDatabaseFactory::getDatabaseConnection();
40
        }
41
        parent::__construct($db, 'extcal_eventnotmember', EventNotMember::class, ['event_id', 'uid']);
0 ignored issues
show
Bug introduced by
array('event_id', 'uid') of type array<integer,string> is incompatible with the type string expected by parameter $keyname of XoopsModules\Extcal\Extc...tHandler::__construct(). ( Ignorable by Annotation )

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

41
        parent::__construct($db, 'extcal_eventnotmember', EventNotMember::class, /** @scrutinizer ignore-type */ ['event_id', 'uid']);
Loading history...
42
    }
43
44
    /**
45
     * @param $varArr
46
     */
47
    public function createEventNotMember($varArr)
48
    {
49
        $eventnotmember = $this->create();
50
        $eventnotmember->setVars($varArr);
51
52
        if ($this->insert($eventnotmember, true)) {
53
            $eventmemberHandler = Helper::getInstance()->getHandler(\_EXTCAL_CLN_MEMBER);
54
            $eventmemberHandler->deleteById([$varArr['event_id'], $varArr['uid']]);
0 ignored issues
show
Bug introduced by
The method deleteById() does not exist on XoopsObjectHandler. Did you maybe mean delete()? ( Ignorable by Annotation )

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

54
            $eventmemberHandler->/** @scrutinizer ignore-call */ 
55
                                 deleteById([$varArr['event_id'], $varArr['uid']]);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
55
        }
56
    }
57
58
    /**
59
     * @param $id
60
     *
61
     * @return bool
62
     */
63
    public function deleteEventNotMember($id)
64
    {
65
        return $this->deleteById($id, true);
66
    }
67
68
    /**
69
     * @param $eventId
70
     *
71
     * @return mixed
72
     */
73
    public function getMembers($eventId)
74
    {
75
        /** @var \XoopsMemberHandler $memberHandler */
76
        $memberHandler  = \xoops_getHandler('member');
77
        $eventNotMember = $this->getObjects(new \Criteria('event_id', $eventId));
78
        $count          = \count($eventNotMember);
79
        if ($count > 0) {
80
            $in = '(' . $eventNotMember[0]->getVar('uid');
81
            \array_shift($eventNotMember);
82
            foreach ($eventNotMember as $member) {
83
                $in .= ',' . $member->getVar('uid');
84
            }
85
            $in       .= ')';
86
            $criteria = new \Criteria('uid', $in, 'IN');
87
        } else {
88
            $criteria = new \Criteria('uid', '(0)', 'IN');
89
        }
90
91
        return $memberHandler->getUsers($criteria, true);
92
    }
93
94
    /**
95
     * @param $eventId
96
     *
97
     * @return int|array
98
     */
99
    public function getNbMember($eventId)
100
    {
101
        $criteria = new \Criteria('event_id', $eventId);
102
103
        return $this->getCount($criteria);
104
    }
105
}
106