diff --git a/lib/SP/Core/Acl/Acl.php b/lib/SP/Core/Acl/Acl.php index d356a3e1..3d10422a 100644 --- a/lib/SP/Core/Acl/Acl.php +++ b/lib/SP/Core/Acl/Acl.php @@ -1,4 +1,5 @@ details[] = [$this->formatString($key), $this->formatString($value)]; + $this->details[] = [$this->formatString($key), $this->formatString((string)$value)]; $this->detailsCounter++; diff --git a/lib/SP/Core/HttpModuleBase.php b/lib/SP/Core/HttpModuleBase.php index d3e2d3ed..07018b97 100644 --- a/lib/SP/Core/HttpModuleBase.php +++ b/lib/SP/Core/HttpModuleBase.php @@ -1,4 +1,5 @@ tags = self::buildFromItemData($this->tags); } @@ -69,11 +72,6 @@ final class AccountSearchItem return $this->favorite; } - public function setFavorite(bool $favorite): void - { - $this->favorite = $favorite; - } - public function isShowRequest(): bool { return !$this->accountAcl->isShow() && self::$requestEnabled; @@ -100,11 +98,6 @@ final class AccountSearchItem return ($this->accountAcl->isShow() && !self::$optionalActions); } - public function setTextMaxLength(int $textMaxLength): void - { - $this->textMaxLength = $textMaxLength; - } - public function getShortUrl(): string { return Html::truncate($this->accountSearchView->getUrl(), $this->textMaxLength); @@ -151,21 +144,11 @@ final class AccountSearchItem return $this->color; } - public function setColor(string $color): void - { - $this->color = $color; - } - - public function getLink(): ?string + public function getLink(): ?bool { return $this->link; } - public function setLink(string $link): void - { - $this->link = $link; - } - public function getAccesses(): array { $accesses = [ @@ -247,7 +230,7 @@ final class AccountSearchItem } /** - * @return \SP\Domain\Common\Models\Item[] + * @return Item[] */ public function getTags(): array { diff --git a/lib/SP/Domain/Account/Dtos/AccountAclDto.php b/lib/SP/Domain/Account/Dtos/AccountAclDto.php index c49616ef..15d36c84 100644 --- a/lib/SP/Domain/Account/Dtos/AccountAclDto.php +++ b/lib/SP/Domain/Account/Dtos/AccountAclDto.php @@ -1,4 +1,5 @@ getUrl(), notes: $account->getNotes(), userEditId: $account->getUserEditId(), - isPrivate: $account->getIsPrivate(), - isPrivateGroup: $account->getIsPrivateGroup(), + isPrivate: (bool)$account->getIsPrivate(), + isPrivateGroup: (bool)$account->getIsPrivateGroup(), passDateChange: $account->getPassDateChange(), parentId: $account->getParentId(), userGroupId: $account->getUserGroupId(), - otherUserEdit: $account->getOtherUserEdit(), - otherUserGroupEdit: $account->getOtherUserGroupEdit(), + otherUserEdit: (bool)$account->getOtherUserEdit(), + otherUserGroupEdit: (bool)$account->getOtherUserGroupEdit(), ); } @@ -185,7 +187,7 @@ abstract class AccountDto extends Dto public function withPrivate(bool $isPrivate): static { $self = clone $this; - $self->isPrivate = (int)$isPrivate; + $self->isPrivate = $isPrivate; return $self; } @@ -193,7 +195,7 @@ abstract class AccountDto extends Dto public function withPrivateGroup(bool $isPrivateGroup): static { $self = clone $this; - $self->isPrivateGroup = (int)$isPrivateGroup; + $self->isPrivateGroup = $isPrivateGroup; return $self; } diff --git a/lib/SP/Domain/Account/Dtos/AccountEnrichedDto.php b/lib/SP/Domain/Account/Dtos/AccountEnrichedDto.php index 3d9f7ba5..eadf68d0 100644 --- a/lib/SP/Domain/Account/Dtos/AccountEnrichedDto.php +++ b/lib/SP/Domain/Account/Dtos/AccountEnrichedDto.php @@ -1,4 +1,5 @@ isModify; } - public function getDateAdd(): ?int + public function getDateAdd(): ?string { return $this->dateAdd; } - public function getDateEdit(): ?int + public function getDateEdit(): ?string { return $this->dateEdit; } diff --git a/lib/SP/Domain/Account/Dtos/AccountPasswordRequest.php b/lib/SP/Domain/Account/Dtos/AccountPasswordRequest.php index 413b1fd8..2f9bcd0e 100644 --- a/lib/SP/Domain/Account/Dtos/AccountPasswordRequest.php +++ b/lib/SP/Domain/Account/Dtos/AccountPasswordRequest.php @@ -1,4 +1,5 @@ categoryId; } - public function getDateAdd(): ?int + public function getDateAdd(): ?string { return $this->dateAdd; } - public function getDateEdit(): ?int + public function getDateEdit(): ?string { return $this->dateEdit; } diff --git a/lib/SP/Domain/Account/Models/AccountHistory.php b/lib/SP/Domain/Account/Models/AccountHistory.php index 6183b8d1..747d22cf 100644 --- a/lib/SP/Domain/Account/Models/AccountHistory.php +++ b/lib/SP/Domain/Account/Models/AccountHistory.php @@ -1,4 +1,5 @@ countView; } - public function getDateEdit(): ?int + public function getDateEdit(): ?string { return $this->dateEdit; } @@ -156,12 +158,12 @@ final class AccountSearchView extends Model return $this->publicLinkHash; } - public function getPublicLinkDateExpire(): ?string + public function getPublicLinkDateExpire(): ?int { return $this->publicLinkDateExpire; } - public function getPublicLinkTotalCountViews(): ?string + public function getPublicLinkTotalCountViews(): ?int { return $this->publicLinkTotalCountViews; } diff --git a/lib/SP/Domain/Account/Models/AccountToUser.php b/lib/SP/Domain/Account/Models/AccountToUser.php index 35e4625b..e2459786 100644 --- a/lib/SP/Domain/Account/Models/AccountToUser.php +++ b/lib/SP/Domain/Account/Models/AccountToUser.php @@ -1,4 +1,5 @@ categoryId; } - public function getDateAdd(): ?int + public function getDateAdd(): ?string { return $this->dateAdd; } - public function getDateEdit(): ?int + public function getDateEdit(): ?string { return $this->dateEdit; } diff --git a/lib/SP/Domain/Account/Models/File.php b/lib/SP/Domain/Account/Models/File.php index b0752ec7..2f99d599 100644 --- a/lib/SP/Domain/Account/Models/File.php +++ b/lib/SP/Domain/Account/Models/File.php @@ -1,4 +1,5 @@ accountItemsService->updateItems($accountId, $userCanChangePermissions, $accountUpdateDto); + $this->accountItemsService->updateItems($userCanChangePermissions, $accountId, $accountUpdateDto); } }, $this @@ -518,7 +519,7 @@ final class Account extends Service implements AccountService { $this->accountRepository->transactionAware( function () use ($id) { - $this->addHistory($id, 1); + $this->addHistory($id, true); if ($this->accountRepository->delete($id)->getAffectedNumRows() === 0) { throw new NoSuchItemException(__u('Account not found')); diff --git a/lib/SP/Domain/Account/Services/AccountAcl.php b/lib/SP/Domain/Account/Services/AccountAcl.php index 6fd567ed..0016bf86 100644 --- a/lib/SP/Domain/Account/Services/AccountAcl.php +++ b/lib/SP/Domain/Account/Services/AccountAcl.php @@ -1,4 +1,5 @@ accountCacheService->getCacheForAccount( $accountSearchView->getId(), - (int)strtotime($accountSearchView->getDateEdit()) + strtotime($accountSearchView->getDateEdit()) ); // Obtener la ACL de la cuenta diff --git a/lib/SP/Domain/Account/Services/Builders/AccountSearchTokenizer.php b/lib/SP/Domain/Account/Services/Builders/AccountSearchTokenizer.php index d290b440..ff74cd71 100644 --- a/lib/SP/Domain/Account/Services/Builders/AccountSearchTokenizer.php +++ b/lib/SP/Domain/Account/Services/Builders/AccountSearchTokenizer.php @@ -1,4 +1,5 @@ ldapParams->getGroup(), 'cn') === 0) { - return LdapUtil::getGroupName($this->ldapParams->getGroup()) ?: ''; + $group = $this->ldapParams->getGroup(); + + if ($group === null) { + return '*'; } - return $this->ldapParams->getGroup() ?: '*'; + if (stripos($group, 'cn') === 0) { + return LdapUtil::getGroupName($group) ?: ''; + } + + return $group; } /** @@ -187,8 +191,7 @@ final class LdapActions implements LdapActionsService */ public function getAttributes(string $filter): AttributeCollection { - $searchResults = $this->getResults($filter) - ->getFirst(); + $searchResults = $this->getResults($filter)->getFirst(); if ($searchResults === null) { return new AttributeCollection(); @@ -201,7 +204,7 @@ final class LdapActions implements LdapActionsService $attributes = array_filter( self::ATTRIBUTES_MAPPING, - fn($attribute) => isset($results[$attribute]), + static fn(string $attribute) => isset($results[$attribute]), ARRAY_FILTER_USE_KEY ); @@ -215,16 +218,10 @@ final class LdapActions implements LdapActionsService ); } else { // Store first value - $attributeCollection->set( - $map, - trim($results[$attribute][0]) - ); + $attributeCollection->set($map, trim($results[$attribute][0])); } } else { - $attributeCollection->set( - $map, - trim($results[$attribute]) - ); + $attributeCollection->set($map, trim((string)$results[$attribute])); } } diff --git a/lib/SP/Domain/Auth/Providers/Ldap/LdapAuth.php b/lib/SP/Domain/Auth/Providers/Ldap/LdapAuth.php index 9d748595..2c0fa254 100644 --- a/lib/SP/Domain/Auth/Providers/Ldap/LdapAuth.php +++ b/lib/SP/Domain/Auth/Providers/Ldap/LdapAuth.php @@ -1,4 +1,5 @@ ldapParams->getGroup(), 'cn') === 0) { - return LdapUtil::getGroupName($this->ldapParams->getGroup()) ?: ''; + $group = $this->ldapParams->getGroup(); + + if ($group === null) { + return ''; } - return $this->ldapParams->getGroup() ?? ''; + if (stripos($group, 'cn') === 0) { + return LdapUtil::getGroupName($group) ?: ''; + } + + return $group; } /** diff --git a/lib/SP/Domain/Auth/Providers/Ldap/LdapCodeEnum.php b/lib/SP/Domain/Auth/Providers/Ldap/LdapCodeEnum.php index ab596eb0..0d572a25 100644 --- a/lib/SP/Domain/Auth/Providers/Ldap/LdapCodeEnum.php +++ b/lib/SP/Domain/Auth/Providers/Ldap/LdapCodeEnum.php @@ -1,4 +1,5 @@ getGroupFromParams(), null, LDAP_ESCAPE_FILTER); - $member = $userDn !== null ? ldap_escape($userDn, null, LDAP_ESCAPE_FILTER) : '*'; + $groupName = ldap_escape($this->getGroupFromParams(), '', LDAP_ESCAPE_FILTER); + $member = $userDn !== null ? ldap_escape($userDn, '', LDAP_ESCAPE_FILTER) : '*'; if (empty($groupName)) { return $this->getUserObjectFilter(); diff --git a/lib/SP/Domain/Auth/Providers/Ldap/LdapTypeEnum.php b/lib/SP/Domain/Auth/Providers/Ldap/LdapTypeEnum.php index c218f306..efaa7d01 100644 --- a/lib/SP/Domain/Auth/Providers/Ldap/LdapTypeEnum.php +++ b/lib/SP/Domain/Auth/Providers/Ldap/LdapTypeEnum.php @@ -1,4 +1,5 @@ jsonSerialize(), $options & JSON_THROW_ON_ERROR); + return Serde::serializeJson($this, $options); } /** diff --git a/lib/SP/Domain/Common/Models/SerializedModel.php b/lib/SP/Domain/Common/Models/SerializedModel.php index ffe54aa8..0bfa44cb 100644 --- a/lib/SP/Domain/Common/Models/SerializedModel.php +++ b/lib/SP/Domain/Common/Models/SerializedModel.php @@ -1,4 +1,5 @@ configService->save('config_backup', $this->packConfigData($configData)); - $this->configService->save('config_backup_date', time()); + $this->configService->save('config_backup_date', (string)time()); } catch (Exception $e) { processException($e); } diff --git a/lib/SP/Domain/Config/Services/ConfigFile.php b/lib/SP/Domain/Config/Services/ConfigFile.php index e3e752b0..110b7f18 100644 --- a/lib/SP/Domain/Config/Services/ConfigFile.php +++ b/lib/SP/Domain/Config/Services/ConfigFile.php @@ -1,4 +1,5 @@ configService->save(self::PARAM_MASTER_PASS_HASH, $hash); - $this->configService->save(self::PARAM_MASTER_PASS_TIME, time()); + $this->configService->save(self::PARAM_MASTER_PASS_TIME, (string)time()); } } diff --git a/lib/SP/Domain/Crypt/Services/SecureSession.php b/lib/SP/Domain/Crypt/Services/SecureSession.php index 3a06468d..a8440f5a 100644 --- a/lib/SP/Domain/Crypt/Services/SecureSession.php +++ b/lib/SP/Domain/Crypt/Services/SecureSession.php @@ -1,4 +1,5 @@ add(self::PARAM_KEY, $secureKey); $configRequest->add(self::PARAM_HASH, Hash::hashKey($randomKey)); - $configRequest->add(self::PARAM_TIME, time()); - $configRequest->add(self::PARAM_MAX_TIME, $this->maxTime); - $configRequest->add(self::PARAM_ATTEMPTS, 0); + $configRequest->add(self::PARAM_TIME, (string)time()); + $configRequest->add(self::PARAM_MAX_TIME, (string)$this->maxTime); + $configRequest->add(self::PARAM_ATTEMPTS, '0'); $this->configService->saveBatch($configRequest); @@ -174,7 +176,7 @@ final class TemporaryMasterPass extends Service implements TemporaryMasterPassSe ); if (!$isValid) { - $this->configService->save(self::PARAM_ATTEMPTS, $attempts + 1); + $this->configService->save(self::PARAM_ATTEMPTS, (string)($attempts + 1)); } return $isValid; @@ -196,9 +198,9 @@ final class TemporaryMasterPass extends Service implements TemporaryMasterPassSe $configRequest->add(self::PARAM_PASS, ''); $configRequest->add(self::PARAM_KEY, ''); $configRequest->add(self::PARAM_HASH, ''); - $configRequest->add(self::PARAM_TIME, 0); - $configRequest->add(self::PARAM_MAX_TIME, 0); - $configRequest->add(self::PARAM_ATTEMPTS, 0); + $configRequest->add(self::PARAM_TIME, '0'); + $configRequest->add(self::PARAM_MAX_TIME, '0'); + $configRequest->add(self::PARAM_ATTEMPTS, '0'); $this->configService->saveBatch($configRequest); diff --git a/lib/SP/Domain/CustomField/Adapters/CustomField.php b/lib/SP/Domain/CustomField/Adapters/CustomField.php index 1c0517f2..4f2815e9 100644 --- a/lib/SP/Domain/CustomField/Adapters/CustomField.php +++ b/lib/SP/Domain/CustomField/Adapters/CustomField.php @@ -1,4 +1,5 @@ databaseUtil->escape($value); + return $this->databaseUtil->escape((string)$value); } return null; diff --git a/lib/SP/Domain/Export/Services/BackupFileHelper.php b/lib/SP/Domain/Export/Services/BackupFileHelper.php index 28b6d401..059138c4 100644 --- a/lib/SP/Domain/Export/Services/BackupFileHelper.php +++ b/lib/SP/Domain/Export/Services/BackupFileHelper.php @@ -1,4 +1,5 @@ document->createTextNode($account->getName())->nodeValue ); - $accountCustomerId = $this->document->createElement('clientId', $account->getClientId()); - $accountCategoryId = $this->document->createElement('categoryId', $account->getCategoryId()); + $accountCustomerId = $this->document->createElement('clientId', (string)$account->getClientId()); + $accountCategoryId = $this->document->createElement('categoryId', (string)$account->getCategoryId()); $accountLogin = $this->document->createElement( 'login', $this->document->createTextNode($account->getLogin())->nodeValue @@ -110,12 +112,12 @@ final class XmlAccountExport extends XmlExportEntityBase $tag = $this->document->createElement('tag'); $tags->appendChild($tag); - $tag->setAttribute('id', $itemData->getId()); + $tag->setAttribute('id', (string)$itemData->getId()); } // Crear el nodo de cuenta $nodeAccount = $this->document->createElement('Account'); - $nodeAccount->setAttribute('id', $account->getId()); + $nodeAccount->setAttribute('id', (string)$account->getId()); $nodeAccount->appendChild($accountName); $nodeAccount->appendChild($accountCustomerId); $nodeAccount->appendChild($accountCategoryId); diff --git a/lib/SP/Domain/Export/Services/XmlCategoryExport.php b/lib/SP/Domain/Export/Services/XmlCategoryExport.php index d1a0a008..78d8a3e1 100644 --- a/lib/SP/Domain/Export/Services/XmlCategoryExport.php +++ b/lib/SP/Domain/Export/Services/XmlCategoryExport.php @@ -1,4 +1,5 @@ document->createElement('Category'); $nodeCategories->appendChild($nodeCategory); - $nodeCategory->setAttribute('id', $category->getId()); + $nodeCategory->setAttribute('id', (string)$category->getId()); $nodeCategory->appendChild( $this->document->createElement( 'name', diff --git a/lib/SP/Domain/Export/Services/XmlClientExport.php b/lib/SP/Domain/Export/Services/XmlClientExport.php index 39860304..de3acf92 100644 --- a/lib/SP/Domain/Export/Services/XmlClientExport.php +++ b/lib/SP/Domain/Export/Services/XmlClientExport.php @@ -1,4 +1,5 @@ document->createElement('Client'); $nodeClients->appendChild($nodeClient); - $nodeClient->setAttribute('id', $client->getId()); + $nodeClient->setAttribute('id', (string)$client->getId()); $nodeClient->appendChild( $this->document->createElement( 'name', diff --git a/lib/SP/Domain/Export/Services/XmlExport.php b/lib/SP/Domain/Export/Services/XmlExport.php index 9557922e..a5115b05 100644 --- a/lib/SP/Domain/Export/Services/XmlExport.php +++ b/lib/SP/Domain/Export/Services/XmlExport.php @@ -1,4 +1,5 @@ append( $this->document->createElement('Generator', 'sysPass'), $this->document->createElement('Version', Version::getVersionStringNormalized()), - $this->document->createElement('Time', time()), + $this->document->createElement('Time', (string)time()), $this->document->createElement( 'User', $this->document->createTextNode($userData->getLogin())->nodeValue diff --git a/lib/SP/Domain/Export/Services/XmlExportEntityBase.php b/lib/SP/Domain/Export/Services/XmlExportEntityBase.php index 513a6dd7..5e68f419 100644 --- a/lib/SP/Domain/Export/Services/XmlExportEntityBase.php +++ b/lib/SP/Domain/Export/Services/XmlExportEntityBase.php @@ -1,4 +1,5 @@ document->createElement('Tag'); $nodeTags->appendChild($nodeTag); - $nodeTag->setAttribute('id', $tag->getId()); + $nodeTag->setAttribute('id', (string)$tag->getId()); $nodeTag->appendChild( $this->document->createElement('name', $this->document->createTextNode($tag->getName())->nodeValue) ); diff --git a/lib/SP/Domain/Export/Services/XmlTrait.php b/lib/SP/Domain/Export/Services/XmlTrait.php index 9b7ecbce..19b7960f 100644 --- a/lib/SP/Domain/Export/Services/XmlTrait.php +++ b/lib/SP/Domain/Export/Services/XmlTrait.php @@ -1,4 +1,5 @@ document))->query('/Root/Meta/Version')->item(0)?->nodeValue ?? 0 ); } @@ -213,7 +215,7 @@ final class SyspassImport extends XmlImportBase implements ItemsImportService static fn(DOMElement $element) => isset($element->tagName) ); - $data = ['id' => $category->getAttribute('id')]; + $data = ['id' => (int)$category->getAttribute('id')]; /** @var DOMElement $node */ foreach ($nodesIterator as $node) { @@ -256,7 +258,7 @@ final class SyspassImport extends XmlImportBase implements ItemsImportService static fn(DOMElement $element) => isset($element->tagName) ); - $data = ['id' => $client->getAttribute('id')]; + $data = ['id' => (int)$client->getAttribute('id')]; /** @var DOMElement $node */ foreach ($nodesIterator as $node) { diff --git a/lib/SP/Domain/Import/Services/XmlFile.php b/lib/SP/Domain/Import/Services/XmlFile.php index b0a378e9..2d3f4a53 100644 --- a/lib/SP/Domain/Import/Services/XmlFile.php +++ b/lib/SP/Domain/Import/Services/XmlFile.php @@ -1,4 +1,6 @@ document->getElementsByTagName('Generator'); try { - return XmlFormat::from(strtolower($nodes->item(0)?->nodeValue)); + return XmlFormat::from(strtolower($nodes->item(0)?->nodeValue ?? '')); } catch (ValueError $e) { throw ImportException::error( __u('XML file not supported'), diff --git a/lib/SP/Domain/Import/Services/XmlFormat.php b/lib/SP/Domain/Import/Services/XmlFormat.php index 06f79aad..06001681 100644 --- a/lib/SP/Domain/Import/Services/XmlFormat.php +++ b/lib/SP/Domain/Import/Services/XmlFormat.php @@ -1,4 +1,5 @@ installData->setDbSocket($match['socket']); } else { $this->installData->setDbHost($match['host']); - $this->installData->setDbPort($match['port']); + $this->installData->setDbPort((int)$match['port']); } } else { $this->installData->setDbPort(3306); @@ -320,7 +322,7 @@ final class Installer implements InstallerService ) ); $this->configService->create( - new Config(['parameter' => 'lastupdatempass', 'value' => time()]) + new Config(['parameter' => 'lastupdatempass', 'value' => (string)time()]) ); } catch (Exception $e) { processException($e); @@ -344,14 +346,14 @@ final class Installer implements InstallerService ] ); - $userProfile = new UserProfile(['name' => 'Admin', 'profile' => new ProfileData()]); + $userProfile = new UserProfile(['name' => 'Admin', 'profile' => (new ProfileData())->toJson()]); $userData = new User([ 'userGroupId' => $this->userGroupService->create($userGroup), 'userProfileId' => $this->userProfileService->create($userProfile), 'login' => $this->installData->getAdminLogin(), 'name' => 'sysPass Admin', - 'isAdminApp' => 1, + 'isAdminApp' => true, ]); $id = $this->userService->createWithMasterPass( diff --git a/lib/SP/Domain/Install/Services/MysqlService.php b/lib/SP/Domain/Install/Services/MysqlService.php index bc64d966..24b30aee 100644 --- a/lib/SP/Domain/Install/Services/MysqlService.php +++ b/lib/SP/Domain/Install/Services/MysqlService.php @@ -1,4 +1,5 @@ getNumRows(); if ($attempts >= self::TIME_TRACKING_MAX_ATTEMPTS) { - $delaySeconds = self::TIME_SLEEP * $attempts; + $delaySeconds = (int)(self::TIME_SLEEP * $attempts); $this->eventDispatcher->notify( 'track.delay', @@ -121,7 +123,7 @@ final class Track extends Service implements TrackService self::TIME_TRACKING_MAX_ATTEMPTS ) ) - ->addDetail(__u('Seconds'), $delaySeconds) + ->addDetail(__u('Seconds'), (string)$delaySeconds) ) ); diff --git a/lib/SP/Domain/Storage/Ports/FileCacheService.php b/lib/SP/Domain/Storage/Ports/FileCacheService.php index 52ef021e..fd2b3400 100644 --- a/lib/SP/Domain/Storage/Ports/FileCacheService.php +++ b/lib/SP/Domain/Storage/Ports/FileCacheService.php @@ -1,4 +1,5 @@ $id, 'pass' => Hash::hashKey($userPass), - 'isChangePass' => 0, - 'isChangedPass' => 1, - 'isMigrate' => 0 + 'isChangePass' => false, + 'isChangedPass' => true, + 'isMigrate' => false ] ); diff --git a/lib/SP/Domain/User/Services/UserPassRecover.php b/lib/SP/Domain/User/Services/UserPassRecover.php index 1c7b5cc3..d3f29d12 100644 --- a/lib/SP/Domain/User/Services/UserPassRecover.php +++ b/lib/SP/Domain/User/Services/UserPassRecover.php @@ -1,4 +1,5 @@ execute(); - $this->lastId = $connection->lastInsertId(); + $this->lastId = (int)$connection->lastInsertId(); return $stmt; } catch (Exception $e) { @@ -142,7 +144,7 @@ final class Database implements DatabaseInterface throw ConstraintException::error(__u('Integrity constraint'), $e->getMessage(), $e->getCode(), $e); } - throw QueryException::critical($e->getMessage(), $e->getCode(), 0, $e); + throw QueryException::critical($e->getMessage(), (string)$e->getCode(), $e->getCode(), $e); } } diff --git a/lib/SP/Infrastructure/Database/DatabaseConnectionData.php b/lib/SP/Infrastructure/Database/DatabaseConnectionData.php index c7430821..baecb8a0 100644 --- a/lib/SP/Infrastructure/Database/DatabaseConnectionData.php +++ b/lib/SP/Infrastructure/Database/DatabaseConnectionData.php @@ -1,4 +1,5 @@ setAttribute('class', get_class($value)); $this->serializeItems($value, $newNode, $key); } else { - $newNode->appendChild($this->document->createTextNode(trim($value))); + $newNode->appendChild($this->document->createTextNode(trim((string)$value))); } $currentNode->appendChild($newNode); @@ -120,7 +122,7 @@ final readonly class XmlFileStorage implements XmlFileStorageService $value = $property->getValue($object); $items[$property->getName()] = match (true) { - is_bool($value) || (is_numeric($value) && !str_contains($value, '.')) => (int)$value, + is_bool($value) || (is_numeric($value) && !str_contains((string)$value, '.')) => (int)$value, default => $value }; } diff --git a/lib/SP/Infrastructure/ItemPreset/Repositories/ItemPreset.php b/lib/SP/Infrastructure/ItemPreset/Repositories/ItemPreset.php index 1c5f409c..bc9e60b2 100644 --- a/lib/SP/Infrastructure/ItemPreset/Repositories/ItemPreset.php +++ b/lib/SP/Infrastructure/ItemPreset/Repositories/ItemPreset.php @@ -1,4 +1,5 @@ $userId, 'userGroupId' => $groupId, - 'isAdminApp' => (int)$isAdminApp, - 'isAdminAcc' => (int)$isAdminAcc + 'isAdminApp' => $isAdminApp, + 'isAdminAcc' => $isAdminAcc ] ) ) @@ -690,9 +692,13 @@ class AccountAclTest extends UnitaryTestCase $fileCache = $this->createMock(FileCacheService::class); $actions = $this->createMock(ActionsInterface::class); + $lastUpdate = DateTime::createFromFormat('U', (string)($dto->getDateEdit() + 10))->format('Y-m-d H:i:s'); + $this->context->setUserData( new UserDataDto( - UserDataGenerator::factory()->buildUserData()->mutate(['lastUpdate' => $dto->getDateEdit() + 10]) + UserDataGenerator::factory() + ->buildUserData() + ->mutate(['lastUpdate' => $lastUpdate]) ) ); diff --git a/tests/SP/Domain/Account/Services/AccountTest.php b/tests/SP/Domain/Account/Services/AccountTest.php index 6d2f0d26..11e38750 100644 --- a/tests/SP/Domain/Account/Services/AccountTest.php +++ b/tests/SP/Domain/Account/Services/AccountTest.php @@ -1,4 +1,5 @@ willReturn(new QueryResult([$accountDataGenerator->buildAccount()])); $this->configService->expects(self::exactly(count($accountsId)))->method('getByParam') ->with('masterPwd')->willReturn(self::$faker->password); - $this->accountItemsService->expects(self::exactly(count($accountsId)))->method('updateItems') + $this->accountItemsService->expects(self::exactly(count($accountsId))) + ->method('updateItems') ->with( ... self::withConsecutive( ... - array_map(fn($v) => [$v, true, $accounts[$v]], $accountsId) + array_map(fn($v) => [true, $v, $accounts[$v]], $accountsId) ) ); @@ -627,7 +629,7 @@ class AccountTest extends UnitaryTestCase ... self::withConsecutive( ... - array_map(fn($v) => [$v, false, $accounts[$v]], $accountsId) + array_map(fn($v) => [false, $v, $accounts[$v]], $accountsId) ) ); @@ -672,7 +674,7 @@ class AccountTest extends UnitaryTestCase ... self::withConsecutive( ... - array_map(fn($v) => [$v, true, $accounts[$v]], $accountsId) + array_map(fn($v) => [true, $v, $accounts[$v]], $accountsId) ) ); @@ -716,7 +718,7 @@ class AccountTest extends UnitaryTestCase ->with( ...self::withConsecutive( ...array_map( - fn($v) => [$v, true, $accounts[$v]], + fn($v) => [true, $v, $accounts[$v]], $accountsId ) ) @@ -755,17 +757,22 @@ class AccountTest extends UnitaryTestCase $account = AccountDataGenerator::factory()->buildAccount(); $accountHistoryCreateDto = new AccountHistoryCreateDto($account, false, true, $password); - $this->configService->expects(self::once())->method('getByParam') - ->with('masterPwd')->willReturn($password); + $this->configService->expects(self::once()) + ->method('getByParam') + ->with('masterPwd') + ->willReturn($password); - $this->accountRepository->expects(self::once())->method('getById') - ->with($id)->willReturn(new QueryResult([$account])); + $this->accountRepository->expects(self::once()) + ->method('getById') + ->with($id) + ->willReturn(new QueryResult([$account])); $this->accountHistoryService->expects(self::once())->method('create') ->with($accountHistoryCreateDto); - $this->accountRepository->expects(self::once())->method('delete') - ->with($id) - ->willReturn(new QueryResult(null, 1)); + $this->accountRepository->expects(self::once()) + ->method('delete') + ->with($id) + ->willReturn(new QueryResult(null, 1)); $this->account->delete($id); } diff --git a/tests/SP/Domain/Auth/Providers/Ldap/LdapActionsTest.php b/tests/SP/Domain/Auth/Providers/Ldap/LdapActionsTest.php index d84b2103..684ac87a 100644 --- a/tests/SP/Domain/Auth/Providers/Ldap/LdapActionsTest.php +++ b/tests/SP/Domain/Auth/Providers/Ldap/LdapActionsTest.php @@ -1,4 +1,5 @@ createMock(Collection::class); $attributes = $this->buildAttributes(); $this->ldap->expects(self::once()) ->method('search') ->with( - $filter, + 'a_filter', null, Ldap::SEARCH_SCOPE_SUB, [], @@ -135,13 +135,13 @@ class LdapActionsTest extends UnitaryTestCase $collection->expects(self::once())->method('getFirst')->willReturn($attributes); - $out = $this->ldapActions->getAttributes($filter); + $out = $this->ldapActions->getAttributes('a_filter'); $expected = new AttributeCollection([ 'dn' => $attributes['dn'], 'group' => array_filter( $attributes['memberof'], - fn($key) => $key !== 'count', + static fn($key) => $key !== 'count', ARRAY_FILTER_USE_KEY ), 'fullname' => $attributes['displayname'], @@ -160,18 +160,18 @@ class LdapActionsTest extends UnitaryTestCase private function buildAttributes(): array { return [ - 'dn' => self::$faker->userName, + 'dn' => self::$faker->userName(), 'memberof' => [ 'count' => 3, - self::$faker->company, - self::$faker->company, - self::$faker->company, + self::$faker->company(), + self::$faker->company(), + self::$faker->company(), ], - 'displayname' => self::$faker->name, - 'givenname' => self::$faker->firstName, - 'sn' => self::$faker->lastName, - 'mail' => self::$faker->email, - 'lockouttime' => self::$faker->unixTime, + 'displayname' => self::$faker->name(), + 'givenname' => self::$faker->firstName(), + 'sn' => self::$faker->lastName(), + 'mail' => self::$faker->email(), + 'lockouttime' => self::$faker->unixTime(), ]; } diff --git a/tests/SP/Generators/AccountDataGenerator.php b/tests/SP/Generators/AccountDataGenerator.php index 8ebfeac9..6076df57 100644 --- a/tests/SP/Generators/AccountDataGenerator.php +++ b/tests/SP/Generators/AccountDataGenerator.php @@ -1,4 +1,5 @@ $this->faker->name(), 'url' => $this->faker->url(), 'notes' => $this->faker->text(), - 'otherUserEdit' => $this->faker->boolean(), - 'otherUserGroupEdit' => $this->faker->boolean(), - 'dateAdd' => $this->faker->unixTime(), - 'dateEdit' => $this->faker->unixTime(), + 'otherUserEdit' => (int)$this->faker->boolean(), + 'otherUserGroupEdit' => (int)$this->faker->boolean(), + 'dateAdd' => $this->faker->dateTime()->format('Y-m-d H:i:s'), + 'dateEdit' => $this->faker->dateTime()->format('Y-m-d H:i:s'), 'countView' => $this->faker->randomNumber(3), 'countDecrypt' => $this->faker->randomNumber(3), - 'isPrivate' => $this->faker->boolean(), - 'isPrivateGroup' => $this->faker->boolean(), + 'isPrivate' => (int)$this->faker->boolean(), + 'isPrivateGroup' => (int)$this->faker->boolean(), 'passDate' => $this->faker->unixTime(), 'passDateChange' => $this->faker->unixTime(), 'parentId' => $this->faker->randomNumber(3), @@ -208,8 +209,8 @@ final class AccountDataGenerator extends DataGenerator accountId: $this->faker->randomNumber(3), isDelete: (int)$this->faker->boolean(), isModify: (int)$this->faker->boolean(), - dateAdd: $this->faker->unixTime(), - dateEdit: $this->faker->unixTime(), + dateAdd: $this->faker->dateTime()->format('Y-m-d H:i:s'), + dateEdit: $this->faker->dateTime()->format('Y-m-d H:i:s'), passDate: $this->faker->unixTime(), countView: $this->faker->randomNumber(3), countDecrypt: $this->faker->randomNumber(3), diff --git a/tests/SP/Generators/ClientGenerator.php b/tests/SP/Generators/ClientGenerator.php index be744d2b..6f06f082 100644 --- a/tests/SP/Generators/ClientGenerator.php +++ b/tests/SP/Generators/ClientGenerator.php @@ -45,7 +45,7 @@ final class ClientGenerator extends DataGenerator 'name' => $this->faker->colorName(), 'description' => $this->faker->text(), 'hash' => $this->faker->sha1(), - 'isGlobal' => $this->faker->boolean() + 'isGlobal' => (int)$this->faker->boolean() ]; } } diff --git a/tests/SP/Generators/CustomFieldDefinitionGenerator.php b/tests/SP/Generators/CustomFieldDefinitionGenerator.php index f8f48c6f..664aec74 100644 --- a/tests/SP/Generators/CustomFieldDefinitionGenerator.php +++ b/tests/SP/Generators/CustomFieldDefinitionGenerator.php @@ -1,4 +1,5 @@ $this->faker->randomNumber(3), 'name' => $this->faker->colorName(), 'moduleId' => $this->faker->randomNumber(3), - 'required' => $this->faker->boolean(), + 'required' => (int)$this->faker->boolean(), 'help' => $this->faker->text(), - 'showInList' => $this->faker->boolean(), + 'showInList' => (int)$this->faker->boolean(), 'typeId' => $this->faker->randomNumber(3), - 'isEncrypted' => $this->faker->boolean(), + 'isEncrypted' => (int)$this->faker->boolean(), ]; } } diff --git a/tests/SP/Generators/PublicLinkDataGenerator.php b/tests/SP/Generators/PublicLinkDataGenerator.php index 817f7e4d..21791964 100644 --- a/tests/SP/Generators/PublicLinkDataGenerator.php +++ b/tests/SP/Generators/PublicLinkDataGenerator.php @@ -1,4 +1,5 @@ $this->faker->randomNumber(3), 'itemId' => $this->faker->randomNumber(3), - 'hash' => $this->faker->randomNumber(3), + 'hash' => $this->faker->sha1(), 'userId' => $this->faker->randomNumber(3), 'typeId' => $this->faker->randomNumber(3), 'notify' => $this->faker->boolean(), - 'dateAdd' => $this->faker->unixTime(), - 'dateUpdate' => $this->faker->unixTime(), - 'dateExpire' => $this->faker->unixTime(), + 'dateAdd' => $this->faker->unixTime(), + 'dateUpdate' => $this->faker->unixTime(), + 'dateExpire' => $this->faker->unixTime(), 'countViews' => $this->faker->randomNumber(3), 'totalCountViews' => $this->faker->randomNumber(3), 'maxCountViews' => $this->faker->randomNumber(3), - 'useInfo' => serialize($this->getUseInfo()), + 'useInfo' => serialize($this->getUseInfo()), 'data' => $this->faker->text(), ]; } diff --git a/tests/SP/Generators/UserDataGenerator.php b/tests/SP/Generators/UserDataGenerator.php index 8466bf7d..2bc18f47 100644 --- a/tests/SP/Generators/UserDataGenerator.php +++ b/tests/SP/Generators/UserDataGenerator.php @@ -46,7 +46,7 @@ final class UserDataGenerator extends DataGenerator return [ 'id' => $this->faker->randomNumber(3), 'name' => $this->faker->name(), - 'email' => $this->faker->randomNumber(3), + 'email' => $this->faker->email(), 'login' => $this->faker->name(), 'ssoLogin' => $this->faker->userName(), 'notes' => $this->faker->text(), @@ -60,8 +60,8 @@ final class UserDataGenerator extends DataGenerator 'isLdap' => $this->faker->boolean(), 'isMigrate' => $this->faker->boolean(), 'loginCount' => $this->faker->randomNumber(3), - 'lastLogin' => $this->faker->unixTime(), - 'lastUpdate' => $this->faker->unixTime(), + 'lastLogin' => $this->faker->dateTime()->format('Y-m-d H:i:s'), + 'lastUpdate' => $this->faker->dateTime()->format('Y-m-d H:i:s'), 'preferences' => serialize($this->buildUserPreferencesData()), 'pass' => $this->faker->password(), 'hashSalt' => $this->faker->sha1(),