Skip to content

Commit 6b5dc11

Browse files
committed
Refactors lib/private/SystemTag.
Mainly using PHP8's constructor property promotion. Signed-off-by: Faraz Samapoor <f.samapoor@gmail.com>
1 parent 912b18b commit 6b5dc11

File tree

5 files changed

+32
-65
lines changed

5 files changed

+32
-65
lines changed

lib/private/SystemTag/ManagerFactory.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,17 @@
3939
* @since 9.0.0
4040
*/
4141
class ManagerFactory implements ISystemTagManagerFactory {
42-
/**
43-
* Server container
44-
*
45-
* @var IServerContainer
46-
*/
47-
private $serverContainer;
48-
4942
/**
5043
* Constructor for the system tag manager factory
51-
*
52-
* @param IServerContainer $serverContainer server container
5344
*/
54-
public function __construct(IServerContainer $serverContainer) {
55-
$this->serverContainer = $serverContainer;
45+
public function __construct(
46+
private IServerContainer $serverContainer,
47+
) {
5648
}
5749

5850
/**
5951
* Creates and returns an instance of the system tag manager
6052
*
61-
* @return ISystemTagManager
6253
* @since 9.0.0
6354
*/
6455
public function getManager(): ISystemTagManager {
@@ -73,7 +64,6 @@ public function getManager(): ISystemTagManager {
7364
* Creates and returns an instance of the system tag object
7465
* mapper
7566
*
76-
* @return ISystemTagObjectMapper
7767
* @since 9.0.0
7868
*/
7969
public function getObjectMapper(): ISystemTagObjectMapper {

lib/private/SystemTag/SystemTag.php

Lines changed: 13 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -30,39 +30,12 @@
3030
use OCP\SystemTag\ISystemTag;
3131

3232
class SystemTag implements ISystemTag {
33-
/**
34-
* @var string
35-
*/
36-
private $id;
37-
38-
/**
39-
* @var string
40-
*/
41-
private $name;
42-
43-
/**
44-
* @var bool
45-
*/
46-
private $userVisible;
47-
48-
/**
49-
* @var bool
50-
*/
51-
private $userAssignable;
52-
53-
/**
54-
* Constructor.
55-
*
56-
* @param string $id tag id
57-
* @param string $name tag name
58-
* @param bool $userVisible whether the tag is user visible
59-
* @param bool $userAssignable whether the tag is user assignable
60-
*/
61-
public function __construct(string $id, string $name, bool $userVisible, bool $userAssignable) {
62-
$this->id = $id;
63-
$this->name = $name;
64-
$this->userVisible = $userVisible;
65-
$this->userAssignable = $userAssignable;
33+
public function __construct(
34+
private string $id,
35+
private string $name,
36+
private bool $userVisible,
37+
private bool $userAssignable,
38+
) {
6639
}
6740

6841
/**
@@ -97,14 +70,14 @@ public function isUserAssignable(): bool {
9770
* {@inheritdoc}
9871
*/
9972
public function getAccessLevel(): int {
100-
if ($this->userVisible) {
101-
if ($this->userAssignable) {
102-
return self::ACCESS_LEVEL_PUBLIC;
103-
} else {
104-
return self::ACCESS_LEVEL_RESTRICTED;
105-
}
106-
} else {
73+
if (!$this->userVisible) {
10774
return self::ACCESS_LEVEL_INVISIBLE;
10875
}
76+
77+
if (!$this->userAssignable) {
78+
return self::ACCESS_LEVEL_RESTRICTED;
79+
}
80+
81+
return self::ACCESS_LEVEL_PUBLIC;
10982
}
11083
}

lib/private/SystemTag/SystemTagManager.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,8 @@ class SystemTagManager implements ISystemTagManager {
5050

5151
/**
5252
* Prepared query for selecting tags directly
53-
*
54-
* @var \OCP\DB\QueryBuilder\IQueryBuilder
5553
*/
56-
private $selectTagQuery;
54+
private IQueryBuilder $selectTagQuery;
5755

5856
public function __construct(
5957
protected IDBConnection $connection,
@@ -219,7 +217,12 @@ public function createTag(string $tagName, bool $userVisible, bool $userAssignab
219217
/**
220218
* {@inheritdoc}
221219
*/
222-
public function updateTag(string $tagId, string $newName, bool $userVisible, bool $userAssignable) {
220+
public function updateTag(
221+
string $tagId,
222+
string $newName,
223+
bool $userVisible,
224+
bool $userAssignable,
225+
): void {
223226
try {
224227
$tags = $this->getTagsByIds($tagId);
225228
} catch (TagNotFoundException $e) {
@@ -271,7 +274,7 @@ public function updateTag(string $tagId, string $newName, bool $userVisible, boo
271274
/**
272275
* {@inheritdoc}
273276
*/
274-
public function deleteTags($tagIds) {
277+
public function deleteTags($tagIds): void {
275278
if (!\is_array($tagIds)) {
276279
$tagIds = [$tagIds];
277280
}
@@ -363,14 +366,14 @@ public function canUserSeeTag(ISystemTag $tag, IUser $user): bool {
363366
return false;
364367
}
365368

366-
private function createSystemTagFromRow($row) {
369+
private function createSystemTagFromRow($row): SystemTag {
367370
return new SystemTag((string)$row['id'], $row['name'], (bool)$row['visibility'], (bool)$row['editable']);
368371
}
369372

370373
/**
371374
* {@inheritdoc}
372375
*/
373-
public function setTagGroups(ISystemTag $tag, array $groupIds) {
376+
public function setTagGroups(ISystemTag $tag, array $groupIds): void {
374377
// delete relationships first
375378
$this->connection->beginTransaction();
376379
try {

lib/private/SystemTag/SystemTagObjectMapper.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ public function getTagIdsForObjects($objIds, string $objectType): array {
8181
$result->closeCursor();
8282
}
8383

84-
8584
return $mapping;
8685
}
8786

@@ -128,7 +127,7 @@ public function getObjectIdsForTags($tagIds, string $objectType, int $limit = 0,
128127
/**
129128
* {@inheritdoc}
130129
*/
131-
public function assignTags(string $objId, string $objectType, $tagIds) {
130+
public function assignTags(string $objId, string $objectType, $tagIds): void {
132131
if (!\is_array($tagIds)) {
133132
$tagIds = [$tagIds];
134133
}
@@ -169,7 +168,7 @@ public function assignTags(string $objId, string $objectType, $tagIds) {
169168
/**
170169
* {@inheritdoc}
171170
*/
172-
public function unassignTags(string $objId, string $objectType, $tagIds) {
171+
public function unassignTags(string $objId, string $objectType, $tagIds): void {
173172
if (!\is_array($tagIds)) {
174173
$tagIds = [$tagIds];
175174
}
@@ -241,7 +240,7 @@ public function haveTag($objIds, string $objectType, string $tagId, bool $all =
241240
*
242241
* @throws \OCP\SystemTag\TagNotFoundException if at least one tag did not exist
243242
*/
244-
private function assertTagsExist($tagIds) {
243+
private function assertTagsExist(array $tagIds): void {
245244
$tags = $this->tagManager->getTagsByIds($tagIds);
246245
if (\count($tags) !== \count($tagIds)) {
247246
// at least one tag missing, bail out

lib/private/SystemTag/SystemTagsInFilesDetector.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@
3636
use OCP\Files\Search\ISearchComparison;
3737

3838
class SystemTagsInFilesDetector {
39-
public function __construct(protected QuerySearchHelper $searchHelper) {
39+
public function __construct(
40+
protected QuerySearchHelper $searchHelper,
41+
) {
4042
}
4143

4244
public function detectAssignedSystemTagsIn(

0 commit comments

Comments
 (0)