Skip to content

Commit 16d4ff4

Browse files
committed
parameter provided to L10N::n() could have been a string
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
1 parent 6b39186 commit 16d4ff4

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

apps/user_ldap/lib/Wizard.php

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,19 @@ public function __destruct() {
8989
*
9090
* @param string $filter the LDAP search filter
9191
* @param string $type a string being either 'users' or 'groups';
92-
* @return bool|int
92+
* @return int
9393
* @throws \Exception
9494
*/
95-
public function countEntries($filter, $type) {
96-
$reqs = array('ldapHost', 'ldapPort', 'ldapBase');
95+
public function countEntries(string $filter, string $type): int {
96+
$reqs = ['ldapHost', 'ldapPort', 'ldapBase'];
9797
if($type === 'users') {
9898
$reqs[] = 'ldapUserFilter';
9999
}
100100
if(!$this->checkRequirements($reqs)) {
101101
throw new \Exception('Requirements not met', 400);
102102
}
103103

104-
$attr = array('dn'); // default
104+
$attr = ['dn']; // default
105105
$limit = 1001;
106106
if($type === 'groups') {
107107
$result = $this->access->countGroups($filter, $attr, $limit);
@@ -113,22 +113,21 @@ public function countEntries($filter, $type) {
113113
throw new \Exception('Internal error: Invalid object type', 500);
114114
}
115115

116-
return $result;
116+
return (int)$result;
117117
}
118118

119119
/**
120120
* formats the return value of a count operation to the string to be
121121
* inserted.
122122
*
123-
* @param bool|int $count
124-
* @return int|string
123+
* @param int $count
124+
* @return string
125125
*/
126-
private function formatCountResult($count) {
127-
$formatted = ($count !== false) ? $count : 0;
128-
if($formatted > 1000) {
129-
$formatted = '> 1000';
126+
private function formatCountResult(int $count): string {
127+
if($count > 1000) {
128+
return '> 1000';
130129
}
131-
return $formatted;
130+
return (string)$count;
132131
}
133132

134133
public function countGroups() {
@@ -141,15 +140,20 @@ public function countGroups() {
141140
}
142141

143142
try {
144-
$groupsTotal = $this->formatCountResult($this->countEntries($filter, 'groups'));
143+
$groupsTotal = $this->countEntries($filter, 'groups');
145144
} catch (\Exception $e) {
146145
//400 can be ignored, 500 is forwarded
147146
if($e->getCode() === 500) {
148147
throw $e;
149148
}
150149
return false;
151150
}
152-
$output = self::$l->n('%s group found', '%s groups found', $groupsTotal, array($groupsTotal));
151+
$output = self::$l->n(
152+
'%s group found',
153+
'%s groups found',
154+
$groupsTotal,
155+
[$this->formatCountResult($groupsTotal)]
156+
);
153157
$this->result->addChange('ldap_group_count', $output);
154158
return $this->result;
155159
}
@@ -161,8 +165,13 @@ public function countGroups() {
161165
public function countUsers() {
162166
$filter = $this->access->getFilterForUserCount();
163167

164-
$usersTotal = $this->formatCountResult($this->countEntries($filter, 'users'));
165-
$output = self::$l->n('%s user found', '%s users found', $usersTotal, array($usersTotal));
168+
$usersTotal = $this->countEntries($filter, 'users');
169+
$output = self::$l->n(
170+
'%s user found',
171+
'%s users found',
172+
$usersTotal,
173+
[$this->formatCountResult($usersTotal)]
174+
);
166175
$this->result->addChange('ldap_user_count', $output);
167176
return $this->result;
168177
}
@@ -175,7 +184,7 @@ public function countUsers() {
175184
*/
176185
public function countInBaseDN() {
177186
// we don't need to provide a filter in this case
178-
$total = $this->countEntries(null, 'objects');
187+
$total = $this->countEntries('', 'objects');
179188
if($total === false) {
180189
throw new \Exception('invalid results received');
181190
}

0 commit comments

Comments
 (0)