• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tempestphp / tempest-framework / 14049246919

24 Mar 2025 09:42PM UTC coverage: 79.353% (-0.04%) from 79.391%
14049246919

push

github

web-flow
feat(support): support array parameters in string manipulations (#1073)

48 of 48 new or added lines in 2 files covered. (100.0%)

735 existing lines in 126 files now uncovered.

10492 of 13222 relevant lines covered (79.35%)

90.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.75
/src/Tempest/Mapper/src/SerializerFactory.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\Mapper;
6

7
use Closure;
8
use Tempest\Reflection\PropertyReflector;
9

10
use function Tempest\get;
11

12
final class SerializerFactory
13
{
14
    /**
15
     * @var array{string|Closure, class-string<\Tempest\Mapper\Serializer>|Closure}[]
16
     */
17
    private array $serializers = [];
18

19
    /**
20
     * @param class-string<\Tempest\Mapper\Serializer> $serializerClass
21
     */
22
    public function addSerializer(string|Closure $for, string|Closure $serializerClass): self
130✔
23
    {
24
        $this->serializers = [[$for, $serializerClass], ...$this->serializers];
130✔
25

26
        return $this;
130✔
27
    }
28

29
    public function forProperty(PropertyReflector $property): ?Serializer
67✔
30
    {
31
        $type = $property->getType();
67✔
32

33
        // Get SerializerWith from the property
34
        $serializeWith = $property->getAttribute(SerializeWith::class);
67✔
35

36
        // Get SerializerWith from the property's type if there's no property-defined SerializerWith
37
        if ($serializeWith === null && $type->isClass()) {
67✔
38
            $serializeWith = $type->asClass()->getAttribute(SerializeWith::class, recursive: true);
28✔
39
        }
40

41
        // Return the serializer if defined with SerializerWith
42
        if ($serializeWith !== null) {
67✔
43
            // Resolve the serializer from the container
44
            return get($serializeWith->className);
2✔
45
        }
46

47
        // Resolve serializer from manual additions
48
        foreach ($this->serializers as [$for, $serializerClass]) {
67✔
49
            if (is_callable($for) && $for($property) || is_string($for) && $type->matches($for) || $type->getName() === $for) {
67✔
50
                return is_callable($serializerClass)
67✔
51
                    ? $serializerClass($property)
4✔
52
                    : get($serializerClass);
67✔
53
            }
54
        }
55

UNCOV
56
        return null;
×
57
    }
58
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc