Browse Source

Change some conditions to asserts

rpm
J. King 5 years ago
parent
commit
fb6e2babb9
  1. 2
      RoboFile.php
  2. 12
      lib/Database.php
  3. 4
      lib/Db/AbstractStatement.php
  4. 2
      tests/bootstrap.php

2
RoboFile.php

@ -126,7 +126,7 @@ class RoboFile extends \Robo\Tasks {
$execpath = norm(BASE."vendor-bin/phpunit/vendor/phpunit/phpunit/phpunit"); $execpath = norm(BASE."vendor-bin/phpunit/vendor/phpunit/phpunit/phpunit");
$confpath = realpath(BASE_TEST."phpunit.dist.xml") ?: norm(BASE_TEST."phpunit.xml"); $confpath = realpath(BASE_TEST."phpunit.dist.xml") ?: norm(BASE_TEST."phpunit.xml");
$this->taskServer(8000)->host("localhost")->dir(BASE_TEST."docroot")->rawArg("-n")->arg(BASE_TEST."server.php")->rawArg($this->blackhole())->background()->run(); $this->taskServer(8000)->host("localhost")->dir(BASE_TEST."docroot")->rawArg("-n")->arg(BASE_TEST."server.php")->rawArg($this->blackhole())->background()->run();
return $this->taskExec($executor)->arg($execpath)->option("-c", $confpath)->args(array_merge($set, $args))->run(); return $this->taskExec($executor)->option("-d", "zend.assertions=1")->arg($execpath)->option("-c", $confpath)->args(array_merge($set, $args))->run();
} }
/** Packages a given commit of the software into a release tarball /** Packages a given commit of the software into a release tarball

12
lib/Database.php

@ -198,13 +198,11 @@ class Database {
* @param boolean $matchAny Whether the search is successful when it matches any (true) or all (false) terms * @param boolean $matchAny Whether the search is successful when it matches any (true) or all (false) terms
*/ */
protected function generateSearch(array $terms, array $cols, bool $matchAny = false): array { protected function generateSearch(array $terms, array $cols, bool $matchAny = false): array {
if (!$cols) {
throw new Exception("arrayEmpty", "cols"); // @codeCoverageIgnore
}
$clause = []; $clause = [];
$types = []; $types = [];
$values = []; $values = [];
$like = $this->db->sqlToken("like"); $like = $this->db->sqlToken("like");
assert(sizeof($cols) > 0, new Exception("arrayEmpty", "cols"));
$embedSet = sizeof($terms) > ((int) (self::LIMIT_SET_SIZE / sizeof($cols))); $embedSet = sizeof($terms) > ((int) (self::LIMIT_SET_SIZE / sizeof($cols)));
foreach ($terms as $term) { foreach ($terms as $term) {
$embedTerm = ($embedSet && strlen($term) <= self::LIMIT_SET_STRING_LENGTH); $embedTerm = ($embedSet && strlen($term) <= self::LIMIT_SET_STRING_LENGTH);
@ -2081,9 +2079,7 @@ class Database {
* @param boolean $byName Whether to interpret the $id parameter as the label's name (true) or identifier (false) * @param boolean $byName Whether to interpret the $id parameter as the label's name (true) or identifier (false)
*/ */
public function labelArticlesSet(string $user, $id, Context $context, int $mode = self::ASSOC_ADD, bool $byName = false): int { public function labelArticlesSet(string $user, $id, Context $context, int $mode = self::ASSOC_ADD, bool $byName = false): int {
if (!in_array($mode, [self::ASSOC_ADD, self::ASSOC_REMOVE, self::ASSOC_REPLACE])) { assert(in_array($mode, [self::ASSOC_ADD, self::ASSOC_REMOVE, self::ASSOC_REPLACE]), new Exception("constantUnknown", $mode));
throw new Exception("constantUnknown", $mode); // @codeCoverageIgnore
}
if (!Arsse::$user->authorize($user, __FUNCTION__)) { if (!Arsse::$user->authorize($user, __FUNCTION__)) {
throw new User\ExceptionAuthz("notAuthorized", ["action" => __FUNCTION__, "user" => $user]); throw new User\ExceptionAuthz("notAuthorized", ["action" => __FUNCTION__, "user" => $user]);
} }
@ -2386,9 +2382,7 @@ class Database {
* @param boolean $byName Whether to interpret the $id parameter as the tag's name (true) or identifier (false) * @param boolean $byName Whether to interpret the $id parameter as the tag's name (true) or identifier (false)
*/ */
public function tagSubscriptionsSet(string $user, $id, array $subscriptions, int $mode = self::ASSOC_ADD, bool $byName = false): int { public function tagSubscriptionsSet(string $user, $id, array $subscriptions, int $mode = self::ASSOC_ADD, bool $byName = false): int {
if (!in_array($mode, [self::ASSOC_ADD, self::ASSOC_REMOVE, self::ASSOC_REPLACE])) { assert(in_array($mode, [self::ASSOC_ADD, self::ASSOC_REMOVE, self::ASSOC_REPLACE]), new Exception("constantUnknown", $mode));
throw new Exception("constantUnknown", $mode); // @codeCoverageIgnore
}
if (!Arsse::$user->authorize($user, __FUNCTION__)) { if (!Arsse::$user->authorize($user, __FUNCTION__)) {
throw new User\ExceptionAuthz("notAuthorized", ["action" => __FUNCTION__, "user" => $user]); throw new User\ExceptionAuthz("notAuthorized", ["action" => __FUNCTION__, "user" => $user]);
} }

4
lib/Db/AbstractStatement.php

@ -56,9 +56,7 @@ abstract class AbstractStatement implements Statement {
$this->retypeArray($binding, true); $this->retypeArray($binding, true);
} else { } else {
$bindId = self::TYPES[trim(strtolower($binding))] ?? 0; $bindId = self::TYPES[trim(strtolower($binding))] ?? 0;
if (!$bindId) { assert($bindId, new Exception("paramTypeInvalid", $binding));
throw new Exception("paramTypeInvalid", $binding); // @codeCoverageIgnore
}
$this->types[] = $bindId; $this->types[] = $bindId;
} }
} }

2
tests/bootstrap.php

@ -10,5 +10,7 @@ const NS_BASE = __NAMESPACE__."\\";
define(NS_BASE."BASE", dirname(__DIR__).DIRECTORY_SEPARATOR); define(NS_BASE."BASE", dirname(__DIR__).DIRECTORY_SEPARATOR);
const DOCROOT = BASE."tests".DIRECTORY_SEPARATOR."docroot".DIRECTORY_SEPARATOR; const DOCROOT = BASE."tests".DIRECTORY_SEPARATOR."docroot".DIRECTORY_SEPARATOR;
ini_set("memory_limit", "-1"); ini_set("memory_limit", "-1");
ini_set("zend.assertions", "1");
ini_set("assert.exception", "true");
error_reporting(\E_ALL); error_reporting(\E_ALL);
require_once BASE."vendor".DIRECTORY_SEPARATOR."autoload.php"; require_once BASE."vendor".DIRECTORY_SEPARATOR."autoload.php";

Loading…
Cancel
Save