Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix types warnings from psalm
Signed-off-by: Carl Schwan <[email protected]>
  • Loading branch information
CarlSchwan committed Jan 12, 2022
commit fffc19f5c3e2e1789564542f3562a7b56b587c8c
14 changes: 7 additions & 7 deletions apps/sharebymail/lib/ShareByMailProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,13 @@ protected function createMailShare(IShare $share) {
$share->getNote()
);

if ($this->mailer->validateMailAddress($share->getSharedWith())) {
if (!$this->mailer->validateMailAddress($share->getSharedWith())) {
$this->removeShareFromTable($shareId);
$e = new HintException('Failed to send share by mail. Got an invalid email address: ' . $share->getSharedWith(),
$this->l->t('Failed to send share by email. Got an invalid email address'));
$this->logger->error($e->getMessage(), [
'message' => 'Failed to send share by mail. Got an invalid email address ' . $share->getSharedWith(),
$this->logger->error('Failed to send share by mail. Got an invalid email address ' . $share->getSharedWith(), [
'app' => 'sharebymail',
'exception' => $e,
]);
}

Expand Down Expand Up @@ -689,7 +689,7 @@ public function getChildren(IShare $parent) {
* @param \DateTime|null $expirationTime
* @return int
*/
protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $password, $sendPasswordByTalk, $hideDownload, $label, $expirationTime, $note = '') {
protected function addShareToDB($itemSource, $itemType, $shareWith, $sharedBy, $uidOwner, $permissions, $token, $password, $sendPasswordByTalk, $hideDownload, $label, $expirationTime, $note = ''): int {
$qb = $this->dbConnection->getQueryBuilder();
$qb->insert('share')
->setValue('share_type', $qb->createNamedParameter(IShare::TYPE_EMAIL))
Expand Down Expand Up @@ -784,7 +784,7 @@ public function delete(IShare $share) {
} catch (\Exception $e) {
}

$this->removeShareFromTable($share->getId());
$this->removeShareFromTable((int)$share->getId());
}

/**
Expand Down Expand Up @@ -980,9 +980,9 @@ public function getShareByToken($token) {
/**
* remove share from table
*
* @param string $shareId
* @param int $shareId
*/
protected function removeShareFromTable($shareId) {
protected function removeShareFromTable(int $shareId): void {
$qb = $this->dbConnection->getQueryBuilder();
$qb->delete('share')
->where($qb->expr()->eq('id', $qb->createNamedParameter($shareId)));
Expand Down
4 changes: 4 additions & 0 deletions apps/sharebymail/tests/ShareByMailProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ public function testCreateFailed() {
public function testCreateMailShare() {
$this->share->expects($this->any())->method('getToken')->willReturn('token');
$this->share->expects($this->once())->method('setToken')->with('token');
$this->share->expects($this->any())->method('getSharedWith')->willReturn('[email protected]');
$node = $this->getMockBuilder('OCP\Files\Node')->getMock();
$node->expects($this->any())->method('getName')->willReturn('fileName');
$this->share->expects($this->any())->method('getNode')->willReturn($node);
Expand All @@ -483,6 +484,7 @@ public function testCreateMailShareFailed() {

$this->share->expects($this->any())->method('getToken')->willReturn('token');
$this->share->expects($this->once())->method('setToken')->with('token');
$this->share->expects($this->any())->method('getSharedWith')->willReturn('[email protected]');
$node = $this->getMockBuilder('OCP\Files\Node')->getMock();
$node->expects($this->any())->method('getName')->willReturn('fileName');
$this->share->expects($this->any())->method('getNode')->willReturn($node);
Expand Down Expand Up @@ -987,6 +989,7 @@ public function testGetSharesInFolder() {
->willReturn(new \OC\Share20\Share($rootFolder, $userManager));

$provider = $this->getInstance(['sendMailNotification', 'createShareActivity']);
$this->mailer->expects($this->any())->method('validateMailAddress')->willReturn(true);

$u1 = $userManager->createUser('testFed', md5(time()));
$u2 = $userManager->createUser('testFed2', md5(time()));
Expand Down Expand Up @@ -1033,6 +1036,7 @@ public function testGetAccessList() {
->willReturn(new \OC\Share20\Share($rootFolder, $userManager));

$provider = $this->getInstance(['sendMailNotification', 'createShareActivity']);
$this->mailer->expects($this->any())->method('validateMailAddress')->willReturn(true);

$u1 = $userManager->createUser('testFed', md5(time()));
$u2 = $userManager->createUser('testFed2', md5(time()));
Expand Down