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

tempestphp / tempest-framework / 11647196989

02 Nov 2024 07:57PM UTC coverage: 82.594% (+0.3%) from 82.286%
11647196989

push

github

web-flow
feat: route enum binding support (#668)

29 of 30 new or added lines in 3 files covered. (96.67%)

4 existing lines in 1 file now uncovered.

7127 of 8629 relevant lines covered (82.59%)

46.49 hits per line

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

92.31
/src/Tempest/Http/src/RouteModelBindingInitializer.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\Http;
6

7
use Tempest\Container\Container;
8
use Tempest\Container\DynamicInitializer;
9
use Tempest\Database\DatabaseModel;
10
use Tempest\Database\Id;
11
use Tempest\Http\Exceptions\NotFoundException;
12
use Tempest\Reflection\ClassReflector;
13

14
final class RouteModelBindingInitializer implements DynamicInitializer
15
{
16
    public function canInitialize(ClassReflector $class): bool
326✔
17
    {
18
        return $class->getType()->matches(DatabaseModel::class);
326✔
19
    }
20

21
    public function initialize(ClassReflector $class, Container $container): object
1✔
22
    {
23
        $matchedRoute = $container->get(MatchedRoute::class);
1✔
24

25
        $parameter = null;
1✔
26

27
        foreach ($matchedRoute->route->handler->getParameters() as $searchParameter) {
1✔
28
            if ($searchParameter->getType()->equals($class->getType())) {
1✔
29
                $parameter = $searchParameter;
1✔
30

31
                break;
1✔
32
            }
33
        }
34

35
        $model = $class->callStatic('find', new Id($matchedRoute->params[$parameter->getName()]));
1✔
36

37
        if ($model === null) {
1✔
NEW
38
            throw new NotFoundException();
×
39
        }
40

41
        return $model;
1✔
42
    }
43
}
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