mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-12 03:14:32 +02:00
Fixed some inspection issues.
This commit is contained in:
parent
eef26f7ae6
commit
639829f5c5
97 changed files with 305 additions and 185 deletions
|
@ -24,6 +24,7 @@ declare(strict_types=1);
|
|||
namespace App\Services\LogSystem;
|
||||
|
||||
use App\Entity\LogSystem\AbstractLogEntry;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class EventUndoHelper
|
||||
{
|
||||
|
@ -44,7 +45,7 @@ class EventUndoHelper
|
|||
public function setMode(string $mode): void
|
||||
{
|
||||
if (!in_array($mode, self::ALLOWED_MODES, true)) {
|
||||
throw new \InvalidArgumentException('Invalid mode passed!');
|
||||
throw new InvalidArgumentException('Invalid mode passed!');
|
||||
}
|
||||
$this->mode = $mode;
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ namespace App\Services\LogSystem;
|
|||
use App\Entity\Attachments\AttachmentContainingDBElement;
|
||||
use App\Entity\Base\AbstractDBElement;
|
||||
use App\Entity\Base\AbstractStructuralDBElement;
|
||||
use App\Entity\Parameters\AbstractParameter;
|
||||
use App\Entity\Parts\Part;
|
||||
|
||||
class HistoryHelper
|
||||
|
@ -38,7 +39,7 @@ class HistoryHelper
|
|||
* Returns an array containing all elements that are associated with the argument.
|
||||
* The returned array contains the given element.
|
||||
*
|
||||
* @psalm-return array<\App\Entity\Parameters\AbstractParameter|array-key, mixed>
|
||||
* @psalm-return array<AbstractParameter|array-key, mixed>
|
||||
*/
|
||||
public function getAssociatedElements(AbstractDBElement $element): array
|
||||
{
|
||||
|
|
|
@ -33,9 +33,14 @@ use App\Entity\LogSystem\AbstractLogEntry;
|
|||
use App\Entity\LogSystem\CollectionElementDeleted;
|
||||
use App\Entity\LogSystem\ElementEditedLogEntry;
|
||||
use Brick\Math\BigDecimal;
|
||||
use DateTime;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Doctrine\ORM\Mapping\MappingException;
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
use ReflectionClass;
|
||||
|
||||
class TimeTravel
|
||||
{
|
||||
|
@ -74,16 +79,16 @@ class TimeTravel
|
|||
*
|
||||
* @param AbstractLogEntry[] $reverted_elements
|
||||
*
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function revertEntityToTimestamp(AbstractDBElement $element, \DateTime $timestamp, array $reverted_elements = []): void
|
||||
public function revertEntityToTimestamp(AbstractDBElement $element, DateTime $timestamp, array $reverted_elements = []): void
|
||||
{
|
||||
if (!$element instanceof TimeStampableInterface) {
|
||||
throw new \InvalidArgumentException('$element must have a Timestamp!');
|
||||
throw new InvalidArgumentException('$element must have a Timestamp!');
|
||||
}
|
||||
|
||||
if ($timestamp > new \DateTime('now')) {
|
||||
throw new \InvalidArgumentException('You can not travel to the future (yet)...');
|
||||
if ($timestamp > new DateTime('now')) {
|
||||
throw new InvalidArgumentException('You can not travel to the future (yet)...');
|
||||
}
|
||||
|
||||
//Skip this process if already were reverted...
|
||||
|
@ -168,7 +173,7 @@ class TimeTravel
|
|||
/**
|
||||
* Apply the changeset in the given LogEntry to the element.
|
||||
*
|
||||
* @throws \Doctrine\ORM\Mapping\MappingException
|
||||
* @throws MappingException
|
||||
*/
|
||||
public function applyEntry(AbstractDBElement $element, TimeTravelInterface $logEntry): void
|
||||
{
|
||||
|
@ -207,7 +212,7 @@ class TimeTravel
|
|||
|
||||
protected function getField(AbstractDBElement $element, string $field)
|
||||
{
|
||||
$reflection = new \ReflectionClass(get_class($element));
|
||||
$reflection = new ReflectionClass(get_class($element));
|
||||
$property = $reflection->getProperty($field);
|
||||
$property->setAccessible(true);
|
||||
|
||||
|
@ -215,11 +220,11 @@ class TimeTravel
|
|||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime|int|null $new_value
|
||||
* @param DateTime|int|null $new_value
|
||||
*/
|
||||
protected function setField(AbstractDBElement $element, string $field, $new_value): void
|
||||
{
|
||||
$reflection = new \ReflectionClass(get_class($element));
|
||||
$reflection = new ReflectionClass(get_class($element));
|
||||
$property = $reflection->getProperty($field);
|
||||
$property->setAccessible(true);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue