mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-07 17:04:30 +02:00
Applied rector with PHP8.1 migration rules
This commit is contained in:
parent
dc6a67c2f0
commit
7ee01d9a05
303 changed files with 1228 additions and 3465 deletions
|
@ -51,7 +51,7 @@ class Group extends AbstractStructuralDBElement implements HasPermissionsInterfa
|
|||
|
||||
#[ORM\ManyToOne(targetEntity: 'Group', inversedBy: 'children')]
|
||||
#[ORM\JoinColumn(name: 'parent_id')]
|
||||
protected ?AbstractStructuralDBElement $parent;
|
||||
protected ?AbstractStructuralDBElement $parent = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, User>
|
||||
|
@ -69,7 +69,7 @@ class Group extends AbstractStructuralDBElement implements HasPermissionsInterfa
|
|||
* @var Collection<int, GroupAttachment>
|
||||
*/
|
||||
#[Assert\Valid]
|
||||
#[ORM\OneToMany(targetEntity: 'App\Entity\Attachments\GroupAttachment', mappedBy: 'element', cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OneToMany(targetEntity: \App\Entity\Attachments\GroupAttachment::class, mappedBy: 'element', cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
||||
protected Collection $attachments;
|
||||
|
||||
|
@ -84,7 +84,7 @@ class Group extends AbstractStructuralDBElement implements HasPermissionsInterfa
|
|||
/** @var Collection<int, GroupParameter>
|
||||
*/
|
||||
#[Assert\Valid]
|
||||
#[ORM\OneToMany(targetEntity: 'App\Entity\Parameters\GroupParameter', mappedBy: 'element', cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OneToMany(targetEntity: \App\Entity\Parameters\GroupParameter::class, mappedBy: 'element', cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['group' => 'ASC', 'name' => 'ASC'])]
|
||||
protected Collection $parameters;
|
||||
|
||||
|
@ -122,7 +122,7 @@ class Group extends AbstractStructuralDBElement implements HasPermissionsInterfa
|
|||
|
||||
public function getPermissions(): PermissionData
|
||||
{
|
||||
if ($this->permissions === null) {
|
||||
if (!$this->permissions instanceof \App\Entity\UserSystem\PermissionData) {
|
||||
$this->permissions = new PermissionData();
|
||||
}
|
||||
|
||||
|
|
|
@ -42,6 +42,10 @@ final class PermissionData implements \JsonSerializable
|
|||
public const CURRENT_SCHEMA_VERSION = 2;
|
||||
|
||||
/**
|
||||
* Creates a new Permission Data Instance using the given data.
|
||||
* By default, an empty array is used, meaning
|
||||
*/
|
||||
public function __construct(/**
|
||||
* @var array|null This array contains the permission values for each permission
|
||||
* This array contains the permission values for each permission, in the form of:
|
||||
* permission => [
|
||||
|
@ -49,19 +53,8 @@ final class PermissionData implements \JsonSerializable
|
|||
* ]
|
||||
*/
|
||||
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::JSON, name: 'data')]
|
||||
protected ?array $data = [
|
||||
//$ prefixed entries are used for metadata
|
||||
'$ver' => self::CURRENT_SCHEMA_VERSION, //The schema version of the permission data
|
||||
];
|
||||
|
||||
/**
|
||||
* Creates a new Permission Data Instance using the given data.
|
||||
* By default, an empty array is used, meaning
|
||||
*/
|
||||
public function __construct(array $data = [])
|
||||
protected array $data = [])
|
||||
{
|
||||
$this->data = $data;
|
||||
|
||||
//If the passed data did not contain a schema version, we set it to the current version
|
||||
if (!isset($this->data['$ver'])) {
|
||||
$this->data['$ver'] = self::CURRENT_SCHEMA_VERSION;
|
||||
|
@ -70,8 +63,6 @@ final class PermissionData implements \JsonSerializable
|
|||
|
||||
/**
|
||||
* Checks if any of the operations of the given permission is defined (meaning it is either ALLOW or DENY)
|
||||
* @param string $permission
|
||||
* @return bool
|
||||
*/
|
||||
public function isAnyOperationOfPermissionSet(string $permission): bool
|
||||
{
|
||||
|
@ -80,7 +71,6 @@ final class PermissionData implements \JsonSerializable
|
|||
|
||||
/**
|
||||
* Returns an associative array containing all defined (non-INHERIT) operations of the given permission.
|
||||
* @param string $permission
|
||||
* @return array An array in the form ["operation" => value], returns an empty array if no operations are defined
|
||||
*/
|
||||
public function getAllDefinedOperationsOfPermission(string $permission): array
|
||||
|
@ -95,8 +85,6 @@ final class PermissionData implements \JsonSerializable
|
|||
/**
|
||||
* Sets all operations of the given permission via the given array.
|
||||
* The data is an array in the form [$operation => $value], all existing values will be overwritten/deleted.
|
||||
* @param string $permission
|
||||
* @param array $data
|
||||
* @return $this
|
||||
*/
|
||||
public function setAllOperationsOfPermission(string $permission, array $data): self
|
||||
|
@ -108,7 +96,6 @@ final class PermissionData implements \JsonSerializable
|
|||
|
||||
/**
|
||||
* Removes a whole permission from the data including all operations (effectivly setting them to INHERIT)
|
||||
* @param string $permission
|
||||
* @return $this
|
||||
*/
|
||||
public function removePermission(string $permission): self
|
||||
|
@ -120,8 +107,6 @@ final class PermissionData implements \JsonSerializable
|
|||
|
||||
/**
|
||||
* Check if a permission value is set for the given permission and operation (meaning there value is not inherit).
|
||||
* @param string $permission
|
||||
* @param string $operation
|
||||
* @return bool True if the permission value is set, false otherwise
|
||||
*/
|
||||
public function isPermissionSet(string $permission, string $operation): bool
|
||||
|
@ -136,8 +121,6 @@ final class PermissionData implements \JsonSerializable
|
|||
|
||||
/**
|
||||
* Returns the permission value for the given permission and operation.
|
||||
* @param string $permission
|
||||
* @param string $operation
|
||||
* @return bool|null True means allow, false means disallow, null means inherit
|
||||
*/
|
||||
public function getPermissionValue(string $permission, string $operation): ?bool
|
||||
|
@ -152,9 +135,6 @@ final class PermissionData implements \JsonSerializable
|
|||
|
||||
/**
|
||||
* Sets the permission value for the given permission and operation.
|
||||
* @param string $permission
|
||||
* @param string $operation
|
||||
* @param bool|null $value
|
||||
* @return $this
|
||||
*/
|
||||
public function setPermissionValue(string $permission, string $operation, ?bool $value): self
|
||||
|
@ -185,8 +165,6 @@ final class PermissionData implements \JsonSerializable
|
|||
|
||||
/**
|
||||
* Creates a new Permission Data Instance using the given JSON encoded data
|
||||
* @param string $json
|
||||
* @return static
|
||||
* @throws \JsonException
|
||||
*/
|
||||
public static function fromJSON(string $json): self
|
||||
|
@ -202,7 +180,6 @@ final class PermissionData implements \JsonSerializable
|
|||
|
||||
/**
|
||||
* Returns an JSON encodable representation of this object.
|
||||
* @return array
|
||||
*/
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
|
@ -215,9 +192,7 @@ final class PermissionData implements \JsonSerializable
|
|||
continue;
|
||||
}
|
||||
|
||||
$ret[$permission] = array_filter($operations, static function ($value) {
|
||||
return $value !== null;
|
||||
});
|
||||
$ret[$permission] = array_filter($operations, static fn($value) => $value !== null);
|
||||
|
||||
//If the permission has no operations, unset it
|
||||
if (empty($ret[$permission])) {
|
||||
|
@ -239,7 +214,6 @@ final class PermissionData implements \JsonSerializable
|
|||
|
||||
/**
|
||||
* Sets the schema version of this permission data
|
||||
* @param int $new_version
|
||||
* @return $this
|
||||
*/
|
||||
public function setSchemaVersion(int $new_version): self
|
||||
|
|
|
@ -73,7 +73,7 @@ class U2FKey implements LegacyU2FKeyInterface
|
|||
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING)]
|
||||
protected string $name;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: 'App\Entity\UserSystem\User', inversedBy: 'u2fKeys')]
|
||||
#[ORM\ManyToOne(targetEntity: \App\Entity\UserSystem\User::class, inversedBy: 'u2fKeys')]
|
||||
protected ?User $user = null;
|
||||
|
||||
public function getKeyHandle(): string
|
||||
|
|
|
@ -56,8 +56,8 @@ use Jbtronics\TFAWebauthn\Model\TwoFactorInterface as WebauthnTwoFactorInterface
|
|||
* Also, this entity is able to save some information about the user, like the names, email-address and other info.
|
||||
*/
|
||||
#[UniqueEntity('name', message: 'validator.user.username_already_used')]
|
||||
#[ORM\Entity(repositoryClass: 'App\Repository\UserRepository')]
|
||||
#[ORM\EntityListeners(['App\EntityListeners\TreeCacheInvalidationListener'])]
|
||||
#[ORM\Entity(repositoryClass: \App\Repository\UserRepository::class)]
|
||||
#[ORM\EntityListeners([\App\EntityListeners\TreeCacheInvalidationListener::class])]
|
||||
#[ORM\Table('`users`')]
|
||||
#[ORM\Index(name: 'user_idx_username', columns: ['name'])]
|
||||
class User extends AttachmentContainingDBElement implements UserInterface, HasPermissionsInterface, TwoFactorInterface,
|
||||
|
@ -68,7 +68,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
/**
|
||||
* The User id of the anonymous user.
|
||||
*/
|
||||
public const ID_ANONYMOUS = 1;
|
||||
final public const ID_ANONYMOUS = 1;
|
||||
|
||||
/**
|
||||
* @var bool Determines if the user is disabled (user can not log in)
|
||||
|
@ -214,7 +214,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
/**
|
||||
* @var Collection<int, UserAttachment>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: 'App\Entity\Attachments\UserAttachment', mappedBy: 'element', cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OneToMany(targetEntity: \App\Entity\Attachments\UserAttachment::class, mappedBy: 'element', cascade: ['persist', 'remove'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['name' => 'ASC'])]
|
||||
protected Collection $attachments;
|
||||
|
||||
|
@ -226,13 +226,13 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
|
||||
/** @var Collection<int, LegacyU2FKeyInterface>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: 'App\Entity\UserSystem\U2FKey', mappedBy: 'user', cascade: ['REMOVE'], orphanRemoval: true)]
|
||||
#[ORM\OneToMany(targetEntity: \App\Entity\UserSystem\U2FKey::class, mappedBy: 'user', cascade: ['REMOVE'], orphanRemoval: true)]
|
||||
protected Collection $u2fKeys;
|
||||
|
||||
/**
|
||||
* @var Collection<int, WebauthnKey>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: 'App\Entity\UserSystem\WebauthnKey', mappedBy: 'user', cascade: ['REMOVE'], orphanRemoval: true)]
|
||||
#[ORM\OneToMany(targetEntity: \App\Entity\UserSystem\WebauthnKey::class, mappedBy: 'user', cascade: ['REMOVE'], orphanRemoval: true)]
|
||||
protected Collection $webauthn_keys;
|
||||
|
||||
/**
|
||||
|
@ -243,9 +243,9 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
* @Selectable()
|
||||
*/
|
||||
#[Groups(['extended', 'full', 'import'])]
|
||||
#[ORM\ManyToOne(targetEntity: 'App\Entity\PriceInformations\Currency')]
|
||||
#[ORM\ManyToOne(targetEntity: \App\Entity\PriceInformations\Currency::class)]
|
||||
#[ORM\JoinColumn(name: 'currency_id')]
|
||||
protected ?Currency $currency;
|
||||
protected ?Currency $currency = null;
|
||||
|
||||
/**
|
||||
* @var PermissionData|null
|
||||
|
@ -259,7 +259,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
* @var \DateTimeInterface|null the time until the password reset token is valid
|
||||
*/
|
||||
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::DATETIME_MUTABLE, nullable: true)]
|
||||
protected ?\DateTimeInterface $pw_reset_expires;
|
||||
protected ?\DateTimeInterface $pw_reset_expires = null;
|
||||
|
||||
/**
|
||||
* @var bool True if the user was created by a SAML provider (and therefore cannot change its password)
|
||||
|
@ -350,8 +350,6 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
|
||||
/**
|
||||
* Sets the password hash for this user.
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function setPassword(string $password): self
|
||||
{
|
||||
|
@ -389,8 +387,6 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
|
||||
/**
|
||||
* Sets the currency the users prefers to see prices in.
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function setCurrency(?Currency $currency): self
|
||||
{
|
||||
|
@ -413,8 +409,6 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
* Sets the status if a user is disabled.
|
||||
*
|
||||
* @param bool $disabled true if the user should be disabled
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function setDisabled(bool $disabled): self
|
||||
{
|
||||
|
@ -425,7 +419,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
|
||||
public function getPermissions(): PermissionData
|
||||
{
|
||||
if ($this->permissions === null) {
|
||||
if (!$this->permissions instanceof \App\Entity\UserSystem\PermissionData) {
|
||||
$this->permissions = new PermissionData();
|
||||
}
|
||||
|
||||
|
@ -442,8 +436,6 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
|
||||
/**
|
||||
* Set the status, if the user needs a password change.
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function setNeedPwChange(bool $need_pw_change): self
|
||||
{
|
||||
|
@ -462,8 +454,6 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
|
||||
/**
|
||||
* Sets the encrypted password reset token.
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function setPwResetToken(?string $pw_reset_token): self
|
||||
{
|
||||
|
@ -482,8 +472,6 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
|
||||
/**
|
||||
* Sets the datetime when the password reset token expires.
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function setPwResetExpires(\DateTimeInterface $pw_reset_expires): self
|
||||
{
|
||||
|
@ -595,8 +583,6 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
* Change the department of the user.
|
||||
*
|
||||
* @param string|null $department The new department
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function setDepartment(?string $department): self
|
||||
{
|
||||
|
@ -631,7 +617,6 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
|
||||
/**
|
||||
* Gets whether the email address of the user is shown on the public profile page.
|
||||
* @return bool
|
||||
*/
|
||||
public function isShowEmailOnProfile(): bool
|
||||
{
|
||||
|
@ -640,8 +625,6 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
|
||||
/**
|
||||
* Sets whether the email address of the user is shown on the public profile page.
|
||||
* @param bool $show_email_on_profile
|
||||
* @return User
|
||||
*/
|
||||
public function setShowEmailOnProfile(bool $show_email_on_profile): User
|
||||
{
|
||||
|
@ -653,7 +636,6 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
|
||||
/**
|
||||
* Returns the about me text of the user.
|
||||
* @return string
|
||||
*/
|
||||
public function getAboutMe(): string
|
||||
{
|
||||
|
@ -662,8 +644,6 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
|
||||
/**
|
||||
* Change the about me text of the user.
|
||||
* @param string $aboutMe
|
||||
* @return User
|
||||
*/
|
||||
public function setAboutMe(string $aboutMe): User
|
||||
{
|
||||
|
@ -689,8 +669,6 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
*
|
||||
* @param string|null $language The new language as 2-letter ISO code (e.g. 'en' or 'de').
|
||||
* Set to null, to use the system-wide language.
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function setLanguage(?string $language): self
|
||||
{
|
||||
|
@ -855,11 +833,7 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
public function setBackupCodes(array $codes): self
|
||||
{
|
||||
$this->backupCodes = $codes;
|
||||
if (empty($codes)) {
|
||||
$this->backupCodesGenerationDate = null;
|
||||
} else {
|
||||
$this->backupCodesGenerationDate = new DateTime();
|
||||
}
|
||||
$this->backupCodesGenerationDate = $codes === [] ? null : new DateTime();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -938,7 +912,6 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
|
||||
/**
|
||||
* Returns true, if the user was created by the SAML authentication.
|
||||
* @return bool
|
||||
*/
|
||||
public function isSamlUser(): bool
|
||||
{
|
||||
|
@ -947,8 +920,6 @@ class User extends AttachmentContainingDBElement implements UserInterface, HasPe
|
|||
|
||||
/**
|
||||
* Sets the saml_user flag.
|
||||
* @param bool $saml_user
|
||||
* @return User
|
||||
*/
|
||||
public function setSamlUser(bool $saml_user): User
|
||||
{
|
||||
|
|
|
@ -39,48 +39,31 @@ class WebauthnKey extends BasePublicKeyCredentialSource
|
|||
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING)]
|
||||
protected string $name;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: 'App\Entity\UserSystem\User', inversedBy: 'webauthn_keys')]
|
||||
#[ORM\ManyToOne(targetEntity: \App\Entity\UserSystem\User::class, inversedBy: 'webauthn_keys')]
|
||||
protected ?User $user = null;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return WebauthnKey
|
||||
*/
|
||||
public function setName(string $name): WebauthnKey
|
||||
{
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return User|null
|
||||
*/
|
||||
public function getUser(): ?User
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User|null $user
|
||||
* @return WebauthnKey
|
||||
*/
|
||||
public function setUser(?User $user): WebauthnKey
|
||||
{
|
||||
$this->user = $user;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue