From 9dc417183077752080799db8d5962ba5147fed29 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Thu, 3 Dec 2015 17:16:51 +0100 Subject: [PATCH] parameter checks for setting actor and object to happen only in one place --- lib/private/comments/comment.php | 10 ++++++++-- lib/private/comments/manager.php | 11 ----------- 2 files changed, 8 insertions(+), 13 deletions(-) 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) -- 2.39.5