Skip to content

Commit 5856c8b

Browse files
committed
fix: Avoid undefined variable
Signed-off-by: Julius Härtl <[email protected]>
1 parent a31601d commit 5856c8b

3 files changed

Lines changed: 32 additions & 44 deletions

File tree

lib/Db/BoardMapper.php

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323

2424
namespace OCA\Deck\Db;
2525

26-
use OC\Cache\CappedMemoryCache;
2726
use OCA\Deck\Service\CirclesService;
2827
use OCP\AppFramework\Db\DoesNotExistException;
2928
use OCP\AppFramework\Db\QBMapper;
29+
use OCP\Cache\CappedMemoryCache;
3030
use OCP\DB\QueryBuilder\IQueryBuilder;
3131
use OCP\IDBConnection;
3232
use OCP\IGroupManager;
@@ -35,37 +35,22 @@
3535

3636
/** @template-extends QBMapper<Board> */
3737
class BoardMapper extends QBMapper implements IPermissionMapper {
38-
private $labelMapper;
39-
private $aclMapper;
40-
private $stackMapper;
41-
private $userManager;
42-
private $groupManager;
43-
private $circlesService;
44-
private $logger;
45-
4638
/** @var CappedMemoryCache<Board[]> */
47-
private $userBoardCache;
39+
private CappedMemoryCache $userBoardCache;
4840
/** @var CappedMemoryCache<Board> */
49-
private $boardCache;
41+
private CappedMemoryCache $boardCache;
5042

5143
public function __construct(
5244
IDBConnection $db,
53-
LabelMapper $labelMapper,
54-
AclMapper $aclMapper,
55-
StackMapper $stackMapper,
56-
IUserManager $userManager,
57-
IGroupManager $groupManager,
58-
CirclesService $circlesService,
59-
LoggerInterface $logger
45+
private LabelMapper $labelMapper,
46+
private AclMapper $aclMapper,
47+
private StackMapper $stackMapper,
48+
private IUserManager $userManager,
49+
private IGroupManager $groupManager,
50+
private CirclesService $circlesService,
51+
private LoggerInterface $logger
6052
) {
6153
parent::__construct($db, 'deck_boards', Board::class);
62-
$this->labelMapper = $labelMapper;
63-
$this->aclMapper = $aclMapper;
64-
$this->stackMapper = $stackMapper;
65-
$this->userManager = $userManager;
66-
$this->groupManager = $groupManager;
67-
$this->circlesService = $circlesService;
68-
$this->logger = $logger;
6954

7055
$this->userBoardCache = new CappedMemoryCache();
7156
$this->boardCache = new CappedMemoryCache();
@@ -81,30 +66,31 @@ public function __construct(
8166
* @throws DoesNotExistException
8267
*/
8368
public function find(int $id, bool $withLabels = false, bool $withAcl = false, bool $allowDeleted = false): Board {
84-
if (!isset($this->boardCache[$id])) {
69+
$cacheKey = (string)$id;
70+
if (!isset($this->boardCache[$cacheKey])) {
8571
$qb = $this->db->getQueryBuilder();
8672
$deletedWhere = $allowDeleted ? $qb->expr()->gte('deleted_at', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT)) : $qb->expr()->eq('deleted_at', $qb->createNamedParameter(0, IQueryBuilder::PARAM_INT));
8773
$qb->select('*')
8874
->from('deck_boards')
8975
->where($qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT)))
9076
->andWhere($deletedWhere)
9177
->orderBy('id');
92-
$this->boardCache[$id] = $this->findEntity($qb);
78+
$this->boardCache[(string)$id] = $this->findEntity($qb);
9379
}
9480

9581
// Add labels
96-
if ($withLabels && $this->boardCache[$id]->getLabels() === null) {
82+
if ($withLabels && $this->boardCache[$cacheKey]->getLabels() === null) {
9783
$labels = $this->labelMapper->findAll($id);
98-
$this->boardCache[$id]->setLabels($labels);
84+
$this->boardCache[$cacheKey]->setLabels($labels);
9985
}
10086

10187
// Add acl
102-
if ($withAcl && $this->boardCache[$id]->getAcl() === null) {
88+
if ($withAcl && $this->boardCache[$cacheKey]->getAcl() === null) {
10389
$acl = $this->aclMapper->findAll($id);
104-
$this->boardCache[$id]->setAcl($acl);
90+
$this->boardCache[$cacheKey]->setAcl($acl);
10591
}
10692

107-
return $this->boardCache[$id];
93+
return $this->boardCache[$cacheKey];
10894
}
10995

11096
public function findBoardIds(string $userId): array {
@@ -464,8 +450,7 @@ public function findBoardId($id): ?int {
464450
}
465451

466452
public function mapAcl(Acl &$acl) {
467-
$groupManager = $this->groupManager;
468-
$acl->resolveRelation('participant', function ($participant) use (&$acl, &$userManager, &$groupManager) {
453+
$acl->resolveRelation('participant', function ($participant) use (&$acl) {
469454
if ($acl->getType() === Acl::PERMISSION_TYPE_USER) {
470455
if ($this->userManager->userExists($acl->getParticipant())) {
471456
return new User($acl->getParticipant(), $this->userManager);
@@ -474,7 +459,7 @@ public function mapAcl(Acl &$acl) {
474459
return null;
475460
}
476461
if ($acl->getType() === Acl::PERMISSION_TYPE_GROUP) {
477-
$group = $groupManager->get($participant);
462+
$group = $this->groupManager->get($participant);
478463
if ($group !== null) {
479464
return new Group($group);
480465
}

tests/integration/database/AssignmentMapperTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ class AssignmentMapperTest extends \Test\TestCase {
5555
/** @var AssignmentService */
5656
private $assignmentService;
5757

58+
/** @var Board */
59+
private $board;
60+
/** @var Card[] */
61+
private $cards;
62+
/** @var Stack[] */
63+
private $stacks;
64+
5865
public static function setUpBeforeClass(): void {
5966
parent::setUpBeforeClass();
6067

tests/integration/features/bootstrap/SessionContext.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,9 @@
99
class SessionContext implements Context {
1010
use RequestTrait;
1111

12-
/** @var ServerContext */
13-
private $serverContext;
14-
15-
/** @var BoardContext */
16-
private $boardContext;
17-
18-
private $tokens = [];
12+
private ServerContext $serverContext;
13+
private BoardContext $boardContext;
14+
private array $tokens = [];
1915

2016
/** @BeforeScenario */
2117
public function gatherContexts(BeforeScenarioScope $scope) {
@@ -40,7 +36,7 @@ public function opensTheBoardNamed($name) {
4036

4137
// store token
4238
$user = $this->serverContext->getCurrentUser();
43-
$this->token[$user] = $res['ocs']['data']['token'];
39+
$this->tokens[$user] = $res['ocs']['data']['token'];
4440
}
4541

4642
/**
@@ -70,7 +66,7 @@ public function closingTheBoardNamed($name) {
7066
}
7167

7268
$user = $this->serverContext->getCurrentUser();
73-
$token = $this->token[$user];
69+
$token = $this->tokens[$user];
7470
Assert::assertNotEmpty($token, "no token for the user found");
7571
$this->requestContext->sendOCSRequest('POST', '/apps/deck/api/v1.0/session/close', [
7672
'boardId' => $board['id'],

0 commit comments

Comments
 (0)