Passed
Push — master ( c914ae...8bc381 )
by Blizzz
11:08 queued 11s
created

Php54::setReadArgs()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 2
eloc 4
c 1
b 1
f 0
nc 2
nop 4
dl 0
loc 6
rs 10
1
<?php
2
declare(strict_types=1);
3
/**
4
 * @copyright Copyright (c) 2020 Arthur Schiwon <[email protected]>
5
 *
6
 * @author Arthur Schiwon <[email protected]>
7
 *
8
 * @license GNU AGPL version 3 or any later version
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License as
12
 * published by the Free Software Foundation, either version 3 of the
13
 * License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 *
23
 */
24
25
namespace OCA\User_LDAP\PagedResults;
26
27
/**
28
 * Class Php54
29
 *
30
 * implements paged results support with PHP APIs available from PHP 5.4
31
 *
32
 * @package OCA\User_LDAP\PagedResults
33
 */
34
class Php54 implements IAdapter {
35
	use TLinkId;
36
37
	/** @var array */
38
	protected $linkData = [];
39
40
	public function getResponseCallFunc(): string {
41
		return 'ldap_control_paged_result_response';
42
	}
43
44
	public function responseCall($link): bool {
45
		$linkId = $this->getLinkId($link);
46
		return ldap_control_paged_result_response(...$this->linkData[$linkId]['responseArgs']);
0 ignored issues
show
Bug introduced by
The call to ldap_control_paged_result_response() has too few arguments starting with result. ( Ignorable by Annotation )

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

46
		return /** @scrutinizer ignore-call */ ldap_control_paged_result_response(...$this->linkData[$linkId]['responseArgs']);

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...
47
	}
48
49
	public function getResponseCallArgs(array $originalArgs): array {
50
		$linkId = $this->getLinkId($originalArgs[0]);
51
		if(!isset($this->linkData[$linkId])) {
52
			throw new \LogicException('There should be a request before the response');
53
		}
54
		$this->linkData[$linkId]['responseArgs'] = &$originalArgs;
55
		$this->linkData[$linkId]['cookie'] = &$originalArgs[2];
56
		return $originalArgs;
57
	}
58
59
	public function getCookie($link): string {
60
		$linkId = $this->getLinkId($link);
61
		return $this->linkData[$linkId]['cookie'];
62
	}
63
64
	public function getRequestCallFunc(): ?string {
65
		return 'ldap_control_paged_result';
66
	}
67
68
	public function setRequestParameters($link, int $pageSize, bool $isCritical): void {
69
		$linkId = $this->getLinkId($link);
70
71
		if($pageSize === 0 || !isset($this->linkData[$linkId]['cookie'])) {
72
			// abandons a previous paged search
73
			$this->linkData[$linkId]['cookie'] = '';
74
		}
75
76
		$this->linkData[$linkId]['requestArgs'] = [
77
			$link,
78
			$pageSize,
79
			$isCritical,
80
			&$this->linkData[$linkId]['cookie']
81
		];
82
	}
83
84
	public function getRequestCallArgs($link): array {
85
		$linkId = $this->getLinkId($link);
86
		return $this->linkData[$linkId]['requestArgs'];
87
	}
88
89
	public function requestCall($link): bool {
90
		$linkId = $this->getLinkId($link);
91
		return ldap_control_paged_result(...$this->linkData[$linkId]['requestArgs']);
0 ignored issues
show
Bug introduced by
The call to ldap_control_paged_result() has too few arguments starting with pagesize. ( Ignorable by Annotation )

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

91
		return /** @scrutinizer ignore-call */ ldap_control_paged_result(...$this->linkData[$linkId]['requestArgs']);

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...
92
	}
93
94
	public function setSearchArgs(
95
		$link,
96
		string $baseDN,
97
		string $filter,
98
		array $attr,
99
		int $attrsOnly,
100
		int $limit
101
	): void {
102
		$linkId = $this->getLinkId($link);
103
		if(!isset($this->linkData[$linkId])) {
104
			$this->linkData[$linkId] = [];
105
		}
106
		$this->linkData[$linkId]['searchArgs'] = func_get_args();
107
	}
108
109
	public function getSearchArgs($link): array {
110
		$linkId = $this->getLinkId($link);
111
		return $this->linkData[$linkId]['searchArgs'];
112
	}
113
114
	public function setReadArgs($link, string $baseDN, string $filter, array $attr): void {
115
		$linkId = $this->getLinkId($link);
116
		if(!isset($this->linkData[$linkId])) {
117
			$this->linkData[$linkId] = [];
118
		}
119
		$this->linkData[$linkId]['readArgs'] = func_get_args();
120
	}
121
122
	public function getReadArgs($link): array {
123
		$linkId = $this->getLinkId($link);
124
		return $this->linkData[$linkId]['readArgs'];
125
	}
126
}
127