mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-25 19:28:51 +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
|
@ -61,14 +61,14 @@ use App\Repository\LogEntryRepository;
|
|||
#[ORM\Index(columns: ['datetime'], name: 'log_idx_datetime')]
|
||||
abstract class AbstractLogEntry extends AbstractDBElement
|
||||
{
|
||||
public const LEVEL_EMERGENCY = 0;
|
||||
public const LEVEL_ALERT = 1;
|
||||
public const LEVEL_CRITICAL = 2;
|
||||
public const LEVEL_ERROR = 3;
|
||||
public const LEVEL_WARNING = 4;
|
||||
public const LEVEL_NOTICE = 5;
|
||||
public const LEVEL_INFO = 6;
|
||||
public const LEVEL_DEBUG = 7;
|
||||
final public const LEVEL_EMERGENCY = 0;
|
||||
final public const LEVEL_ALERT = 1;
|
||||
final public const LEVEL_CRITICAL = 2;
|
||||
final public const LEVEL_ERROR = 3;
|
||||
final public const LEVEL_WARNING = 4;
|
||||
final public const LEVEL_NOTICE = 5;
|
||||
final public const LEVEL_INFO = 6;
|
||||
final public const LEVEL_DEBUG = 7;
|
||||
|
||||
protected const TARGET_TYPE_NONE = 0;
|
||||
protected const TARGET_TYPE_USER = 1;
|
||||
|
@ -129,7 +129,7 @@ abstract class AbstractLogEntry extends AbstractDBElement
|
|||
|
||||
/** @var User|null The user which has caused this log entry
|
||||
*/
|
||||
#[ORM\ManyToOne(targetEntity: 'App\Entity\UserSystem\User', fetch: 'EAGER')]
|
||||
#[ORM\ManyToOne(targetEntity: \App\Entity\UserSystem\User::class, fetch: 'EAGER')]
|
||||
#[ORM\JoinColumn(name: 'id_user', onDelete: 'SET NULL')]
|
||||
protected ?User $user = null;
|
||||
|
||||
|
@ -147,7 +147,7 @@ abstract class AbstractLogEntry extends AbstractDBElement
|
|||
/** @var int The priority level of the associated level. 0 is highest, 7 lowest
|
||||
*/
|
||||
#[ORM\Column(type: 'tinyint', name: 'level')]
|
||||
protected int $level;
|
||||
protected int $level = self::LEVEL_WARNING;
|
||||
|
||||
/** @var int The ID of the element targeted by this event
|
||||
*/
|
||||
|
@ -173,7 +173,6 @@ abstract class AbstractLogEntry extends AbstractDBElement
|
|||
public function __construct()
|
||||
{
|
||||
$this->timestamp = new DateTime();
|
||||
$this->level = self::LEVEL_WARNING;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -214,7 +213,6 @@ abstract class AbstractLogEntry extends AbstractDBElement
|
|||
* Marks this log entry as a CLI entry, and set the username of the CLI user.
|
||||
* This removes the association to a user object in database, as CLI users are not really related to logged in
|
||||
* Part-DB users.
|
||||
* @param string $cli_username
|
||||
* @return $this
|
||||
*/
|
||||
public function setCLIUsername(string $cli_username): self
|
||||
|
@ -372,14 +370,14 @@ abstract class AbstractLogEntry extends AbstractDBElement
|
|||
*/
|
||||
public function setTargetElement(?AbstractDBElement $element): self
|
||||
{
|
||||
if (null === $element) {
|
||||
if (!$element instanceof \App\Entity\Base\AbstractDBElement) {
|
||||
$this->target_id = 0;
|
||||
$this->target_type = self::TARGET_TYPE_NONE;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->target_type = static::targetTypeClassToID(get_class($element));
|
||||
$this->target_type = static::targetTypeClassToID($element::class);
|
||||
$this->target_id = $element->getID();
|
||||
|
||||
return $this;
|
||||
|
|
|
@ -93,11 +93,9 @@ class CollectionElementDeleted extends AbstractLogEntry implements LogWithEventU
|
|||
public function __construct(AbstractDBElement $changed_element, string $collection_name, AbstractDBElement $deletedElement)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->level = self::LEVEL_INFO;
|
||||
$this->setTargetElement($changed_element);
|
||||
$this->extra['n'] = $collection_name;
|
||||
$this->extra['c'] = self::targetTypeClassToID(get_class($deletedElement));
|
||||
$this->extra['c'] = self::targetTypeClassToID($deletedElement::class);
|
||||
$this->extra['i'] = $deletedElement->getID();
|
||||
if ($deletedElement instanceof NamedElementInterface) {
|
||||
$this->extra['o'] = $deletedElement->getName();
|
||||
|
@ -141,8 +139,6 @@ class CollectionElementDeleted extends AbstractLogEntry implements LogWithEventU
|
|||
/**
|
||||
* This functions maps an abstract class name derived from the extra c element to an instantiable class name (based on the target element of this log entry).
|
||||
* For example if the target element is a part and the extra c element is "App\Entity\Attachments\Attachment", this function will return "App\Entity\Attachments\PartAttachment".
|
||||
* @param string $abstract_class
|
||||
* @return string
|
||||
*/
|
||||
private function resolveAbstractClassToInstantiableClass(string $abstract_class): string
|
||||
{
|
||||
|
|
|
@ -26,9 +26,9 @@ use Doctrine\ORM\Mapping as ORM;
|
|||
#[ORM\Entity]
|
||||
class PartStockChangedLogEntry extends AbstractLogEntry
|
||||
{
|
||||
public const TYPE_ADD = "add";
|
||||
public const TYPE_WITHDRAW = "withdraw";
|
||||
public const TYPE_MOVE = "move";
|
||||
final public const TYPE_ADD = "add";
|
||||
final public const TYPE_WITHDRAW = "withdraw";
|
||||
final public const TYPE_MOVE = "move";
|
||||
|
||||
protected string $typeString = 'part_stock_changed';
|
||||
|
||||
|
@ -68,7 +68,7 @@ class PartStockChangedLogEntry extends AbstractLogEntry
|
|||
$this->extra['c'] = mb_strimwidth($comment, 0, self::COMMENT_MAX_LENGTH, '...');
|
||||
}
|
||||
|
||||
if ($move_to_target) {
|
||||
if ($move_to_target instanceof \App\Entity\Parts\PartLot) {
|
||||
if ($type !== self::TYPE_MOVE) {
|
||||
throw new \InvalidArgumentException('The move_to_target parameter can only be set if the type is "move"!');
|
||||
}
|
||||
|
@ -130,7 +130,6 @@ class PartStockChangedLogEntry extends AbstractLogEntry
|
|||
|
||||
/**
|
||||
* Returns the old stock of the lot.
|
||||
* @return float
|
||||
*/
|
||||
public function getOldStock(): float
|
||||
{
|
||||
|
@ -139,7 +138,6 @@ class PartStockChangedLogEntry extends AbstractLogEntry
|
|||
|
||||
/**
|
||||
* Returns the new stock of the lot.
|
||||
* @return float
|
||||
*/
|
||||
public function getNewStock(): float
|
||||
{
|
||||
|
@ -148,7 +146,6 @@ class PartStockChangedLogEntry extends AbstractLogEntry
|
|||
|
||||
/**
|
||||
* Returns the new total instock of the part.
|
||||
* @return float
|
||||
*/
|
||||
public function getNewTotalPartInstock(): float
|
||||
{
|
||||
|
@ -157,7 +154,6 @@ class PartStockChangedLogEntry extends AbstractLogEntry
|
|||
|
||||
/**
|
||||
* Returns the comment associated with the change.
|
||||
* @return string
|
||||
*/
|
||||
public function getComment(): string
|
||||
{
|
||||
|
@ -166,7 +162,6 @@ class PartStockChangedLogEntry extends AbstractLogEntry
|
|||
|
||||
/**
|
||||
* Gets the difference between the old and the new stock value of the lot as a positive number.
|
||||
* @return float
|
||||
*/
|
||||
public function getChangeAmount(): float
|
||||
{
|
||||
|
@ -175,7 +170,6 @@ class PartStockChangedLogEntry extends AbstractLogEntry
|
|||
|
||||
/**
|
||||
* Returns the target lot ID (where the instock was moved to) if the type is TYPE_MOVE.
|
||||
* @return int|null
|
||||
*/
|
||||
public function getMoveToTargetID(): ?int
|
||||
{
|
||||
|
@ -184,39 +178,27 @@ class PartStockChangedLogEntry extends AbstractLogEntry
|
|||
|
||||
/**
|
||||
* Converts the human-readable type (TYPE_* consts) to the version stored in DB
|
||||
* @param string $type
|
||||
* @return string
|
||||
*/
|
||||
protected function typeToShortType(string $type): string
|
||||
{
|
||||
switch ($type) {
|
||||
case self::TYPE_ADD:
|
||||
return 'a';
|
||||
case self::TYPE_WITHDRAW:
|
||||
return 'w';
|
||||
case self::TYPE_MOVE:
|
||||
return 'm';
|
||||
default:
|
||||
throw new \InvalidArgumentException('Invalid type: '.$type);
|
||||
}
|
||||
return match ($type) {
|
||||
self::TYPE_ADD => 'a',
|
||||
self::TYPE_WITHDRAW => 'w',
|
||||
self::TYPE_MOVE => 'm',
|
||||
default => throw new \InvalidArgumentException('Invalid type: '.$type),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the short type stored in DB to the human-readable type (TYPE_* consts).
|
||||
* @param string $short_type
|
||||
* @return string
|
||||
*/
|
||||
protected function shortTypeToType(string $short_type): string
|
||||
{
|
||||
switch ($short_type) {
|
||||
case 'a':
|
||||
return self::TYPE_ADD;
|
||||
case 'w':
|
||||
return self::TYPE_WITHDRAW;
|
||||
case 'm':
|
||||
return self::TYPE_MOVE;
|
||||
default:
|
||||
throw new \InvalidArgumentException('Invalid short type: '.$short_type);
|
||||
}
|
||||
return match ($short_type) {
|
||||
'a' => self::TYPE_ADD,
|
||||
'w' => self::TYPE_WITHDRAW,
|
||||
'm' => self::TYPE_MOVE,
|
||||
default => throw new \InvalidArgumentException('Invalid short type: '.$short_type),
|
||||
};
|
||||
}
|
||||
}
|
|
@ -54,7 +54,7 @@ use Symfony\Component\HttpFoundation\IpUtils;
|
|||
#[ORM\Entity]
|
||||
class SecurityEventLogEntry extends AbstractLogEntry
|
||||
{
|
||||
public const SECURITY_TYPE_MAPPING = [
|
||||
final public const SECURITY_TYPE_MAPPING = [
|
||||
0 => SecurityEvents::PASSWORD_CHANGED,
|
||||
1 => SecurityEvents::PASSWORD_RESET,
|
||||
2 => SecurityEvents::BACKUP_KEYS_RESET,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue