Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion lib/private/Group/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ class Group implements IGroup {
private bool $usersLoaded = false;

public function __construct(
/** @var non-empty-string $gid */
private string $gid,
/** @var list<GroupInterface> */
private array $backends,
private IEventDispatcher $dispatcher,
private IUserManager $userManager,
private ?PublicEmitter $emitter = null,
/** @var ?non-empty-string $displayName */
protected ?string $displayName = null,
) {
}
Expand All @@ -63,7 +65,7 @@ public function getDisplayName(): string {
foreach ($this->backends as $backend) {
if ($backend instanceof IGetDisplayNameBackend) {
$displayName = $backend->getDisplayName($this->gid);
if (trim($displayName) !== '') {
if ($displayName !== '') {
$this->displayName = $displayName;
return $this->displayName;
}
Expand Down
9 changes: 0 additions & 9 deletions lib/private/L10N/L10N.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,6 @@ public function getLocaleCode(): string {
return $this->locale ?? '';
}

/**
* Translating
* @param string $text The text we need a translation for
* @param array|string $parameters default:array() Parameters for sprintf
* @return string Translation or the same text
*
* Returns the translation. If no translation is found, $text will be
* returned.
*/
#[\Override]
public function t(string $text, $parameters = []): string {
if (!\is_array($parameters)) {
Expand Down
10 changes: 9 additions & 1 deletion lib/private/L10N/L10NString.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public function __construct(
) {
}

/**
* @return non-empty-string
*/
public function __toString(): string {
$translations = $this->l10n->getTranslations();
$identityTranslator = $this->l10n->getIdentityTranslator();
Expand Down Expand Up @@ -52,7 +55,12 @@ public function __toString(): string {
// $count as %count% as per \Symfony\Contracts\Translation\TranslatorInterface
$text = $identityTranslator->trans($identity, $parameters);

return vsprintf($text, $this->parameters);
$text = vsprintf($text, $this->parameters);
if ($text === '') {
throw new \RuntimeException('The translated text is empty: ' . $this->text);
}

return $text;
}

#[\Override]
Expand Down
13 changes: 13 additions & 0 deletions lib/private/Snowflake/SnowflakeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use OCP\IServerInfo;
use OCP\Snowflake\ISnowflakeGenerator;
use Override;
use RuntimeException;

/**
* Nextcloud Snowflake ID generator
Expand Down Expand Up @@ -59,10 +60,15 @@ public function minForTimeId(int $timestamp): string {
return $this->packSnowflakeId($timestamp - self::TS_OFFSET, 0, 0, 0, 0);
}

/**
* @psalm-suppress MoreSpecificReturnType
* @return non-empty-string
*/
private function packSnowflakeId($seconds, $milliseconds, $serverId, $isCli, $sequenceId): string {
if (PHP_INT_SIZE === 8) {
$firstHalf = $seconds & 0x7FFFFFFF;
$secondHalf = (($milliseconds & 0x3FF) << 22) | ($serverId << 13) | ($isCli << 12) | $sequenceId;
/** @psalm-suppress LessSpecificReturnStatement */
return (string)($firstHalf << 32 | $secondHalf);
}

Expand All @@ -85,6 +91,9 @@ private function packSnowflakeId($seconds, $milliseconds, $serverId, $isCli, $se
/**
* Mostly copied from Symfony:
* https://github.com/symfony/symfony/blob/v7.3.4/src/Symfony/Component/Uid/BinaryUtil.php#L49
*
* @param non-empty-list<non-negative-int> $bytes
* @return non-empty-string
*/
private function convertToDecimal(array $bytes): string {
$base = 10;
Expand All @@ -108,6 +117,10 @@ private function convertToDecimal(array $bytes): string {
$bytes = $quotient;
}

if ($digits === '') {
throw new RuntimeException('Empty digits: ' . var_export($bytes, true));
}

return $digits;
}

Expand Down
3 changes: 3 additions & 0 deletions lib/private/User/DisplayNameCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public function __construct(
$this->memCache = $cacheFactory->createDistributed('displayNameMappingCache');
}

/**
* @return ?non-empty-string
*/
public function getDisplayName(string $userId): ?string {
if (isset($this->cache[$userId])) {
return $this->cache[$userId];
Expand Down
2 changes: 2 additions & 0 deletions lib/private/User/LazyUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ class LazyUser implements IUser {
private ?IUser $user = null;

public function __construct(
/** @var non-empty-string $uid */
private string $uid,
private IUserManager $userManager,
/** @var ?non-empty-string $displayName */
private ?string $displayName = null,
private ?UserInterface $backend = null,
) {
Expand Down
2 changes: 2 additions & 0 deletions lib/private/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class User implements IUser {
private IAssertion $assertion;
protected ?IAccountManager $accountManager = null;

/** @var ?non-empty-string $displayName */
private ?string $displayName = null;
private ?bool $enabled = null;
private ?string $home = null;
Expand All @@ -65,6 +66,7 @@ class User implements IUser {
private ?IAvatarManager $avatarManager = null;

public function __construct(
/** @var non-empty-string $uid */
private string $uid,
private ?UserInterface $backend,
private IEventDispatcher $dispatcher,
Expand Down
4 changes: 2 additions & 2 deletions lib/public/IGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
*/
interface IGroup {
/**
* @return string
* @return non-empty-string
* @since 8.0.0
*/
public function getGID(): string;

/**
* Returns the group display name
*
* @return string
* @return non-empty-string
* @since 12.0.0
*/
public function getDisplayName(): string;
Expand Down
6 changes: 3 additions & 3 deletions lib/public/IL10N.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
interface IL10N {
/**
* Translating
* @param string $text The text we need a translation for
* @param array|string $parameters default:array() Parameters for sprintf
* @return string Translation or the same text
* @param non-empty-string $text The text we need a translation for
* @param array|non-empty-string $parameters default:array() Parameters for sprintf
* @return non-empty-string Translation or the same text
*
* Returns the translation. If no translation is found, $text will be
* returned.
Expand Down
2 changes: 2 additions & 0 deletions lib/public/IUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ interface IUser {
/**
* get the user id
*
* @return non-empty-string
* @since 8.0.0
*/
public function getUID(): string;

/**
* get the display name for the user, if no specific display name is set it will fallback to the user id
*
* @return non-empty-string
* @since 8.0.0
*/
public function getDisplayName(): string;
Expand Down
2 changes: 1 addition & 1 deletion lib/public/IUserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function get($uid);
* Get the display name of a user
*
* @param string $uid
* @return string|null
* @return non-empty-string|null
* @since 25.0.0
*/
public function getDisplayName(string $uid): ?string;
Expand Down
2 changes: 2 additions & 0 deletions lib/public/Snowflake/ISnowflakeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ interface ISnowflakeGenerator {
*
* Each call to this method is guaranteed to return a different ID.
*
* @return non-empty-string
*
* @since 33.0
*/
public function nextId(): string;
Expand Down
7 changes: 6 additions & 1 deletion lib/public/Teams/Team.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,34 @@ class Team implements \JsonSerializable {
* @since 29.0.0
*/
public function __construct(
/** @var non-empty-string */
private string $teamId,
/** @var non-empty-string */
private string $displayName,
/** @var ?non-empty-string */
private ?string $link,
) {
}

/**
* Unique identifier of the team (singleId of the circle)
*
* @return non-empty-string
* @since 29.0.0
*/
public function getId(): string {
return $this->teamId;
}

/**
* @return non-empty-string
* @since 29.0.0
*/
public function getDisplayName(): string {
return $this->displayName;
}

/**
* @return ?non-empty-string
* @since 29.0.0
*/
public function getLink(): ?string {
Expand Down
Loading