Skip to content

Commit

Permalink
chore: Add readonly or implement ResetInterface to applicable cla…
Browse files Browse the repository at this point in the history
…sses.
  • Loading branch information
priyadi committed Feb 22, 2024
1 parent 3023390 commit b51acf6
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 20 deletions.
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()

Check failure on line 33 in src/Debug/TraceableMappingFactory.php

View workflow job for this annotation

GitHub Actions / Symfony 6.4.*, lowest deps, PHP 8.2, ubuntu-latest

MissingReturnType

src/Debug/TraceableMappingFactory.php:33:21: MissingReturnType: Method Rekalogika\Mapper\Debug\TraceableMappingFactory::reset does not have a return type, expecting void (see https://psalm.dev/050)

Check failure on line 33 in src/Debug/TraceableMappingFactory.php

View workflow job for this annotation

GitHub Actions / Symfony 6.4.*, lowest deps, PHP 8.3, ubuntu-latest

MissingReturnType

src/Debug/TraceableMappingFactory.php:33:21: MissingReturnType: Method Rekalogika\Mapper\Debug\TraceableMappingFactory::reset does not have a return type, expecting void (see https://psalm.dev/050)
{
$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()

Check failure on line 55 in src/MainTransformer/Implementation/MainTransformer.php

View workflow job for this annotation

GitHub Actions / Symfony 6.4.*, lowest deps, PHP 8.2, ubuntu-latest

MissingReturnType

src/MainTransformer/Implementation/MainTransformer.php:55:21: MissingReturnType: Method Rekalogika\Mapper\MainTransformer\Implementation\MainTransformer::reset does not have a return type, expecting void (see https://psalm.dev/050)

Check failure on line 55 in src/MainTransformer/Implementation/MainTransformer.php

View workflow job for this annotation

GitHub Actions / Symfony 6.4.*, lowest deps, PHP 8.3, ubuntu-latest

MissingReturnType

src/MainTransformer/Implementation/MainTransformer.php:55:21: MissingReturnType: Method Rekalogika\Mapper\MainTransformer\Implementation\MainTransformer::reset does not have a return type, expecting void (see https://psalm.dev/050)
{
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

0 comments on commit b51acf6

Please sign in to comment.