Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Cleanup classes #40

Merged
merged 1 commit into from
Feb 22, 2024
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
13 changes: 12 additions & 1 deletion src/Debug/MapperDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
use Symfony\Bundle\FrameworkBundle\DataCollector\AbstractDataCollector;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\Service\ResetInterface;

/**
* @internal
*/
final class MapperDataCollector extends AbstractDataCollector
final class MapperDataCollector extends AbstractDataCollector implements ResetInterface
{
public function getName(): string
{
Expand Down Expand Up @@ -135,4 +136,14 @@ public function getTotalTime(): float
$this->getMappings()
));
}

public function reset(): void
{
$this->data = [];
$this->totalMappings = null;
$this->totalMappingsIncludingSubMappings = null;
$this->totalTime = null;

parent::reset();
}
}
8 changes: 7 additions & 1 deletion src/Debug/TraceableMappingFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@

use Rekalogika\Mapper\Mapping\Mapping;
use Rekalogika\Mapper\Mapping\MappingFactoryInterface;
use Symfony\Contracts\Service\ResetInterface;

/**
* @internal
*/
final class TraceableMappingFactory implements MappingFactoryInterface
final class TraceableMappingFactory implements MappingFactoryInterface, ResetInterface
{
private bool $mappingCollected = false;

Expand All @@ -29,6 +30,11 @@ public function __construct(
) {
}

public function reset(): void
{
$this->mappingCollected = false;
}

public function getMapping(): Mapping
{
if ($this->mappingCollected) {
Expand Down
13 changes: 4 additions & 9 deletions src/Debug/TraceableTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ final class TraceableTransformer extends AbstractTransformerDecorator implements
{
use MainTransformerAwareTrait;

private bool $withMainTransformerCalled = false;

public function __construct(
private TransformerInterface $decorated,
private MapperDataCollector $dataCollector
Expand All @@ -48,17 +46,14 @@ public function getDecorated(): TransformerInterface

public function withMainTransformer(MainTransformerInterface $mainTransformer): static
{
if ($this->withMainTransformerCalled) {
if (!$this->decorated instanceof MainTransformerAwareInterface) {
return $this;
}

$this->withMainTransformerCalled = true;

if ($this->decorated instanceof MainTransformerAwareInterface) {
$this->decorated = $this->decorated->withMainTransformer($mainTransformer);
}
$clone = clone $this;
$clone->decorated = $this->decorated->withMainTransformer($mainTransformer);

return $this;
return $clone;
}

public function transform(
Expand Down
8 changes: 7 additions & 1 deletion src/MainTransformer/Implementation/MainTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@
use Rekalogika\Mapper\Util\TypeCheck;
use Rekalogika\Mapper\Util\TypeGuesser;
use Symfony\Component\PropertyInfo\Type;
use Symfony\Contracts\Service\ResetInterface;

/**
* @internal
*/
final class MainTransformer implements MainTransformerInterface
final class MainTransformer implements MainTransformerInterface, ResetInterface
{
public static int $manualGcInterval = 500;
private static int $runCounter = 1;
Expand All @@ -51,6 +52,11 @@ public function __construct(
) {
}

public function reset(): void
{
self::$runCounter = 1;
}

private function processTransformer(
TransformerInterface $transformer
): TransformerInterface {
Expand Down
2 changes: 1 addition & 1 deletion src/ObjectCache/Implementation/ObjectCacheFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Rekalogika\Mapper\ObjectCache\ObjectCacheFactoryInterface;
use Rekalogika\Mapper\TypeResolver\TypeResolverInterface;

final class ObjectCacheFactory implements ObjectCacheFactoryInterface
final readonly class ObjectCacheFactory implements ObjectCacheFactoryInterface
{
public function __construct(
private TypeResolverInterface $typeResolver
Expand Down
6 changes: 5 additions & 1 deletion src/Proxy/ProxyNamer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@
/**
* @internal
*/
class ProxyNamer
final readonly class ProxyNamer
{
public function __construct()
{
}

/**
* @param class-string $class
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Serializer/DenormalizerContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
* @deprecated
* @phpstan-ignore-next-line
*/
class DenormalizerContext extends AbstractSerializerContext
final class DenormalizerContext extends AbstractSerializerContext
{
}
2 changes: 1 addition & 1 deletion src/Serializer/NormalizerContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
* @deprecated
* @phpstan-ignore-next-line
*/
class NormalizerContext extends AbstractSerializerContext
final class NormalizerContext extends AbstractSerializerContext
{
}
2 changes: 1 addition & 1 deletion src/Transformer/Util/ReaderWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/**
* @internal
*/
class ReaderWriter
final readonly class ReaderWriter
{
/**
* @throws UninitializedSourcePropertyException
Expand Down
2 changes: 1 addition & 1 deletion src/Util/TypeCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Rekalogika\Mapper\Transformer\MixedType;
use Symfony\Component\PropertyInfo\Type;

final class TypeCheck
final readonly class TypeCheck
{
private function __construct()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Util/TypeGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Rekalogika\Mapper\Exception\InvalidArgumentException;
use Symfony\Component\PropertyInfo\Type;

final class TypeGuesser
final readonly class TypeGuesser
{
private function __construct()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Util/TypeUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
use Rekalogika\Mapper\TypeResolver\Implementation\TypeResolver;
use Symfony\Component\PropertyInfo\Type;

final class TypeUtil
final readonly class TypeUtil
{
private function __construct()
{
Expand Down
Loading