From 4a96e222588104f647f911857e370b3ab692ea22 Mon Sep 17 00:00:00 2001 From: Arthur Schiwon Date: Wed, 6 Sep 2017 16:09:29 +0200 Subject: don't keep result types hard coded Signed-off-by: Arthur Schiwon --- .../Collaboration/Collaborators/ISearchResult.php | 20 ++++---- .../Collaborators/SearchResultType.php | 57 ++++++++++++++++++++++ 2 files changed, 67 insertions(+), 10 deletions(-) create mode 100644 lib/public/Collaboration/Collaborators/SearchResultType.php (limited to 'lib/public') diff --git a/lib/public/Collaboration/Collaborators/ISearchResult.php b/lib/public/Collaboration/Collaborators/ISearchResult.php index 87c787c040b..abea5df8598 100644 --- a/lib/public/Collaboration/Collaborators/ISearchResult.php +++ b/lib/public/Collaboration/Collaborators/ISearchResult.php @@ -31,39 +31,39 @@ namespace OCP\Collaboration\Collaborators; */ interface ISearchResult { /** - * @param string $type one of: users, groups, remotes, email, circles, lookup + * @param SearchResultType $type * @param array $matches * @param array|null $exactMatches * @since 13.0.0 */ - public function addResultSet($type, array $matches, array $exactMatches = null); + public function addResultSet(SearchResultType $type, array $matches, array $exactMatches = null); /** - * @param string $type one of: users, groups, remotes, email, circles, lookup + * @param SearchResultType $type * @param string $collaboratorId * @return bool * @since 13.0.0 */ - public function hasResult($type, $collaboratorId); + public function hasResult(SearchResultType $type, $collaboratorId); /** - * @param string $type one of: users, groups, remotes, email, circles, lookup + * @param SearchResultType $type * @since 13.0.0 */ - public function unsetResult($type); + public function unsetResult(SearchResultType $type); /** - * @param string $type one of: users, groups, remotes, email, circles, lookup + * @param SearchResultType $type * @since 13.0.0 */ - public function markExactIdMatch($type); + public function markExactIdMatch(SearchResultType $type); /** - * @param string $type one of: users, groups, remotes, email, circles, lookup + * @param SearchResultType $type * @return bool * @since 13.0.0 */ - public function hasExactIdMatch($type); + public function hasExactIdMatch(SearchResultType $type); /** * @return array diff --git a/lib/public/Collaboration/Collaborators/SearchResultType.php b/lib/public/Collaboration/Collaborators/SearchResultType.php new file mode 100644 index 00000000000..569adb864e9 --- /dev/null +++ b/lib/public/Collaboration/Collaborators/SearchResultType.php @@ -0,0 +1,57 @@ + + * + * @author Arthur Schiwon + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCP\Collaboration\Collaborators; + +/** + * Class SearchResultType + * + * @package OCP\Collaboration\Collaborators + * @since 13.0.0 + */ +class SearchResultType { + /** @var string */ + protected $label; + + public function __construct($label) { + $this->label = $this->getValidatedType($label); + } + + public function getLabel() { + return $this->label; + } + + protected function getValidatedType($type) { + $type = trim(strval($type)); + + if($type === '') { + throw new \InvalidArgumentException('Type must not be empty'); + } + + if(trim($type) === 'exact') { + throw new \InvalidArgumentException('Provided type is a reserved word'); + } + + return $type; + } +} -- cgit v1.2.3