aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/SystemTag
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2018-02-21 21:56:00 +0100
committerRoeland Jago Douma <roeland@famdouma.nl>2018-02-21 22:08:27 +0100
commit8e5657014dc77eb2978c9b1c0aac505b7f30eaed (patch)
tree364f590458b1cd0fecffc461f1d1a964ec6cd5f5 /lib/private/SystemTag
parentf01754a389cf30cbebd391f812e46548dc062cc2 (diff)
downloadnextcloud-server-8e5657014dc77eb2978c9b1c0aac505b7f30eaed.tar.gz
nextcloud-server-8e5657014dc77eb2978c9b1c0aac505b7f30eaed.zip
Make SystemTag strict
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
Diffstat (limited to 'lib/private/SystemTag')
-rw-r--r--lib/private/SystemTag/ManagerFactory.php5
-rw-r--r--lib/private/SystemTag/SystemTag.php11
-rw-r--r--lib/private/SystemTag/SystemTagManager.php63
-rw-r--r--lib/private/SystemTag/SystemTagObjectMapper.php31
4 files changed, 53 insertions, 57 deletions
diff --git a/lib/private/SystemTag/ManagerFactory.php b/lib/private/SystemTag/ManagerFactory.php
index 12af2523f47..839a819a04a 100644
--- a/lib/private/SystemTag/ManagerFactory.php
+++ b/lib/private/SystemTag/ManagerFactory.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -57,7 +58,7 @@ class ManagerFactory implements ISystemTagManagerFactory {
* @return ISystemTagManager
* @since 9.0.0
*/
- public function getManager() {
+ public function getManager(): ISystemTagManager {
return new SystemTagManager(
$this->serverContainer->getDatabaseConnection(),
$this->serverContainer->getGroupManager(),
@@ -72,7 +73,7 @@ class ManagerFactory implements ISystemTagManagerFactory {
* @return ISystemTagObjectMapper
* @since 9.0.0
*/
- public function getObjectMapper() {
+ public function getObjectMapper(): ISystemTagObjectMapper {
return new SystemTagObjectMapper(
$this->serverContainer->getDatabaseConnection(),
$this->getManager(),
diff --git a/lib/private/SystemTag/SystemTag.php b/lib/private/SystemTag/SystemTag.php
index 15eb15efd9e..3b0cf23c9a8 100644
--- a/lib/private/SystemTag/SystemTag.php
+++ b/lib/private/SystemTag/SystemTag.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -55,7 +56,7 @@ class SystemTag implements ISystemTag {
* @param bool $userVisible whether the tag is user visible
* @param bool $userAssignable whether the tag is user assignable
*/
- public function __construct($id, $name, $userVisible, $userAssignable) {
+ public function __construct(string $id, string $name, bool $userVisible, bool $userAssignable) {
$this->id = $id;
$this->name = $name;
$this->userVisible = $userVisible;
@@ -65,28 +66,28 @@ class SystemTag implements ISystemTag {
/**
* {@inheritdoc}
*/
- public function getId() {
+ public function getId(): string {
return $this->id;
}
/**
* {@inheritdoc}
*/
- public function getName() {
+ public function getName(): string {
return $this->name;
}
/**
* {@inheritdoc}
*/
- public function isUserVisible() {
+ public function isUserVisible(): bool {
return $this->userVisible;
}
/**
* {@inheritdoc}
*/
- public function isUserAssignable() {
+ public function isUserAssignable(): bool {
return $this->userAssignable;
}
}
diff --git a/lib/private/SystemTag/SystemTagManager.php b/lib/private/SystemTag/SystemTagManager.php
index 642ce515801..055b744e5c3 100644
--- a/lib/private/SystemTag/SystemTagManager.php
+++ b/lib/private/SystemTag/SystemTagManager.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -65,6 +66,7 @@ class SystemTagManager implements ISystemTagManager {
* Constructor.
*
* @param IDBConnection $connection database connection
+ * @param IGroupManager $groupManager
* @param EventDispatcherInterface $dispatcher
*/
public function __construct(
@@ -87,8 +89,8 @@ class SystemTagManager implements ISystemTagManager {
/**
* {@inheritdoc}
*/
- public function getTagsByIds($tagIds) {
- if (!is_array($tagIds)) {
+ public function getTagsByIds($tagIds): array {
+ if (!\is_array($tagIds)) {
$tagIds = [$tagIds];
}
@@ -117,7 +119,7 @@ class SystemTagManager implements ISystemTagManager {
$result->closeCursor();
- if (count($tags) !== count($tagIds)) {
+ if (\count($tags) !== \count($tagIds)) {
throw new TagNotFoundException(
'Tag id(s) not found', 0, null, array_diff($tagIds, array_keys($tags))
);
@@ -129,14 +131,14 @@ class SystemTagManager implements ISystemTagManager {
/**
* {@inheritdoc}
*/
- public function getAllTags($visibilityFilter = null, $nameSearchPattern = null) {
+ public function getAllTags($visibilityFilter = null, $nameSearchPattern = null): array {
$tags = [];
$query = $this->connection->getQueryBuilder();
$query->select('*')
->from(self::TAG_TABLE);
- if (!is_null($visibilityFilter)) {
+ if (!\is_null($visibilityFilter)) {
$query->andWhere($query->expr()->eq('visibility', $query->createNamedParameter((int)$visibilityFilter)));
}
@@ -167,14 +169,11 @@ class SystemTagManager implements ISystemTagManager {
/**
* {@inheritdoc}
*/
- public function getTag($tagName, $userVisible, $userAssignable) {
- $userVisible = (int)$userVisible;
- $userAssignable = (int)$userAssignable;
-
+ public function getTag(string $tagName, bool $userVisible, bool $userAssignable): ISystemTag {
$result = $this->selectTagQuery
->setParameter('name', $tagName)
- ->setParameter('visibility', $userVisible)
- ->setParameter('editable', $userAssignable)
+ ->setParameter('visibility', $userVisible ? 1 : 0)
+ ->setParameter('editable', $userAssignable ? 1 : 0)
->execute();
$row = $result->fetch();
@@ -191,16 +190,13 @@ class SystemTagManager implements ISystemTagManager {
/**
* {@inheritdoc}
*/
- public function createTag($tagName, $userVisible, $userAssignable) {
- $userVisible = (int)$userVisible;
- $userAssignable = (int)$userAssignable;
-
+ public function createTag(string $tagName, bool $userVisible, bool $userAssignable): ISystemTag {
$query = $this->connection->getQueryBuilder();
$query->insert(self::TAG_TABLE)
->values([
'name' => $query->createNamedParameter($tagName),
- 'visibility' => $query->createNamedParameter($userVisible),
- 'editable' => $query->createNamedParameter($userAssignable),
+ 'visibility' => $query->createNamedParameter($userVisible ? 1 : 0),
+ 'editable' => $query->createNamedParameter($userAssignable ? 1 : 0),
]);
try {
@@ -216,10 +212,10 @@ class SystemTagManager implements ISystemTagManager {
$tagId = $query->getLastInsertId();
$tag = new SystemTag(
- (int)$tagId,
+ (string)$tagId,
$tagName,
- (bool)$userVisible,
- (bool)$userAssignable
+ $userVisible,
+ $userAssignable
);
$this->dispatcher->dispatch(ManagerEvent::EVENT_CREATE, new ManagerEvent(
@@ -232,10 +228,7 @@ class SystemTagManager implements ISystemTagManager {
/**
* {@inheritdoc}
*/
- public function updateTag($tagId, $tagName, $userVisible, $userAssignable) {
- $userVisible = (int)$userVisible;
- $userAssignable = (int)$userAssignable;
-
+ public function updateTag(string $tagId, string $tagName, bool $userVisible, bool $userAssignable) {
try {
$tags = $this->getTagsByIds($tagId);
} catch (TagNotFoundException $e) {
@@ -246,10 +239,10 @@ class SystemTagManager implements ISystemTagManager {
$beforeUpdate = array_shift($tags);
$afterUpdate = new SystemTag(
- (int) $tagId,
+ $tagId,
$tagName,
- (bool) $userVisible,
- (bool) $userAssignable
+ $userVisible,
+ $userAssignable
);
$query = $this->connection->getQueryBuilder();
@@ -259,8 +252,8 @@ class SystemTagManager implements ISystemTagManager {
->set('editable', $query->createParameter('editable'))
->where($query->expr()->eq('id', $query->createParameter('tagid')))
->setParameter('name', $tagName)
- ->setParameter('visibility', $userVisible)
- ->setParameter('editable', $userAssignable)
+ ->setParameter('visibility', $userVisible ? 1 : 0)
+ ->setParameter('editable', $userAssignable ? 1 : 0)
->setParameter('tagid', $tagId);
try {
@@ -286,7 +279,7 @@ class SystemTagManager implements ISystemTagManager {
* {@inheritdoc}
*/
public function deleteTags($tagIds) {
- if (!is_array($tagIds)) {
+ if (!\is_array($tagIds)) {
$tagIds = [$tagIds];
}
@@ -337,7 +330,7 @@ class SystemTagManager implements ISystemTagManager {
/**
* {@inheritdoc}
*/
- public function canUserAssignTag(ISystemTag $tag, IUser $user) {
+ public function canUserAssignTag(ISystemTag $tag, IUser $user): bool {
// early check to avoid unneeded group lookups
if ($tag->isUserAssignable() && $tag->isUserVisible()) {
return true;
@@ -365,7 +358,7 @@ class SystemTagManager implements ISystemTagManager {
/**
* {@inheritdoc}
*/
- public function canUserSeeTag(ISystemTag $tag, IUser $user) {
+ public function canUserSeeTag(ISystemTag $tag, IUser $user): bool {
if ($tag->isUserVisible()) {
return true;
}
@@ -378,13 +371,13 @@ class SystemTagManager implements ISystemTagManager {
}
private function createSystemTagFromRow($row) {
- return new SystemTag((int)$row['id'], $row['name'], (bool)$row['visibility'], (bool)$row['editable']);
+ return new SystemTag((string)$row['id'], $row['name'], (bool)$row['visibility'], (bool)$row['editable']);
}
/**
* {@inheritdoc}
*/
- public function setTagGroups(ISystemTag $tag, $groupIds) {
+ public function setTagGroups(ISystemTag $tag, array $groupIds) {
// delete relationships first
$this->connection->beginTransaction();
try {
@@ -418,7 +411,7 @@ class SystemTagManager implements ISystemTagManager {
/**
* {@inheritdoc}
*/
- public function getTagGroups(ISystemTag $tag) {
+ public function getTagGroups(ISystemTag $tag): array {
$groupIds = [];
$query = $this->connection->getQueryBuilder();
$query->select('gid')
diff --git a/lib/private/SystemTag/SystemTagObjectMapper.php b/lib/private/SystemTag/SystemTagObjectMapper.php
index 75bf37c652c..8ecc46b4357 100644
--- a/lib/private/SystemTag/SystemTagObjectMapper.php
+++ b/lib/private/SystemTag/SystemTagObjectMapper.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -63,8 +64,8 @@ class SystemTagObjectMapper implements ISystemTagObjectMapper {
/**
* {@inheritdoc}
*/
- public function getTagIdsForObjects($objIds, $objectType) {
- if (!is_array($objIds)) {
+ public function getTagIdsForObjects($objIds, string $objectType): array {
+ if (!\is_array($objIds)) {
$objIds = [$objIds];
} else if (empty($objIds)) {
return [];
@@ -99,8 +100,8 @@ class SystemTagObjectMapper implements ISystemTagObjectMapper {
/**
* {@inheritdoc}
*/
- public function getObjectIdsForTags($tagIds, $objectType, $limit = 0, $offset = '') {
- if (!is_array($tagIds)) {
+ public function getObjectIdsForTags($tagIds, string $objectType, int $limit = 0, string $offset = ''): array {
+ if (!\is_array($tagIds)) {
$tagIds = [$tagIds];
}
@@ -113,7 +114,7 @@ class SystemTagObjectMapper implements ISystemTagObjectMapper {
->andWhere($query->expr()->eq('objecttype', $query->createNamedParameter($objectType)));
if ($limit) {
- if (count($tagIds) !== 1) {
+ if (\count($tagIds) !== 1) {
throw new \InvalidArgumentException('Limit is only allowed with a single tag');
}
@@ -138,8 +139,8 @@ class SystemTagObjectMapper implements ISystemTagObjectMapper {
/**
* {@inheritdoc}
*/
- public function assignTags($objId, $objectType, $tagIds) {
- if (!is_array($tagIds)) {
+ public function assignTags(string $objId, string $objectType, $tagIds) {
+ if (!\is_array($tagIds)) {
$tagIds = [$tagIds];
}
@@ -173,8 +174,8 @@ class SystemTagObjectMapper implements ISystemTagObjectMapper {
/**
* {@inheritdoc}
*/
- public function unassignTags($objId, $objectType, $tagIds) {
- if (!is_array($tagIds)) {
+ public function unassignTags(string $objId, string $objectType, $tagIds) {
+ if (!\is_array($tagIds)) {
$tagIds = [$tagIds];
}
@@ -201,10 +202,10 @@ class SystemTagObjectMapper implements ISystemTagObjectMapper {
/**
* {@inheritdoc}
*/
- public function haveTag($objIds, $objectType, $tagId, $all = true) {
+ public function haveTag($objIds, string $objectType, string $tagId, bool $all = true): bool {
$this->assertTagsExist([$tagId]);
- if (!is_array($objIds)) {
+ if (!\is_array($objIds)) {
$objIds = [$objIds];
}
@@ -232,10 +233,10 @@ class SystemTagObjectMapper implements ISystemTagObjectMapper {
$result->closeCursor();
if ($all) {
- return ((int)$row[0] === count($objIds));
- } else {
- return (bool) $row;
+ return ((int)$row[0] === \count($objIds));
}
+
+ return (bool) $row;
}
/**
@@ -247,7 +248,7 @@ class SystemTagObjectMapper implements ISystemTagObjectMapper {
*/
private function assertTagsExist($tagIds) {
$tags = $this->tagManager->getTagsByIds($tagIds);
- if (count($tags) !== count($tagIds)) {
+ if (\count($tags) !== \count($tagIds)) {
// at least one tag missing, bail out
$foundTagIds = array_map(
function(ISystemTag $tag) {