mirror of
https://github.com/nextcloud/passman.git
synced 2025-11-09 21:51:36 +08:00
improve in-code type usage and update php syntax to 8.1 using rector
Signed-off-by: binsky <timo@binsky.org>
This commit is contained in:
parent
a8e48902d2
commit
be643a82f7
40 changed files with 273 additions and 281 deletions
|
|
@ -88,7 +88,7 @@ return [
|
|||
['name' => 'Icon#getLocalIconList', 'url' => '/api/v2/icon/list', 'verb' => 'GET'],
|
||||
|
||||
//
|
||||
['name' => 'Vault#preflighted_cors', 'url' => '/api/v2/{path}', 'verb' => 'OPTIONS', 'requirements' => array('path' => '.+')],
|
||||
['name' => 'Vault#preflighted_cors', 'url' => '/api/v2/{path}', 'verb' => 'OPTIONS', 'requirements' => ['path' => '.+']],
|
||||
//Internal API
|
||||
['name' => 'Internal#remind', 'url' => '/api/internal/notifications/remind/{credential_id}', 'verb' => 'POST'],
|
||||
['name' => 'Internal#read', 'url' => '/api/internal/notifications/read/{credential_id}', 'verb' => 'DELETE'],
|
||||
|
|
|
|||
|
|
@ -6,5 +6,12 @@
|
|||
"email": "brantje@gmail.com"
|
||||
}
|
||||
],
|
||||
"require": {}
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"scripts": {
|
||||
"rector:check": "rector --dry-run --clear-cache",
|
||||
"rector:fix": "rector"
|
||||
},
|
||||
"require-dev": {
|
||||
"rector/rector": "^2.1"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -227,18 +227,15 @@ class Activity implements \OCP\Activity\IExtension {
|
|||
* @param string $type
|
||||
* @return string|false
|
||||
*/
|
||||
public function getTypeIcon($type) {
|
||||
switch ($type) {
|
||||
case self::TYPE_ITEM_ACTION:
|
||||
case self::TYPE_ITEM_EXPIRED:
|
||||
return 'icon-password';
|
||||
case self::TYPE_ITEM_SHARED:
|
||||
return 'icon-share';
|
||||
case self::TYPE_ITEM_RENAMED:
|
||||
return 'icon-rename';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public function getTypeIcon($type)
|
||||
{
|
||||
return match ($type) {
|
||||
self::TYPE_ITEM_ACTION, self::TYPE_ITEM_EXPIRED => 'icon-password',
|
||||
self::TYPE_ITEM_SHARED => 'icon-share',
|
||||
self::TYPE_ITEM_RENAMED => 'icon-rename',
|
||||
default => false,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The extension can define the parameter grouping by returning the index as integer.
|
||||
|
|
|
|||
|
|
@ -69,13 +69,9 @@ class Application extends App implements IBootstrap {
|
|||
|
||||
$context->registerSearchProvider(Provider::class);
|
||||
|
||||
$context->registerService(View::class, function () {
|
||||
return new View('');
|
||||
}, false);
|
||||
$context->registerService(View::class, fn() => new View(''), false);
|
||||
|
||||
$context->registerService('isCLI', function () {
|
||||
return \OC::$CLI;
|
||||
});
|
||||
$context->registerService('isCLI', fn() => \OC::$CLI);
|
||||
|
||||
$context->registerMiddleware(ShareMiddleware::class);
|
||||
$context->registerMiddleware(APIMiddleware::class);
|
||||
|
|
@ -106,20 +102,16 @@ class Application extends App implements IBootstrap {
|
|||
});
|
||||
|
||||
|
||||
$context->registerService('CronService', function (ContainerInterface $c) {
|
||||
return new CronService(
|
||||
$context->registerService('CronService', fn(ContainerInterface $c) => new CronService(
|
||||
$c->get(CredentialService::class),
|
||||
$c->get(LoggerInterface::class),
|
||||
$c->get(Utils::class),
|
||||
$c->get(NotificationService::class),
|
||||
$c->get(ActivityService::class),
|
||||
$c->get(IDBConnection::class)
|
||||
);
|
||||
});
|
||||
));
|
||||
|
||||
$context->registerService('Logger', function (ContainerInterface $c) {
|
||||
return $c->get(ServerContainer::class)->getLogger();
|
||||
});
|
||||
$context->registerService('Logger', fn(ContainerInterface $c) => $c->get(ServerContainer::class)->getLogger());
|
||||
}
|
||||
|
||||
public function boot(IBootContext $context): void {
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ class ExpireCredentials extends TimedJob {
|
|||
public function __construct(
|
||||
ITimeFactory $timeFactory,
|
||||
protected IConfig $config,
|
||||
private CronService $cronService,
|
||||
private readonly CronService $cronService,
|
||||
) {
|
||||
parent::__construct($timeFactory);
|
||||
|
||||
|
|
|
|||
|
|
@ -28,19 +28,17 @@ use OCP\IUserManager;
|
|||
|
||||
|
||||
class AdminController extends ApiController {
|
||||
private $userId;
|
||||
|
||||
public function __construct(
|
||||
$AppName,
|
||||
IRequest $request,
|
||||
$UserId,
|
||||
private VaultService $vaultService,
|
||||
private CredentialService $credentialService,
|
||||
private FileService $fileService,
|
||||
private CredentialRevisionService $revisionService,
|
||||
private DeleteVaultRequestService $deleteVaultRequestService,
|
||||
private IConfig $config,
|
||||
private IUserManager $userManager,
|
||||
private $userId,
|
||||
private readonly VaultService $vaultService,
|
||||
private readonly CredentialService $credentialService,
|
||||
private readonly FileService $fileService,
|
||||
private readonly CredentialRevisionService $revisionService,
|
||||
private readonly DeleteVaultRequestService $deleteVaultRequestService,
|
||||
private readonly IConfig $config,
|
||||
private readonly IUserManager $userManager,
|
||||
) {
|
||||
parent::__construct(
|
||||
$AppName,
|
||||
|
|
@ -48,7 +46,6 @@ class AdminController extends ApiController {
|
|||
'GET, POST, DELETE, PUT, PATCH, OPTIONS',
|
||||
'Authorization, Content-Type, Accept',
|
||||
86400);
|
||||
$this->userId = $UserId;
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -121,7 +118,7 @@ class AdminController extends ApiController {
|
|||
$req = $this->deleteVaultRequestService->getDeleteRequestForVault($vault_guid);
|
||||
try{
|
||||
$vault = $this->vaultService->getByGuid($vault_guid, $requested_by);
|
||||
} catch (\Exception $e){
|
||||
} catch (\Exception){
|
||||
//Ignore
|
||||
}
|
||||
|
||||
|
|
@ -175,7 +172,7 @@ class AdminController extends ApiController {
|
|||
$result = false;
|
||||
try {
|
||||
$delete_request = $this->deleteVaultRequestService->getDeleteRequestForVault($vault_guid);
|
||||
} catch (\Exception $exception){
|
||||
} catch (\Exception){
|
||||
// Ignore it
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,17 +28,15 @@ use OCP\IRequest;
|
|||
|
||||
|
||||
class CredentialController extends ApiController {
|
||||
private $userId;
|
||||
|
||||
public function __construct(
|
||||
$AppName,
|
||||
IRequest $request,
|
||||
$userId,
|
||||
private CredentialService $credentialService,
|
||||
private ActivityService $activityService,
|
||||
private CredentialRevisionService $credentialRevisionService,
|
||||
private ShareService $sharingService,
|
||||
private SettingsService $settings,
|
||||
private $userId,
|
||||
private readonly CredentialService $credentialService,
|
||||
private readonly ActivityService $activityService,
|
||||
private readonly CredentialRevisionService $credentialRevisionService,
|
||||
private readonly ShareService $sharingService,
|
||||
private readonly SettingsService $settings,
|
||||
) {
|
||||
parent::__construct(
|
||||
$AppName,
|
||||
|
|
@ -46,7 +44,6 @@ class CredentialController extends ApiController {
|
|||
'GET, POST, DELETE, PUT, PATCH, OPTIONS',
|
||||
'Authorization, Content-Type, Accept',
|
||||
86400);
|
||||
$this->userId = $userId;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -199,7 +196,7 @@ class CredentialController extends ApiController {
|
|||
|
||||
try {
|
||||
$acl_list = $this->sharingService->getCredentialAclList($storedCredential->getGuid());
|
||||
} catch (\Exception $exception) {
|
||||
} catch (\Exception) {
|
||||
// Just check if we have an acl list
|
||||
}
|
||||
if (!empty($acl_list)) {
|
||||
|
|
@ -264,7 +261,7 @@ class CredentialController extends ApiController {
|
|||
public function deleteCredential($credential_guid) {
|
||||
try {
|
||||
$credential = $this->credentialService->getCredentialByGUID($credential_guid, $this->userId);
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Exception) {
|
||||
return new NotFoundJSONResponse();
|
||||
}
|
||||
if ($credential instanceof Credential) {
|
||||
|
|
@ -285,7 +282,7 @@ class CredentialController extends ApiController {
|
|||
public function getRevision($credential_guid) {
|
||||
try {
|
||||
$credential = $this->credentialService->getCredentialByGUID($credential_guid);
|
||||
} catch (\Exception $ex) {
|
||||
} catch (\Exception) {
|
||||
return new NotFoundJSONResponse();
|
||||
}
|
||||
// If the request was made by the owner of the credential
|
||||
|
|
@ -320,7 +317,7 @@ class CredentialController extends ApiController {
|
|||
$revision = null;
|
||||
try {
|
||||
$revision = $this->credentialRevisionService->getRevision($revision_id);
|
||||
} catch (\Exception $exception) {
|
||||
} catch (\Exception) {
|
||||
return new JSONResponse([]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,14 +18,12 @@ use OCP\IRequest;
|
|||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class FileController extends ApiController {
|
||||
private $userId;
|
||||
|
||||
public function __construct(
|
||||
$AppName,
|
||||
IRequest $request,
|
||||
$UserId,
|
||||
private FileService $fileService,
|
||||
private LoggerInterface $logger,
|
||||
private $userId,
|
||||
private readonly FileService $fileService,
|
||||
private readonly LoggerInterface $logger,
|
||||
) {
|
||||
parent::__construct(
|
||||
$AppName,
|
||||
|
|
@ -33,7 +31,6 @@ class FileController extends ApiController {
|
|||
'GET, POST, DELETE, PUT, PATCH, OPTIONS',
|
||||
'Authorization, Content-Type, Accept',
|
||||
86400);
|
||||
$this->userId = $UserId;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -97,7 +94,7 @@ class FileController extends ApiController {
|
|||
public function updateFile($file_id, $file_data, $filename) {
|
||||
try {
|
||||
$file = $this->fileService->getFile($file_id, $this->userId);
|
||||
} catch (\Exception $doesNotExistException) {
|
||||
} catch (\Exception) {
|
||||
|
||||
}
|
||||
if ($file) {
|
||||
|
|
|
|||
|
|
@ -24,16 +24,15 @@ use OCP\IRequest;
|
|||
use OCP\IURLGenerator;
|
||||
|
||||
class IconController extends ApiController {
|
||||
private $userId;
|
||||
const ICON_CACHE_OFFSET = 2592000; // 3600 * 24 * 30
|
||||
|
||||
public function __construct(
|
||||
$AppName,
|
||||
IRequest $request,
|
||||
$UserId,
|
||||
private CredentialService $credentialService,
|
||||
private AppManager $am,
|
||||
private IURLGenerator $urlGenerator,
|
||||
private $userId,
|
||||
private readonly CredentialService $credentialService,
|
||||
private readonly AppManager $am,
|
||||
private readonly IURLGenerator $urlGenerator,
|
||||
) {
|
||||
parent::__construct(
|
||||
$AppName,
|
||||
|
|
@ -41,8 +40,6 @@ class IconController extends ApiController {
|
|||
'GET, POST, DELETE, PUT, PATCH, OPTIONS',
|
||||
'Authorization, Content-Type, Accept',
|
||||
86400);
|
||||
$this->userId = $UserId;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -78,7 +75,7 @@ class IconController extends ApiController {
|
|||
try {
|
||||
$credential = $this->credentialService->getCredentialById($credentialId, $this->userId);
|
||||
$credential = $credential->jsonSerialize();
|
||||
} catch (DoesNotExistException $e) {
|
||||
} catch (DoesNotExistException) {
|
||||
// Credential is not found, continue
|
||||
$credential = false;
|
||||
}
|
||||
|
|
@ -97,14 +94,14 @@ class IconController extends ApiController {
|
|||
$data = $icon->icoData;
|
||||
$type = $icon->icoType;
|
||||
}
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
} catch (\InvalidArgumentException) {
|
||||
//no need to do stuff in catch
|
||||
//if IconService fails the predefined $data and $type are used
|
||||
}
|
||||
|
||||
if (isset($credential) && $credential['user_id'] == $this->userId) {
|
||||
$iconData = [
|
||||
'type' => ($type) ? $type : 'x-icon',
|
||||
'type' => $type ?: 'x-icon',
|
||||
'content' => base64_encode($data)
|
||||
];
|
||||
$credential['icon'] = json_encode($iconData);
|
||||
|
|
@ -112,7 +109,7 @@ class IconController extends ApiController {
|
|||
if ($credential) {
|
||||
$this->credentialService->updateCredential($credential);
|
||||
}
|
||||
} catch (DriverException $exception) {
|
||||
} catch (DriverException) {
|
||||
/**
|
||||
* @FIXME Syntax error or access violation: 1118 Row size too large
|
||||
* This happens when favicons are quite big.
|
||||
|
|
@ -146,7 +143,7 @@ class IconController extends ApiController {
|
|||
$icons = [];
|
||||
foreach ($result as $icon) {
|
||||
$iconPath = $icon;
|
||||
$path = explode('passman/', $iconPath);
|
||||
$path = explode('passman/', (string) $iconPath);
|
||||
$pack = explode('/', $path[1])[2];
|
||||
$mime = mime_content_type($iconPath);
|
||||
if ($mime !== 'directory') {
|
||||
|
|
|
|||
|
|
@ -21,16 +21,14 @@ use OCP\IConfig;
|
|||
use OCP\IRequest;
|
||||
|
||||
class InternalController extends ApiController {
|
||||
private $userId;
|
||||
|
||||
public function __construct(
|
||||
$AppName,
|
||||
IRequest $request,
|
||||
$UserId,
|
||||
private CredentialService $credentialService,
|
||||
private NotificationService $notificationService,
|
||||
private IConfig $config,
|
||||
private IAppManager $appManager,
|
||||
private $userId,
|
||||
private readonly CredentialService $credentialService,
|
||||
private readonly NotificationService $notificationService,
|
||||
private readonly IConfig $config,
|
||||
private readonly IAppManager $appManager,
|
||||
) {
|
||||
parent::__construct(
|
||||
$AppName,
|
||||
|
|
@ -38,7 +36,6 @@ class InternalController extends ApiController {
|
|||
'GET, POST, DELETE, PUT, PATCH, OPTIONS',
|
||||
'Authorization, Content-Type, Accept',
|
||||
86400);
|
||||
$this->userId = $UserId;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ class SettingsController extends ApiController {
|
|||
$AppName,
|
||||
IRequest $request,
|
||||
private $userId,
|
||||
private SettingsService $settings,
|
||||
private IL10N $l,
|
||||
private readonly SettingsService $settings,
|
||||
private readonly IL10N $l,
|
||||
) {
|
||||
parent::__construct(
|
||||
$AppName,
|
||||
|
|
|
|||
|
|
@ -35,25 +35,23 @@ use OCP\Notification\IManager;
|
|||
|
||||
|
||||
class ShareController extends ApiController {
|
||||
private $userId;
|
||||
|
||||
private $limit = 50;
|
||||
private $offset = 0;
|
||||
|
||||
public function __construct(
|
||||
$AppName,
|
||||
IRequest $request,
|
||||
$UserId,
|
||||
private IGroupManager $groupManager,
|
||||
private IUserManager $userManager,
|
||||
private ActivityService $activityService,
|
||||
private VaultService $vaultService,
|
||||
private ShareService $shareService,
|
||||
private CredentialService $credentialService,
|
||||
private NotificationService $notificationService,
|
||||
private FileService $fileService,
|
||||
private SettingsService $settings,
|
||||
private IManager $manager,
|
||||
private $userId,
|
||||
private readonly IGroupManager $groupManager,
|
||||
private readonly IUserManager $userManager,
|
||||
private readonly ActivityService $activityService,
|
||||
private readonly VaultService $vaultService,
|
||||
private readonly ShareService $shareService,
|
||||
private readonly CredentialService $credentialService,
|
||||
private readonly NotificationService $notificationService,
|
||||
private readonly FileService $fileService,
|
||||
private readonly SettingsService $settings,
|
||||
private readonly IManager $manager,
|
||||
) {
|
||||
parent::__construct(
|
||||
$AppName,
|
||||
|
|
@ -61,8 +59,6 @@ class ShareController extends ApiController {
|
|||
'GET, POST, DELETE, PUT, PATCH, OPTIONS',
|
||||
'Authorization, Content-Type, Accept',
|
||||
86400);
|
||||
|
||||
$this->userId = $UserId;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -83,7 +79,7 @@ class ShareController extends ApiController {
|
|||
|
||||
try {
|
||||
$acl = $this->shareService->getACL(null, $item_guid);
|
||||
} catch (\Exception $exception) {
|
||||
} catch (\Exception) {
|
||||
$acl = new SharingACL();
|
||||
}
|
||||
|
||||
|
|
@ -132,7 +128,7 @@ class ShareController extends ApiController {
|
|||
$acl = null;
|
||||
try {
|
||||
$acl = $this->shareService->getCredentialAclForUser($first_vault['user_id'], $item_guid);
|
||||
} catch (\Exception $exception) {
|
||||
} catch (\Exception) {
|
||||
// no need to catch this
|
||||
}
|
||||
|
||||
|
|
@ -147,7 +143,7 @@ class ShareController extends ApiController {
|
|||
if (!in_array($vault->getTargetUserId(), $processed_users)) {
|
||||
$target_user = $vault->getTargetUserId();
|
||||
$notification = [
|
||||
'from_user' => ucfirst($this->userId->getDisplayName()),
|
||||
'from_user' => ucfirst((string) $this->userId->getDisplayName()),
|
||||
'credential_label' => $credential->getLabel(),
|
||||
'credential_id' => $credential->getId(),
|
||||
'item_id' => $credential->getId(),
|
||||
|
|
@ -222,7 +218,7 @@ class ShareController extends ApiController {
|
|||
try {
|
||||
$shareRequests = $this->shareService->getPendingShareRequestsForCredential($item_guid, $user_id);
|
||||
$sr = array_pop($shareRequests);
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Exception) {
|
||||
// no need to catch this
|
||||
}
|
||||
|
||||
|
|
@ -275,7 +271,7 @@ class ShareController extends ApiController {
|
|||
public function savePendingRequest($item_guid, $target_vault_guid, $final_shared_key) {
|
||||
try {
|
||||
$sr = $this->shareService->getRequestByGuid($item_guid, $target_vault_guid);
|
||||
} catch (\Exception $ex) {
|
||||
} catch (\Exception) {
|
||||
return new NotFoundResponse();
|
||||
}
|
||||
|
||||
|
|
@ -286,7 +282,7 @@ class ShareController extends ApiController {
|
|||
$this->manager->markProcessed($notification);
|
||||
|
||||
$notification = [
|
||||
'from_user' => ucfirst($this->userId->getDisplayName()),
|
||||
'from_user' => ucfirst((string) $this->userId->getDisplayName()),
|
||||
'credential_label' => $this->credentialService->getCredentialLabelById($sr->getItemId())->getLabel(),
|
||||
'target_user' => $sr->getFromUserId(),
|
||||
'req_id' => $sr->getId()
|
||||
|
|
@ -315,7 +311,7 @@ class ShareController extends ApiController {
|
|||
$results[] = $result;
|
||||
}
|
||||
return new JSONResponse($results);
|
||||
} catch (\Exception $ex) {
|
||||
} catch (\Exception) {
|
||||
return new NotFoundResponse();
|
||||
}
|
||||
}
|
||||
|
|
@ -329,7 +325,7 @@ class ShareController extends ApiController {
|
|||
public function getRevisions($item_guid) {
|
||||
try {
|
||||
return new JSONResponse($this->shareService->getItemHistory($this->userId, $item_guid));
|
||||
} catch (\Exception $ex) {
|
||||
} catch (\Exception) {
|
||||
return new NotFoundJSONResponse();
|
||||
}
|
||||
}
|
||||
|
|
@ -343,7 +339,7 @@ class ShareController extends ApiController {
|
|||
public function getVaultItems($vault_guid) {
|
||||
try {
|
||||
return new JSONResponse($this->shareService->getSharedItems($this->userId->getUID(), $vault_guid));
|
||||
} catch (\Exception $ex) {
|
||||
} catch (\Exception) {
|
||||
return new NotFoundResponse();
|
||||
}
|
||||
}
|
||||
|
|
@ -357,7 +353,7 @@ class ShareController extends ApiController {
|
|||
public function getVaultAclEntries($vault_guid) {
|
||||
try {
|
||||
return new JSONResponse($this->shareService->getVaultAclList($this->userId->getUID(), $vault_guid));
|
||||
} catch (\Exception $ex) {
|
||||
} catch (\Exception) {
|
||||
return new NotFoundResponse();
|
||||
}
|
||||
}
|
||||
|
|
@ -373,7 +369,7 @@ class ShareController extends ApiController {
|
|||
|
||||
$sr = $this->shareService->getShareRequestById($share_request_id);
|
||||
$notification = [
|
||||
'from_user' => ucfirst($this->userId->getDisplayName()),
|
||||
'from_user' => ucfirst((string) $this->userId->getDisplayName()),
|
||||
'credential_label' => $this->credentialService->getCredentialLabelById($sr->getItemId())->getLabel(),
|
||||
'target_user' => $sr->getFromUserId(),
|
||||
'req_id' => $sr->getId()
|
||||
|
|
@ -391,7 +387,7 @@ class ShareController extends ApiController {
|
|||
|
||||
$this->shareService->cleanItemRequestsForUser($sr);
|
||||
return new JSONResponse(['result' => true]);
|
||||
} catch (\Exception $ex) {
|
||||
} catch (\Exception) {
|
||||
return new NotFoundJSONResponse();
|
||||
}
|
||||
}
|
||||
|
|
@ -424,7 +420,7 @@ class ShareController extends ApiController {
|
|||
try {
|
||||
$credential = $this->shareService->getSharedItem(null, $credential_guid);
|
||||
return new JSONResponse($credential);
|
||||
} catch (\Exception $ex) {
|
||||
} catch (\Exception) {
|
||||
return new NotFoundJSONResponse();
|
||||
}
|
||||
}
|
||||
|
|
@ -450,7 +446,7 @@ class ShareController extends ApiController {
|
|||
} else {
|
||||
return new NotFoundResponse();
|
||||
}
|
||||
} catch (\Exception $ex) {
|
||||
} catch (\Exception) {
|
||||
return new JSONResponse([]);
|
||||
}
|
||||
}
|
||||
|
|
@ -467,7 +463,7 @@ class ShareController extends ApiController {
|
|||
public function getFile($item_guid, $file_guid) {
|
||||
try {
|
||||
$credential = $this->credentialService->getCredentialByGUID($item_guid);
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Exception) {
|
||||
return new NotFoundJSONResponse();
|
||||
}
|
||||
|
||||
|
|
@ -497,7 +493,7 @@ class ShareController extends ApiController {
|
|||
public function uploadFile($item_guid, $data, $filename, $mimetype, $size) {
|
||||
try {
|
||||
$credential = $this->credentialService->getCredentialByGUID($item_guid);
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Exception) {
|
||||
return new NotFoundJSONResponse();
|
||||
}
|
||||
|
||||
|
|
@ -532,7 +528,7 @@ class ShareController extends ApiController {
|
|||
public function updateSharedCredentialACL($item_guid, $user_id, $permission) {
|
||||
try {
|
||||
$credential = $this->credentialService->getCredentialByGUID($item_guid);
|
||||
} catch (\Exception $exception) {
|
||||
} catch (\Exception) {
|
||||
return new NotFoundJSONResponse();
|
||||
}
|
||||
if ($this->userId->getUID() === $credential->getUserId()) {
|
||||
|
|
@ -541,7 +537,7 @@ class ShareController extends ApiController {
|
|||
$acl = $this->shareService->getACL($user_id, $item_guid);
|
||||
$acl->setPermissions($permission);
|
||||
return $this->shareService->updateCredentialACL($acl);
|
||||
} catch (\Exception $exception) {
|
||||
} catch (\Exception) {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ class TranslationController extends ApiController {
|
|||
public function __construct(
|
||||
$AppName,
|
||||
IRequest $request,
|
||||
private IL10N $trans,
|
||||
private readonly IL10N $trans,
|
||||
) {
|
||||
parent::__construct(
|
||||
$AppName,
|
||||
|
|
|
|||
|
|
@ -25,18 +25,16 @@ use Psr\Log\LoggerInterface;
|
|||
|
||||
|
||||
class VaultController extends ApiController {
|
||||
private $userId;
|
||||
|
||||
public function __construct(
|
||||
$AppName,
|
||||
IRequest $request,
|
||||
$UserId,
|
||||
private VaultService $vaultService,
|
||||
private CredentialService $credentialService,
|
||||
private DeleteVaultRequestService $deleteVaultRequestService,
|
||||
private SettingsService $settings,
|
||||
private FileService $fileService,
|
||||
private LoggerInterface $logger,
|
||||
private $userId,
|
||||
private readonly VaultService $vaultService,
|
||||
private readonly CredentialService $credentialService,
|
||||
private readonly DeleteVaultRequestService $deleteVaultRequestService,
|
||||
private readonly SettingsService $settings,
|
||||
private readonly FileService $fileService,
|
||||
private readonly LoggerInterface $logger,
|
||||
) {
|
||||
parent::__construct(
|
||||
$AppName,
|
||||
|
|
@ -44,7 +42,6 @@ class VaultController extends ApiController {
|
|||
'GET, POST, DELETE, PUT, PATCH, OPTIONS',
|
||||
'Authorization, Content-Type, Accept',
|
||||
86400);
|
||||
$this->userId = $UserId;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -95,7 +92,7 @@ class VaultController extends ApiController {
|
|||
$vault = null;
|
||||
try {
|
||||
$vault = $this->vaultService->getByGuid($vault_guid, $this->userId);
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Exception) {
|
||||
return new NotFoundJSONResponse();
|
||||
}
|
||||
$result = [];
|
||||
|
|
@ -146,8 +143,8 @@ class VaultController extends ApiController {
|
|||
$vault = null;
|
||||
try {
|
||||
$vault = $this->vaultService->getByGuid($vault_guid, $this->userId);
|
||||
} catch (\Exception $e) {
|
||||
// No need to catch the execption
|
||||
} catch (\Exception) {
|
||||
// No need to catch the exception
|
||||
}
|
||||
|
||||
if ($vault) {
|
||||
|
|
@ -181,7 +178,7 @@ class VaultController extends ApiController {
|
|||
}
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Exception) {
|
||||
return new NotFoundJSONResponse();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class CredentialMapper extends QBMapper {
|
|||
|
||||
public function __construct(
|
||||
IDBConnection $db,
|
||||
private Utils $utils,
|
||||
private readonly Utils $utils,
|
||||
) {
|
||||
parent::__construct($db, self::TABLE_NAME);
|
||||
}
|
||||
|
|
@ -59,14 +59,14 @@ class CredentialMapper extends QBMapper {
|
|||
return $this->findEntities($qb);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a random credential from a vault
|
||||
*
|
||||
* @param string $vault_id
|
||||
* @param string $user_id
|
||||
* @return Credential[]
|
||||
*/
|
||||
public function getRandomCredentialByVaultId(string $vault_id, string $user_id) {
|
||||
/**
|
||||
* Get a random credential from a vault
|
||||
*
|
||||
* @param string $vault_id
|
||||
* @param string $user_id
|
||||
* @return Credential[]
|
||||
*/
|
||||
public function getRandomCredentialByVaultId(string $vault_id, string $user_id): array {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
$qb->select('*')
|
||||
->from(self::TABLE_NAME)
|
||||
|
|
@ -78,9 +78,7 @@ class CredentialMapper extends QBMapper {
|
|||
$entities = $this->findEntities($qb);
|
||||
$count = count($entities) - 1;
|
||||
|
||||
/** @var Credential[] $entity */
|
||||
$entity = array_splice($entities, rand(0, $count), 1);
|
||||
return $entity;
|
||||
return array_splice($entities, rand(0, $count), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -33,11 +33,9 @@ use OCP\IDBConnection;
|
|||
|
||||
class CredentialRevisionMapper extends QBMapper {
|
||||
const TABLE_NAME = 'passman_revisions';
|
||||
private Utils $utils;
|
||||
|
||||
public function __construct(IDBConnection $db, Utils $utils) {
|
||||
public function __construct(IDBConnection $db, private readonly Utils $utils) {
|
||||
parent::__construct($db, self::TABLE_NAME);
|
||||
$this->utils = $utils;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class FileMapper extends QBMapper {
|
|||
|
||||
public function __construct(
|
||||
IDBConnection $db,
|
||||
private Utils $utils,
|
||||
private readonly Utils $utils,
|
||||
) {
|
||||
parent::__construct($db, self::TABLE_NAME);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,8 +74,8 @@ class ShareRequestMapper extends QBMapper {
|
|||
* @return Entity[]
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getRequestsByItemGuid(string $item_guid) {
|
||||
if (strtolower($this->db->getDatabasePlatform()->getName()) === 'mysql') {
|
||||
public function getRequestsByItemGuid(string $item_guid): array {
|
||||
if ($this->db->getDatabaseProvider() === IDBConnection::PLATFORM_MYSQL) {
|
||||
$this->db->executeQuery("SET sql_mode = '';");
|
||||
}
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class VaultMapper extends QBMapper {
|
|||
|
||||
public function __construct(
|
||||
IDBConnection $db,
|
||||
private Utils $utils,
|
||||
private readonly Utils $utils,
|
||||
) {
|
||||
parent::__construct($db, self::TABLE_NAME);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use OCP\IRequest;
|
|||
class APIMiddleware extends Middleware {
|
||||
|
||||
public function __construct(
|
||||
private IRequest $request,
|
||||
private readonly IRequest $request,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,11 +10,9 @@ use OCP\AppFramework\Middleware;
|
|||
|
||||
class ShareMiddleware extends Middleware {
|
||||
|
||||
private $settings;
|
||||
|
||||
public function __construct(SettingsService $config) {
|
||||
$this->settings = $config;
|
||||
}
|
||||
public function __construct(private readonly SettingsService $settings)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public function beforeController($controller, $methodName) {
|
||||
|
|
|
|||
|
|
@ -43,12 +43,12 @@ class ServerSideEncryption implements IRepairStep {
|
|||
private $installedVersion;
|
||||
|
||||
public function __construct(
|
||||
private EncryptService $encryptService,
|
||||
private IDBConnection $db,
|
||||
private LoggerInterface $logger,
|
||||
private CredentialService $credentialService,
|
||||
private CredentialRevisionService $revisionService,
|
||||
private FileService $fileService,
|
||||
private readonly EncryptService $encryptService,
|
||||
private readonly IDBConnection $db,
|
||||
private readonly LoggerInterface $logger,
|
||||
private readonly CredentialService $credentialService,
|
||||
private readonly CredentialRevisionService $revisionService,
|
||||
private readonly FileService $fileService,
|
||||
IConfig $config,
|
||||
) {
|
||||
$this->installedVersion = $config->getAppValue('passman', 'installed_version');
|
||||
|
|
|
|||
|
|
@ -43,10 +43,10 @@ use OCP\Search\SearchResultEntry;
|
|||
class Provider implements IProvider {
|
||||
|
||||
public function __construct(
|
||||
private IL10N $l10n,
|
||||
private IURLGenerator $urlGenerator,
|
||||
private IDBConnection $db,
|
||||
private SettingsService $settings,
|
||||
private readonly IL10N $l10n,
|
||||
private readonly IURLGenerator $urlGenerator,
|
||||
private readonly IDBConnection $db,
|
||||
private readonly SettingsService $settings,
|
||||
) {
|
||||
|
||||
}
|
||||
|
|
@ -60,7 +60,7 @@ class Provider implements IProvider {
|
|||
}
|
||||
|
||||
public function getOrder(string $route, array $routeParameters): int {
|
||||
if (strpos($route, Application::APP_ID . '.') === 0) {
|
||||
if (str_starts_with($route, Application::APP_ID . '.')) {
|
||||
// Active app, prefer my results
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -81,7 +81,7 @@ class Provider implements IProvider {
|
|||
$Credentials = $CredentialMapper->getCredentialsByVaultId($Vault->getId(), $Vault->getUserId());
|
||||
|
||||
foreach ($Credentials as $Credential) {
|
||||
if (strpos($Credential->getLabel(), $query->getTerm()) !== false) {
|
||||
if (str_contains((string) $Credential->getLabel(), $query->getTerm())) {
|
||||
try {
|
||||
$searchResultEntries[] = new SearchResultEntry(
|
||||
$this->urlGenerator->imagePath(Application::APP_ID, 'app.svg'),
|
||||
|
|
@ -89,12 +89,11 @@ class Provider implements IProvider {
|
|||
\sprintf("Part of Passman vault %s", $Vault->getName()),
|
||||
$this->urlGenerator->linkToRoute('passman.Page.index') . "#/vault/" . $Vault->getGuid() . "?show=" . $Credential->getGuid()
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Exception) {
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (DoesNotExistException $e) {
|
||||
} catch (MultipleObjectsReturnedException $e) {
|
||||
} catch (DoesNotExistException|MultipleObjectsReturnedException) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,8 +36,8 @@ class CredentialRevisionService {
|
|||
private $server_key;
|
||||
|
||||
public function __construct(
|
||||
private CredentialRevisionMapper $credentialRevisionMapper,
|
||||
private EncryptService $encryptService,
|
||||
private readonly CredentialRevisionMapper $credentialRevisionMapper,
|
||||
private readonly EncryptService $encryptService,
|
||||
IConfig $config,
|
||||
) {
|
||||
$this->server_key = $config->getSystemValue('passwordsalt', '');
|
||||
|
|
|
|||
|
|
@ -40,15 +40,15 @@ class CredentialService {
|
|||
private $server_key;
|
||||
|
||||
public function __construct(
|
||||
private CredentialMapper $credentialMapper,
|
||||
private SharingACLMapper $sharingACL,
|
||||
private ActivityService $activityService,
|
||||
private ShareService $shareService,
|
||||
private EncryptService $encryptService,
|
||||
private CredentialRevisionService $credentialRevisionService,
|
||||
private IURLGenerator $urlGenerator,
|
||||
private VaultService $vaultService,
|
||||
private NotificationService $notificationService,
|
||||
private readonly CredentialMapper $credentialMapper,
|
||||
private readonly SharingACLMapper $sharingACL,
|
||||
private readonly ActivityService $activityService,
|
||||
private readonly ShareService $shareService,
|
||||
private readonly EncryptService $encryptService,
|
||||
private readonly CredentialRevisionService $credentialRevisionService,
|
||||
private readonly IURLGenerator $urlGenerator,
|
||||
private readonly VaultService $vaultService,
|
||||
private readonly NotificationService $notificationService,
|
||||
IConfig $config,
|
||||
) {
|
||||
$this->server_key = $config->getSystemValue('passwordsalt', '');
|
||||
|
|
|
|||
|
|
@ -32,11 +32,11 @@ use Psr\Log\LoggerInterface;
|
|||
class CronService {
|
||||
|
||||
public function __construct(
|
||||
private CredentialService $credentialService,
|
||||
private LoggerInterface $logger,
|
||||
private Utils $utils,
|
||||
private NotificationService $notificationService,
|
||||
private ActivityService $activityService,
|
||||
private readonly CredentialService $credentialService,
|
||||
private readonly LoggerInterface $logger,
|
||||
private readonly Utils $utils,
|
||||
private readonly NotificationService $notificationService,
|
||||
private readonly ActivityService $activityService,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ use OCP\AppFramework\Db\Entity;
|
|||
class DeleteVaultRequestService {
|
||||
|
||||
public function __construct(
|
||||
private DeleteVaultRequestMapper $deleteVaultRequestMapper,
|
||||
private readonly DeleteVaultRequestMapper $deleteVaultRequestMapper,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
@ -63,7 +63,7 @@ class DeleteVaultRequestService {
|
|||
public function getDeleteRequestForVault(string $vault_guid) {
|
||||
try {
|
||||
return $this->deleteVaultRequestMapper->getDeleteRequestsForVault($vault_guid);
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Exception) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,7 +68,16 @@ class EncryptService {
|
|||
|
||||
// The fields of a credential which are encrypted
|
||||
public $encrypted_credential_fields = [
|
||||
'description', 'username', 'password', 'files', 'custom_fields', 'otp', 'email', 'tags', 'url', 'icon'
|
||||
'description',
|
||||
'username',
|
||||
'password',
|
||||
'files',
|
||||
'custom_fields',
|
||||
'otp',
|
||||
'email',
|
||||
'tags',
|
||||
'url',
|
||||
'icon'
|
||||
];
|
||||
|
||||
// Contains the server key
|
||||
|
|
@ -130,10 +139,9 @@ class EncryptService {
|
|||
* @returns string|false The returned string if decryption is successful
|
||||
* false if it is not
|
||||
*/
|
||||
public function decrypt($data_hex, $key) {
|
||||
|
||||
public function decrypt(string $data_hex, string $key): bool|string {
|
||||
if (!function_exists('hex2bin')) {
|
||||
function hex2bin($str) {
|
||||
function hex2bin(string $str): string {
|
||||
$sbin = "";
|
||||
$len = strlen($str);
|
||||
for ($i = 0; $i < $len; $i += 2) {
|
||||
|
|
@ -150,13 +158,11 @@ class EncryptService {
|
|||
$enc = substr($data, 128, -64);
|
||||
$mac = substr($data, -64);
|
||||
|
||||
list ($cipherKey, $macKey, $iv) = $this->getKeys($salt, $key);
|
||||
[$cipherKey, $macKey, $iv] = $this->getKeys($salt, $key);
|
||||
|
||||
if (hash_equals(hash_hmac('sha512', $enc, $macKey, true), $mac)) {
|
||||
if (hash_equals(hash_hmac('sha512', $enc, (string)$macKey, true), $mac)) {
|
||||
$dec = openssl_decrypt($enc, $this->cipher, $cipherKey, true, $iv);
|
||||
$data = $this->unpad($dec);
|
||||
|
||||
return $data;
|
||||
return $this->unpad($dec);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
@ -170,19 +176,17 @@ class EncryptService {
|
|||
*
|
||||
* @returns string The encrypted data
|
||||
*/
|
||||
public function encrypt($data, $key) {
|
||||
public function encrypt(string $data, string $key): string {
|
||||
if (function_exists('random_bytes')) {
|
||||
$salt = random_bytes(128);
|
||||
} else {
|
||||
$salt = openssl_random_pseudo_bytes(128);
|
||||
}
|
||||
list ($cipherKey, $macKey, $iv) = $this->getKeys($salt, $key);
|
||||
[$cipherKey, $macKey, $iv] = $this->getKeys($salt, $key);
|
||||
$data = $this->pad($data);
|
||||
$enc = openssl_encrypt($data, $this->cipher, $cipherKey, true, $iv);
|
||||
$mac = hash_hmac('sha512', $enc, $macKey, true);
|
||||
$data = bin2hex($salt . $enc . $mac);
|
||||
return $data;
|
||||
|
||||
$mac = hash_hmac('sha512', $enc, (string)$macKey, true);
|
||||
return bin2hex($salt . $enc . $mac);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -193,7 +197,7 @@ class EncryptService {
|
|||
*
|
||||
* @returns array An array of keys (a cipher key, a mac key, and a IV)
|
||||
*/
|
||||
protected function getKeys($salt, $key) {
|
||||
protected function getKeys(string $salt, string $key): array {
|
||||
$ivSize = openssl_cipher_iv_length($this->cipher);
|
||||
$keySize = openssl_cipher_iv_length($this->cipher);
|
||||
$length = 2 * $keySize + $ivSize;
|
||||
|
|
@ -219,7 +223,7 @@ class EncryptService {
|
|||
*
|
||||
* @returns string The derived key.
|
||||
*/
|
||||
protected function pbkdf2($algo, $key, $salt, $rounds, $length) {
|
||||
protected function pbkdf2(string $algo, string $key, string $salt, int $rounds, int $length): string {
|
||||
$size = strlen(hash($algo, '', true));
|
||||
$len = ceil($length / $size);
|
||||
$result = '';
|
||||
|
|
@ -238,10 +242,10 @@ class EncryptService {
|
|||
/**
|
||||
* Pad the data with a random char chosen by the pad amount.
|
||||
*
|
||||
* @param $data
|
||||
* @param string $data
|
||||
* @return string
|
||||
*/
|
||||
protected function pad($data) {
|
||||
protected function pad(string $data): string {
|
||||
$length = $this->getKeySize();
|
||||
$padAmount = $length - strlen($data) % $length;
|
||||
if ($padAmount === 0) {
|
||||
|
|
@ -252,15 +256,20 @@ class EncryptService {
|
|||
|
||||
|
||||
/**
|
||||
* Unpad the the data
|
||||
* Unpad the data
|
||||
*
|
||||
* @param $data
|
||||
* @param false|string $data
|
||||
* @return bool|string
|
||||
*/
|
||||
protected function unpad($data) {
|
||||
protected function unpad(false|string $data): bool|string {
|
||||
if ($data === false) {
|
||||
return false;
|
||||
}
|
||||
$length = $this->getKeySize();
|
||||
$last = ord($data[strlen($data) - 1]);
|
||||
if ($last > $length) return false;
|
||||
if ($last > $length) {
|
||||
return false;
|
||||
}
|
||||
if (substr($data, -1 * $last) !== str_repeat(chr($last), $last)) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -297,11 +306,11 @@ class EncryptService {
|
|||
if ($credential instanceof Credential) {
|
||||
$userSuppliedKey = $credential->getLabel();
|
||||
$sk = $credential->getSharedKey();
|
||||
$userKey = (isset($sk)) ? $sk : $credential->getUserId();
|
||||
$userKey = $sk ?? $credential->getUserId();
|
||||
}
|
||||
if (is_array($credential)) {
|
||||
$userSuppliedKey = $credential['label'];
|
||||
$userKey = (isset($credential['shared_key'])) ? $credential['shared_key'] : $credential['user_id'];
|
||||
$userKey = $credential['shared_key'] ?? $credential['user_id'];
|
||||
}
|
||||
return [$userKey, $userSuppliedKey];
|
||||
}
|
||||
|
|
@ -314,12 +323,12 @@ class EncryptService {
|
|||
* @throws \Exception
|
||||
*/
|
||||
private function handleCredential($credential, $service_function) {
|
||||
list($userKey, $userSuppliedKey) = $this->extractKeysFromCredential($credential);
|
||||
[$userKey, $userSuppliedKey] = $this->extractKeysFromCredential($credential);
|
||||
|
||||
$key = $this->makeKey($userKey, $this->server_key, $userSuppliedKey);
|
||||
$key = static::makeKey($userKey, $this->server_key, $userSuppliedKey);
|
||||
foreach ($this->encrypted_credential_fields as $field) {
|
||||
if ($credential instanceof Credential) {
|
||||
$field = str_replace(' ', '', str_replace('_', ' ', ucwords($field, '_')));
|
||||
$field = str_replace(' ', '', str_replace('_', ' ', ucwords((string)$field, '_')));
|
||||
$set = 'set' . $field;
|
||||
$get = 'get' . $field;
|
||||
$credential->{$set}($this->{$service_function}($credential->{$get}(), $key));
|
||||
|
|
@ -371,10 +380,10 @@ class EncryptService {
|
|||
|
||||
if (is_array($file)) {
|
||||
$userSuppliedKey = $file['size'];
|
||||
$userKey = md5($file['mimetype']);
|
||||
$userKey = md5((string)$file['mimetype']);
|
||||
}
|
||||
|
||||
$key = $this->makeKey($userKey, $this->server_key, $userSuppliedKey);
|
||||
$key = static::makeKey($userKey, $this->server_key, $userSuppliedKey);
|
||||
|
||||
|
||||
if ($file instanceof File) {
|
||||
|
|
|
|||
|
|
@ -37,8 +37,8 @@ class FileService {
|
|||
private $server_key;
|
||||
|
||||
public function __construct(
|
||||
private FileMapper $fileMapper,
|
||||
private EncryptService $encryptService,
|
||||
private readonly FileMapper $fileMapper,
|
||||
private readonly EncryptService $encryptService,
|
||||
IConfig $config,
|
||||
) {
|
||||
$this->server_key = $config->getSystemValue('passwordsalt', '');
|
||||
|
|
|
|||
|
|
@ -35,84 +35,84 @@ class IconService {
|
|||
/**
|
||||
* @var string Page URL
|
||||
*/
|
||||
public $url;
|
||||
public string $url;
|
||||
|
||||
/**
|
||||
* @var string Page URL, after prospective redirects
|
||||
*/
|
||||
public $pageUrl;
|
||||
public string $pageUrl;
|
||||
|
||||
/**
|
||||
* @var string Site root URL (homepage), based on $pageUrl
|
||||
*/
|
||||
public $siteUrl;
|
||||
public string $siteUrl;
|
||||
|
||||
/**
|
||||
* @var string full URI to favicon
|
||||
*/
|
||||
public $icoUrl;
|
||||
public string $icoUrl;
|
||||
|
||||
/**
|
||||
* @var string favicon type (file extension, ex: ico|gif|png)
|
||||
*/
|
||||
public $icoType;
|
||||
public string $icoType;
|
||||
|
||||
/**
|
||||
* @var string favicon url determination method (default /favicon.ico or found in head>link tag)
|
||||
*/
|
||||
public $findMethod;
|
||||
public string $findMethod;
|
||||
|
||||
/**
|
||||
* @var string details, in case of failure
|
||||
*/
|
||||
public $error;
|
||||
public string $error;
|
||||
|
||||
/**
|
||||
* @var bool tell if the favicon exists (set after calling IconService)
|
||||
*/
|
||||
public $icoExists;
|
||||
public bool $icoExists;
|
||||
|
||||
/**
|
||||
* @var string md5 of $icoData
|
||||
*/
|
||||
public $icoMd5;
|
||||
public string $icoMd5;
|
||||
|
||||
/**
|
||||
* @var string favicon binary data
|
||||
*/
|
||||
public $icoData;
|
||||
public string $icoData;
|
||||
|
||||
/**
|
||||
* @var array Additional debug info
|
||||
*/
|
||||
public $debugInfo;
|
||||
public array $debugInfo;
|
||||
|
||||
/**
|
||||
* @var string HTTP proxy (ex: localhost:8888)
|
||||
* @var string|null HTTP proxy (ex: localhost:8888)
|
||||
*/
|
||||
protected $httpProxy;
|
||||
protected mixed $httpProxy;
|
||||
|
||||
/**
|
||||
* @var bool SSL verify peer (default: true)
|
||||
*/
|
||||
protected $sslVerify;
|
||||
protected bool $sslVerify;
|
||||
|
||||
/**
|
||||
* Create a new IconService object, search & download favicon if $auto is true
|
||||
*
|
||||
* @param string $url Page URL
|
||||
* @param array $options Optional settings
|
||||
* @param array|null $options Optional settings
|
||||
* @param bool $auto Search & download favicon on instantiation
|
||||
*/
|
||||
public function __construct($url, $options = null, $auto = true) {
|
||||
if (!$url) {
|
||||
public function __construct(string $url, array $options = null, bool $auto = true) {
|
||||
if (empty($url)) {
|
||||
throw new \InvalidArgumentException("url is empty");
|
||||
}
|
||||
if (self::urlType($url) != self::URL_TYPE_ABSOLUTE) {
|
||||
throw new \InvalidArgumentException("'" . $url . "' is not an absolute url");
|
||||
}
|
||||
$this->url = $url;
|
||||
$this->httpProxy = isset($options['httpProxy']) ? $options['httpProxy'] : null;
|
||||
$this->httpProxy = $options['httpProxy'] ?? null;
|
||||
$this->sslVerify = isset($options['sslVerify']) && $options['sslVerify'] === false ? false : true;
|
||||
if ($auto) {
|
||||
$this->getFaviconUrl();
|
||||
|
|
@ -164,12 +164,12 @@ class IconService {
|
|||
$this->findMethod = 'default';
|
||||
|
||||
// HTML <head> tag extraction
|
||||
preg_match('#^(.*)<\s*body#isU', $html, $matches);
|
||||
$htmlHead = isset($matches[1]) ? $matches[1] : $html;
|
||||
preg_match('#^(.*)<\s*body#isU', (string) $html, $matches);
|
||||
$htmlHead = $matches[1] ?? $html;
|
||||
|
||||
// HTML <base> tag href extraction
|
||||
$base_href = null;
|
||||
if (preg_match('#<base[^>]+href=(["\'])([^>]+)\1#i', $htmlHead, $matches)) {
|
||||
if (preg_match('#<base[^>]+href=(["\'])([^>]+)\1#i', (string) $htmlHead, $matches)) {
|
||||
$base_href = rtrim($matches[2], '/') . '/';
|
||||
$this->debugInfo['base_href'] = $base_href;
|
||||
}
|
||||
|
|
@ -182,7 +182,7 @@ class IconService {
|
|||
|
||||
|
||||
private function parseLinkElement($htmlHead, $pageUrlInfo, $base_href){
|
||||
if (preg_match('#<\s*link[^>]*(rel=(["\'])[^>\2]*icon[^>\2]*\2)[^>]*>#i', $htmlHead, $matches)) {
|
||||
if (preg_match('#<\s*link[^>]*(rel=(["\'])[^>\2]*icon[^>\2]*\2)[^>]*>#i', (string) $htmlHead, $matches)) {
|
||||
$link_tag = $matches[0];
|
||||
$this->debugInfo['link_tag'] = $link_tag;
|
||||
|
||||
|
|
@ -224,7 +224,7 @@ class IconService {
|
|||
break;
|
||||
case self::URL_TYPE_RELATIVE:
|
||||
$this->findMethod .= ' relative';
|
||||
$path = preg_replace('#/[^/]+?$#i', '/', $pageUrlInfo['path']);
|
||||
$path = preg_replace('#/[^/]+?$#i', '/', (string) $pageUrlInfo['path']);
|
||||
$this->icoUrl = $pageUrlInfo['scheme'] . '://' . $pageUrlInfo['host'] . $path . $ico_href;
|
||||
$this->findMethod .= ' without base href';
|
||||
if (isset($base_href)) {
|
||||
|
|
@ -297,19 +297,19 @@ class IconService {
|
|||
}
|
||||
|
||||
// Check favicon content
|
||||
if (strlen($content) == 0) {
|
||||
if (strlen((string) $content) == 0) {
|
||||
$this->error = "Empty content";
|
||||
return false;
|
||||
}
|
||||
$textTypes = ['text/html', 'text/plain'];
|
||||
if (in_array($info['content_type'], $textTypes) || preg_match('#(</html>|</b>)#i', $content)) {
|
||||
if (in_array($info['content_type'], $textTypes) || preg_match('#(</html>|</b>)#i', (string) $content)) {
|
||||
$this->error = "Seems to be a text document";
|
||||
return false;
|
||||
}
|
||||
|
||||
// All right baby !
|
||||
$this->icoData = $content;
|
||||
$this->icoMd5 = md5($content);
|
||||
$this->icoMd5 = md5((string) $content);
|
||||
$this->icoExists = true;
|
||||
return true;
|
||||
}
|
||||
|
|
@ -350,7 +350,7 @@ class IconService {
|
|||
$info['content_type'] = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
|
||||
curl_close($ch);
|
||||
|
||||
if ($info['curl_errno'] !== CURLE_OK || in_array($info['http_code'], array(403, 404, 500, 503))) {
|
||||
if ($info['curl_errno'] !== CURLE_OK || in_array($info['http_code'], [403, 404, 500, 503])) {
|
||||
return false;
|
||||
}
|
||||
return $content;
|
||||
|
|
@ -400,9 +400,10 @@ class IconService {
|
|||
* - URL_TYPE_RELATIVE ex: ../images/fav.ico
|
||||
* - URL_TYPE_EMBED_BASE64 ex: data:image/x-icon;base64,AAABAA...
|
||||
*
|
||||
* @return int
|
||||
* @param string $url
|
||||
* @return false|int
|
||||
*/
|
||||
public static function urlType($url) {
|
||||
public static function urlType(string $url): false|int {
|
||||
if (empty($url)) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,9 +31,9 @@ use OCP\Notification\IManager;
|
|||
|
||||
class NotificationService {
|
||||
public function __construct(
|
||||
private IManager $manager,
|
||||
private IURLGenerator $urlGenerator,
|
||||
private IDBConnection $db,
|
||||
private readonly IManager $manager,
|
||||
private readonly IURLGenerator $urlGenerator,
|
||||
private readonly IDBConnection $db,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,8 +28,6 @@ use OCP\IConfig;
|
|||
|
||||
class SettingsService {
|
||||
|
||||
private $userId;
|
||||
private $appName;
|
||||
public $settings;
|
||||
|
||||
private $numeric_settings = [
|
||||
|
|
@ -44,12 +42,10 @@ class SettingsService {
|
|||
];
|
||||
|
||||
public function __construct(
|
||||
$UserId,
|
||||
private IConfig $config,
|
||||
$AppName,
|
||||
private $userId,
|
||||
private readonly IConfig $config,
|
||||
private $appName,
|
||||
) {
|
||||
$this->userId = $UserId;
|
||||
$this->appName = $AppName;
|
||||
$this->settings = [
|
||||
'link_sharing_enabled' => intval($this->config->getAppValue('passman', 'link_sharing_enabled', 1)),
|
||||
'user_sharing_enabled' => intval($this->config->getAppValue('passman', 'user_sharing_enabled', 1)),
|
||||
|
|
@ -82,7 +78,7 @@ class SettingsService {
|
|||
* @return mixed
|
||||
*/
|
||||
public function getAppSetting($key, $default_value = null) {
|
||||
$value = ($this->settings[$key]) ? $this->settings[$key] : $this->config->getAppValue('passman', $key, $default_value);
|
||||
$value = $this->settings[$key] ?: $this->config->getAppValue('passman', $key, $default_value);
|
||||
if (in_array($key, $this->numeric_settings)) {
|
||||
$value = intval($value);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,12 +39,12 @@ use OCP\Notification\IManager;
|
|||
|
||||
class ShareService {
|
||||
public function __construct(
|
||||
private SharingACLMapper $sharingACL,
|
||||
private ShareRequestMapper $shareRequest,
|
||||
private CredentialMapper $credential,
|
||||
private CredentialRevisionService $revisions,
|
||||
private EncryptService $encryptService,
|
||||
private IManager $IManager,
|
||||
private readonly SharingACLMapper $sharingACL,
|
||||
private readonly ShareRequestMapper $shareRequest,
|
||||
private readonly CredentialMapper $credential,
|
||||
private readonly CredentialRevisionService $revisions,
|
||||
private readonly EncryptService $encryptService,
|
||||
private readonly IManager $IManager,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ use OCP\AppFramework\Db\MultipleObjectsReturnedException;
|
|||
class VaultService {
|
||||
|
||||
public function __construct(
|
||||
private VaultMapper $vaultMapper,
|
||||
private readonly VaultMapper $vaultMapper,
|
||||
) {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,9 +41,9 @@ class Admin implements ISettings {
|
|||
*/
|
||||
public function __construct(
|
||||
protected IConfig $config,
|
||||
private IL10N $l,
|
||||
private IAppManager $appManager,
|
||||
private LoggerInterface $logger,
|
||||
private readonly IL10N $l,
|
||||
private readonly IAppManager $appManager,
|
||||
private readonly LoggerInterface $logger,
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
|
|||
19
rector.php
Normal file
19
rector.php
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
|
||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
*/
|
||||
|
||||
use Rector\Config\RectorConfig;
|
||||
|
||||
return RectorConfig::configure()
|
||||
->withPaths([
|
||||
__DIR__ . '/appinfo',
|
||||
__DIR__ . '/lib',
|
||||
__DIR__ . '/templates',
|
||||
__DIR__ . '/tests',
|
||||
])
|
||||
->withPhpSets(php81: true)
|
||||
->withTypeCoverageLevel(0);
|
||||
|
|
@ -80,12 +80,12 @@ abstract class DatabaseHelperTest extends PHPUnit_Extensions_Database_TestCase {
|
|||
$this->db->executeQuery($this->db->getDatabasePlatform()->getTruncateTableSQL($table_name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the table with the corresponding dataset on the dumps dir
|
||||
*
|
||||
* @param $table_name
|
||||
*/
|
||||
public function setUpTable($table_name){
|
||||
/**
|
||||
* Initializes the table with the corresponding dataset on the dumps dir
|
||||
*
|
||||
* @param string $table_name
|
||||
*/
|
||||
public function setUpTable(string $table_name){
|
||||
$table = $this->getTableDataset($table_name);
|
||||
$table_no_prefix = substr($table_name, 3);
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class ExpireCredentialsTest extends PHPUnit_Framework_TestCase {
|
|||
try {
|
||||
$backgroundJob->execute($jobList);
|
||||
}
|
||||
catch (Exception $ex) {
|
||||
catch (Exception) {
|
||||
$this->assertTrue(false);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -286,4 +286,4 @@ class CredentialMapperTest extends DatabaseHelperTest {
|
|||
$this->mapper->getCredentialById($cred->getId())->jsonSerialize()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,9 +39,9 @@ class IconServiceTest extends PHPUnit_Framework_TestCase {
|
|||
private $testKey;
|
||||
|
||||
public function setUp() {
|
||||
$this->options = array(
|
||||
$this->options = [
|
||||
'sslVerify' => false,
|
||||
);
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue