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

strictlyPHP / dolphin / #9

18 May 2025 10:11PM UTC coverage: 88.889% (-11.1%) from 100.0%
#9

push

web-flow
add dependency injection and improve routing (#23)

* add dependency injection and improve routing

* add dto mapping and request injection

* add logging

* edit tests

* fixes

127 of 148 new or added lines in 4 files covered. (85.81%)

168 of 189 relevant lines covered (88.89%)

2.49 hits per line

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

86.67
/src/Strategy/DtoMapper.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace StrictlyPHP\Dolphin\Strategy;
6

7
use Exception;
8

9
class DtoMapper
10
{
11
    public function map(string $dtoClass, array $data): object
12
    {
13
        $refClass = new \ReflectionClass($dtoClass);
3✔
14
        $constructor = $refClass->getConstructor();
3✔
15

16
        if (! $constructor) {
3✔
NEW
17
            return new $dtoClass();
×
18
        }
19

20
        $args = [];
3✔
21

22
        foreach ($constructor->getParameters() as $param) {
3✔
23
            $name = $param->getName();
3✔
24
            $type = $param->getType();
3✔
25

26
            if ($type instanceof \ReflectionNamedType && ! $type->isBuiltin()) {
3✔
27
                // Recursive DTO
28
                $nestedClass = $type->getName();
3✔
29

30
                if (isset($data[$name]) && is_array($data[$name])) {
3✔
31
                    $args[] = $this->map($nestedClass, $data[$name]);
3✔
32
                } else {
NEW
33
                    throw new Exception(sprintf('parameter %s has no type', $name));
×
34
                }
35
            } else {
36
                $args[] = $data[$name] ?? null;
3✔
37
            }
38
        }
39

40
        return $refClass->newInstanceArgs($args);
3✔
41
    }
42
}
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