Skip to content

Commit

Permalink
Merge pull request #38995 from fsamapoor/refactor_lib_private_systemtag
Browse files Browse the repository at this point in the history
Refactors lib/private/SystemTag
  • Loading branch information
ChristophWurst authored Nov 7, 2023
2 parents 2e24e70 + a988754 commit 2aa8e9d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 65 deletions.
16 changes: 3 additions & 13 deletions lib/private/SystemTag/ManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,17 @@
* @since 9.0.0
*/
class ManagerFactory implements ISystemTagManagerFactory {
/**
* Server container
*
* @var IServerContainer
*/
private $serverContainer;

/**
* Constructor for the system tag manager factory
*
* @param IServerContainer $serverContainer server container
*/
public function __construct(IServerContainer $serverContainer) {
$this->serverContainer = $serverContainer;
public function __construct(
private IServerContainer $serverContainer,
) {
}

/**
* Creates and returns an instance of the system tag manager
*
* @return ISystemTagManager
* @since 9.0.0
*/
public function getManager(): ISystemTagManager {
Expand All @@ -73,7 +64,6 @@ public function getManager(): ISystemTagManager {
* Creates and returns an instance of the system tag object
* mapper
*
* @return ISystemTagObjectMapper
* @since 9.0.0
*/
public function getObjectMapper(): ISystemTagObjectMapper {
Expand Down
53 changes: 13 additions & 40 deletions lib/private/SystemTag/SystemTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,39 +30,12 @@
use OCP\SystemTag\ISystemTag;

class SystemTag implements ISystemTag {
/**
* @var string
*/
private $id;

/**
* @var string
*/
private $name;

/**
* @var bool
*/
private $userVisible;

/**
* @var bool
*/
private $userAssignable;

/**
* Constructor.
*
* @param string $id tag id
* @param string $name tag name
* @param bool $userVisible whether the tag is user visible
* @param bool $userAssignable whether the tag is user assignable
*/
public function __construct(string $id, string $name, bool $userVisible, bool $userAssignable) {
$this->id = $id;
$this->name = $name;
$this->userVisible = $userVisible;
$this->userAssignable = $userAssignable;
public function __construct(
private string $id,
private string $name,
private bool $userVisible,
private bool $userAssignable,
) {
}

/**
Expand Down Expand Up @@ -97,14 +70,14 @@ public function isUserAssignable(): bool {
* {@inheritdoc}
*/
public function getAccessLevel(): int {
if ($this->userVisible) {
if ($this->userAssignable) {
return self::ACCESS_LEVEL_PUBLIC;
} else {
return self::ACCESS_LEVEL_RESTRICTED;
}
} else {
if (!$this->userVisible) {
return self::ACCESS_LEVEL_INVISIBLE;
}

if (!$this->userAssignable) {
return self::ACCESS_LEVEL_RESTRICTED;
}

return self::ACCESS_LEVEL_PUBLIC;
}
}
17 changes: 10 additions & 7 deletions lib/private/SystemTag/SystemTagManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ class SystemTagManager implements ISystemTagManager {

/**
* Prepared query for selecting tags directly
*
* @var \OCP\DB\QueryBuilder\IQueryBuilder
*/
private $selectTagQuery;
private IQueryBuilder $selectTagQuery;

public function __construct(
protected IDBConnection $connection,
Expand Down Expand Up @@ -219,7 +217,12 @@ public function createTag(string $tagName, bool $userVisible, bool $userAssignab
/**
* {@inheritdoc}
*/
public function updateTag(string $tagId, string $newName, bool $userVisible, bool $userAssignable) {
public function updateTag(
string $tagId,
string $newName,
bool $userVisible,
bool $userAssignable,
): void {
try {
$tags = $this->getTagsByIds($tagId);
} catch (TagNotFoundException $e) {
Expand Down Expand Up @@ -271,7 +274,7 @@ public function updateTag(string $tagId, string $newName, bool $userVisible, boo
/**
* {@inheritdoc}
*/
public function deleteTags($tagIds) {
public function deleteTags($tagIds): void {
if (!\is_array($tagIds)) {
$tagIds = [$tagIds];
}
Expand Down Expand Up @@ -363,14 +366,14 @@ public function canUserSeeTag(ISystemTag $tag, IUser $user): bool {
return false;
}

private function createSystemTagFromRow($row) {
private function createSystemTagFromRow($row): SystemTag {
return new SystemTag((string)$row['id'], $row['name'], (bool)$row['visibility'], (bool)$row['editable']);
}

/**
* {@inheritdoc}
*/
public function setTagGroups(ISystemTag $tag, array $groupIds) {
public function setTagGroups(ISystemTag $tag, array $groupIds): void {
// delete relationships first
$this->connection->beginTransaction();
try {
Expand Down
7 changes: 3 additions & 4 deletions lib/private/SystemTag/SystemTagObjectMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ public function getTagIdsForObjects($objIds, string $objectType): array {
$result->closeCursor();
}


return $mapping;
}

Expand Down Expand Up @@ -128,7 +127,7 @@ public function getObjectIdsForTags($tagIds, string $objectType, int $limit = 0,
/**
* {@inheritdoc}
*/
public function assignTags(string $objId, string $objectType, $tagIds) {
public function assignTags(string $objId, string $objectType, $tagIds): void {
if (!\is_array($tagIds)) {
$tagIds = [$tagIds];
}
Expand Down Expand Up @@ -169,7 +168,7 @@ public function assignTags(string $objId, string $objectType, $tagIds) {
/**
* {@inheritdoc}
*/
public function unassignTags(string $objId, string $objectType, $tagIds) {
public function unassignTags(string $objId, string $objectType, $tagIds): void {
if (!\is_array($tagIds)) {
$tagIds = [$tagIds];
}
Expand Down Expand Up @@ -241,7 +240,7 @@ public function haveTag($objIds, string $objectType, string $tagId, bool $all =
*
* @throws \OCP\SystemTag\TagNotFoundException if at least one tag did not exist
*/
private function assertTagsExist($tagIds) {
private function assertTagsExist(array $tagIds): void {
$tags = $this->tagManager->getTagsByIds($tagIds);
if (\count($tags) !== \count($tagIds)) {
// at least one tag missing, bail out
Expand Down
4 changes: 3 additions & 1 deletion lib/private/SystemTag/SystemTagsInFilesDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
use OCP\Files\Search\ISearchComparison;

class SystemTagsInFilesDetector {
public function __construct(protected QuerySearchHelper $searchHelper) {
public function __construct(
protected QuerySearchHelper $searchHelper,
) {
}

public function detectAssignedSystemTagsIn(
Expand Down

0 comments on commit 2aa8e9d

Please sign in to comment.