More usage of dbm::is_result($r) instead of count($r):

- count() returns very different results and never a boolean (not even false on
  error condition).
- therefore you should NOT use it in boolean expressions. This still *can* be
  done in PHP because of its lazyness. But it is discouraged if it comes to
  more clean code.

Signed-off-by: Roland Häder <roland@mxchange.org>
This commit is contained in:
Roland Häder 2016-12-13 10:44:13 +01:00
parent 293436e5fd
commit 6a8a36f12d
115 changed files with 439 additions and 437 deletions

View file

@ -208,7 +208,7 @@
dbesc(trim($user)),
dbesc($encrypted)
);
if(count($r))
if(dbm::is_result($r))
$record = $r[0];
}
@ -1326,10 +1326,10 @@
if (isset($_GET["q"])) {
$r = q("SELECT id FROM `contact` WHERE `uid` = 0 AND `name` = '%s'", dbesc($_GET["q"]));
if (!count($r))
if (!dbm::is_result($r))
$r = q("SELECT `id` FROM `contact` WHERE `uid` = 0 AND `nick` = '%s'", dbesc($_GET["q"]));
if (count($r)) {
if (dbm::is_result($r)) {
$k = 0;
foreach ($r AS $user) {
$user_info = api_get_user($a, $user["id"], "json");
@ -3174,7 +3174,7 @@
intval(api_user())
);
if ((! count($r)) || ($r[0]['network'] !== NETWORK_DFRN))
if ((! dbm::is_result($r)) || ($r[0]['network'] !== NETWORK_DFRN))
throw new BadRequestException("Unknown contact");
$cid = $r[0]['id'];
@ -3526,7 +3526,7 @@
intval($uid),
intval($gid));
// error message if specified gid is not in database
if (count($r) == 0)
if (!dbm::is_result($r))
throw new BadRequestException("gid not available");
}
else
@ -3581,7 +3581,7 @@
intval($uid),
intval($gid));
// error message if specified gid is not in database
if (count($r) == 0)
if (!dbm::is_result($r))
throw new BadRequestException('gid not available');
// get data of the specified group id and group name
@ -3919,7 +3919,9 @@
$profile_url = $user_info["url"];
// message if nothing was found
if (count($r) == 0)
if (!dbm::is_result($r))
$success = array('success' => false, 'search_results' => 'problem with query');
else if (count($r) == 0)
$success = array('success' => false, 'search_results' => 'nothing found');
else {
$ret = Array();
@ -3966,7 +3968,7 @@
intval(api_user()),
intval($profileid));
// error message if specified gid is not in database
if (count($r) == 0)
if (!dbm::is_result($r))
throw new BadRequestException("profile_id not available");
}
else