Passed
Push — master ( 29a096...72a8e1 )
by Roeland
26:38 queued 16:45
created

GenericEventWrapper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 4
rs 10
1
<?php
2
3
declare(strict_types=1);
4
/**
5
 * @copyright Copyright (c) 2020, Roeland Jago Douma <[email protected]>
6
 *
7
 * @author Roeland Jago Douma <[email protected]>
8
 *
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
26
namespace OC\EventDispatcher;
27
28
use OCP\ILogger;
29
use Symfony\Component\EventDispatcher\GenericEvent;
30
31
class GenericEventWrapper extends GenericEvent {
32
33
	/** @var ILogger */
34
	private $logger;
35
36
	/** @var GenericEvent */
37
	private $event;
38
39
	/** @var string */
40
	private $eventName;
41
42
	public function __construct(ILogger $logger, string $eventName, ?GenericEvent $event) {
43
		$this->logger = $logger;
44
		$this->event = $event;
45
		$this->eventName = $eventName;
46
	}
47
48
	private function log() {
49
		$this->logger->info(
50
			'Deprecated event type for {name}: {class} is used',
51
			[ 'name' => $this->eventName, 'class' => is_object($this->event) ? get_class($this->event) : 'null' ]
52
		);
53
	}
54
55
	public function isPropagationStopped() {
56
		$this->log();
57
		return $this->event->isPropagationStopped();
0 ignored issues
show
Deprecated Code introduced by
The function Symfony\Component\EventD...:isPropagationStopped() has been deprecated: since Symfony 4.3, use "Symfony\Contracts\EventDispatcher\Event" instead ( Ignorable by Annotation )

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

57
		return /** @scrutinizer ignore-deprecated */ $this->event->isPropagationStopped();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
58
	}
59
60
	public function stopPropagation() {
61
		$this->log();
62
		$this->event->stopPropagation();
0 ignored issues
show
Deprecated Code introduced by
The function Symfony\Component\EventD...vent::stopPropagation() has been deprecated: since Symfony 4.3, use "Symfony\Contracts\EventDispatcher\Event" instead ( Ignorable by Annotation )

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

62
		/** @scrutinizer ignore-deprecated */ $this->event->stopPropagation();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
63
	}
64
65
	public function getSubject() {
66
		$this->log();
67
		return $this->event->getSubject();
68
	}
69
70
	public function getArgument($key) {
71
		$this->log();
72
		return $this->event->getArgument($key);
73
	}
74
75
	public function setArgument($key, $value) {
76
		$this->log();
77
		return $this->event->setArgument($key, $value);
78
	}
79
80
	public function getArguments() {
81
		return $this->event->getArguments();
82
	}
83
84
	public function setArguments(array $args = []) {
85
		return $this->event->setArguments($args);
86
	}
87
88
	public function hasArgument($key) {
89
		return $this->event->hasArgument($key);
90
	}
91
92
	public function offsetGet($key) {
93
		return $this->event->offsetGet($key);
94
	}
95
96
	public function offsetSet($key, $value) {
97
		return $this->event->offsetSet($key, $value);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->event->offsetSet($key, $value) targeting Symfony\Component\EventD...nericEvent::offsetSet() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
98
	}
99
100
	public function offsetUnset($key) {
101
		return $this->event->offsetUnset($key);
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->event->offsetUnset($key) targeting Symfony\Component\EventD...ricEvent::offsetUnset() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
102
	}
103
104
	public function offsetExists($key) {
105
		return $this->event->offsetExists($key);
106
	}
107
108
	public function getIterator() {
109
		return$this->event->getIterator();
110
	}
111
}
112