• 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

95.83
/src/Tempest/Mapper/src/Mappers/ObjectToArrayMapper.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\Mapper\Mappers;
6

7
use JsonSerializable;
8
use Tempest\Mapper\Mapper;
9
use Tempest\Mapper\MapTo;
10
use Tempest\Mapper\SerializerFactory;
11
use Tempest\Reflection\ClassReflector;
12
use Tempest\Reflection\PropertyReflector;
13

14
final readonly class ObjectToArrayMapper implements Mapper
15
{
16
    public function __construct(
129✔
17
        private SerializerFactory $serializerFactory,
18
    ) {}
129✔
19

20
    public function canMap(mixed $from, mixed $to): bool
122✔
21
    {
22
        return false;
122✔
23
    }
24

25
    public function map(mixed $from, mixed $to): array
7✔
26
    {
27
        if ($from instanceof JsonSerializable) {
7✔
28
            return $from->jsonSerialize();
1✔
29
        }
30

31
        $class = new ClassReflector($from);
6✔
32

33
        $mappedProperties = [];
6✔
34

35
        foreach ($class->getPublicProperties() as $property) {
6✔
36
            $propertyName = $this->resolvePropertyName($property);
6✔
37
            $propertyValue = $this->resolvePropertyValue($property, $from);
6✔
38
            $mappedProperties[$propertyName] = $propertyValue;
6✔
39
        }
40

41
        return $mappedProperties;
6✔
42
    }
43

44
    private function resolvePropertyValue(PropertyReflector $property, object $object): mixed
6✔
45
    {
46
        $propertyValue = $property->getValue($object);
6✔
47

48
        if (($serializer = $this->serializerFactory->forProperty($property)) !== null) {
6✔
49
            return $serializer->serialize($propertyValue);
6✔
50
        }
51

UNCOV
52
        return $propertyValue;
×
53
    }
54

55
    private function resolvePropertyName(PropertyReflector $property): string
6✔
56
    {
57
        $mapTo = $property->getAttribute(MapTo::class);
6✔
58

59
        if ($mapTo !== null) {
6✔
60
            return $mapTo->name;
2✔
61
        }
62

63
        return $property->getName();
5✔
64
    }
65
}
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