mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-12 11:24:31 +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
|
@ -43,12 +43,10 @@ use ReflectionClass;
|
|||
|
||||
class TimeTravel
|
||||
{
|
||||
protected EntityManagerInterface $em;
|
||||
protected LogEntryRepository $repo;
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
public function __construct(protected EntityManagerInterface $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
$this->repo = $em->getRepository(AbstractLogEntry::class);
|
||||
}
|
||||
|
||||
|
@ -126,7 +124,7 @@ class TimeTravel
|
|||
}
|
||||
|
||||
// Revert any of the associated elements
|
||||
$metadata = $this->em->getClassMetadata(get_class($element));
|
||||
$metadata = $this->em->getClassMetadata($element::class);
|
||||
$associations = $metadata->getAssociationMappings();
|
||||
foreach ($associations as $field => $mapping) {
|
||||
if (
|
||||
|
@ -148,10 +146,10 @@ class TimeTravel
|
|||
} elseif ( //Revert *_TO_MANY associations (collection properties)
|
||||
(ClassMetadataInfo::MANY_TO_MANY === $mapping['type']
|
||||
|| ClassMetadataInfo::ONE_TO_MANY === $mapping['type'])
|
||||
&& false === $mapping['isOwningSide']
|
||||
&& !$mapping['isOwningSide']
|
||||
) {
|
||||
$target_elements = $this->getField($element, $field);
|
||||
if (null === $target_elements || count($target_elements) > 10) {
|
||||
if (null === $target_elements || (is_countable($target_elements) ? count($target_elements) : 0) > 10) {
|
||||
continue;
|
||||
}
|
||||
foreach ($target_elements as $target_element) {
|
||||
|
@ -200,7 +198,7 @@ class TimeTravel
|
|||
if (!$element instanceof TimeStampableInterface) {
|
||||
return;
|
||||
}
|
||||
$metadata = $this->em->getClassMetadata(get_class($element));
|
||||
$metadata = $this->em->getClassMetadata($element::class);
|
||||
$old_data = $logEntry->getOldData();
|
||||
|
||||
foreach ($old_data as $field => $data) {
|
||||
|
@ -232,19 +230,16 @@ class TimeTravel
|
|||
|
||||
protected function getField(AbstractDBElement $element, string $field)
|
||||
{
|
||||
$reflection = new ReflectionClass(get_class($element));
|
||||
$reflection = new ReflectionClass($element::class);
|
||||
$property = $reflection->getProperty($field);
|
||||
$property->setAccessible(true);
|
||||
|
||||
return $property->getValue($element);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DateTime|int|null $new_value
|
||||
*/
|
||||
protected function setField(AbstractDBElement $element, string $field, $new_value): void
|
||||
protected function setField(AbstractDBElement $element, string $field, \DateTime|int|null $new_value): void
|
||||
{
|
||||
$reflection = new ReflectionClass(get_class($element));
|
||||
$reflection = new ReflectionClass($element::class);
|
||||
$property = $reflection->getProperty($field);
|
||||
$property->setAccessible(true);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue