From: Arthur Schiwon Date: Thu, 3 Dec 2015 16:16:51 +0000 (+0100) Subject: parameter checks for setting actor and object to happen only in one place X-Git-Tag: v9.0beta1~520^2~13 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9dc417183077752080799db8d5962ba5147fed29;p=nextcloud-server.git parameter checks for setting actor and object to happen only in one place --- diff --git a/lib/private/comments/comment.php b/lib/private/comments/comment.php index 2e9e4bd3d84..8efd7d5613a 100644 --- a/lib/private/comments/comment.php +++ b/lib/private/comments/comment.php @@ -229,7 +229,10 @@ class Comment implements IComment { * @since 9.0.0 */ public function setActor($actorType, $actorId) { - if(!is_string($actorType) || !is_string($actorId)) { + if( + !is_string($actorType) || empty($actorType) + || !is_string($actorId) || empty($actorId) + ) { throw new \InvalidArgumentException('String expected.'); } $this->data['actorType'] = $actorType; @@ -312,7 +315,10 @@ class Comment implements IComment { * @since 9.0.0 */ public function setObject($objectType, $objectId) { - if(!is_string($objectType) || !is_string($objectId)) { + if( + !is_string($objectType) || empty($objectType) + || !is_string($objectId) || empty($objectId) + ) { throw new \InvalidArgumentException('String expected.'); } $this->data['objectType'] = $objectType; diff --git a/lib/private/comments/manager.php b/lib/private/comments/manager.php index 12b90a063d1..184e37eb12a 100644 --- a/lib/private/comments/manager.php +++ b/lib/private/comments/manager.php @@ -354,20 +354,9 @@ class Manager implements ICommentsManager { * @param string $objectType the object type the comment is attached to * @param string $objectId the object id the comment is attached to * @return IComment - * @throws \InvalidArgumentException * @since 9.0.0 */ public function create($actorType, $actorId, $objectType, $objectId) { - if( - !is_string($actorType) || empty($actorType) - || !is_string($actorId) || empty($actorId) - || !is_string($objectType) || empty($objectType) - || !is_string($objectId) || empty($objectId) - ) { - // unsure whether it's a good place to enforce it here, since the - // comment instance can be manipulated anyway. - throw new \InvalidArgumentException('All arguments must be non-empty strings'); - } $comment = new Comment(); $comment ->setActor($actorType, $actorId)