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

ICanBoogie / bind-routing / 4495689867

pending completion
4495689867

push

github

Olivier Laviale
Add Route attributes

62 of 62 new or added lines in 8 files covered. (100.0%)

77 of 126 relevant lines covered (61.11%)

0.62 hits per line

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

77.78
/lib/ConfigBuilder.php
1
<?php
2

3
namespace ICanBoogie\Binding\Routing;
4

5
use ICanBoogie\Binding\Routing\Attribute\Delete;
6
use ICanBoogie\Binding\Routing\Attribute\Get;
7
use ICanBoogie\Binding\Routing\Attribute\Post;
8
use ICanBoogie\Binding\Routing\Attribute\Put;
9
use ICanBoogie\Binding\Routing\Attribute\Route;
10
use ICanBoogie\Config\Builder;
11
use ICanBoogie\Routing\RouteCollector;
12
use ICanBoogie\Routing\RouteProvider;
13
use LogicException;
14
use olvlvl\ComposerAttributeCollector\Attributes;
15

16
use function class_exists;
17
use function sprintf;
18

19
/**
20
 * A config builder for 'routes' fragments.
21
 *
22
 * @implements Builder<RouteProvider>
23
 */
24
final class ConfigBuilder extends RouteCollector implements Builder
25
{
26
    public static function get_fragment_filename(): string
27
    {
28
        return 'routes';
1✔
29
    }
30

31
    public function build(): RouteProvider
32
    {
33
        return $this->collect();
2✔
34
    }
35

36
    /**
37
     * Builds configuration from the {@link Route} attribute.
38
     *
39
     * @return $this
40
     */
41
    public function from_attributes(): self
42
    {
43
        if (!class_exists(Attributes::class)) {
1✔
44
            throw new LogicException(
×
45
                sprintf(
×
46
                    "Unable to build from attributes, the class %s is not available",
×
47
                    Attributes::class
×
48
                )
×
49
            );
×
50
        }
51

52
        $target_methods = [
1✔
53
            ...Attributes::findTargetMethods(Get::class),
1✔
54
            ...Attributes::findTargetMethods(Post::class),
1✔
55
            ...Attributes::findTargetMethods(Put::class),
1✔
56
            ...Attributes::findTargetMethods(Delete::class),
1✔
57
            ...Attributes::findTargetMethods(Route::class),
1✔
58
        ];
1✔
59

60
        foreach ($target_methods as $method) {
1✔
61
            /** @var Route $attribute */
62
            $attribute = $method->attribute;
1✔
63
            $action = $attribute->action
1✔
64
                ?? ActionResolver::resolve_action($method->class, $method->name);
1✔
65

66
            $this->route(
1✔
67
                pattern: $attribute->pattern,
1✔
68
                action:  $action,
1✔
69
                methods:  $attribute->methods,
1✔
70
                id:  $attribute->id
1✔
71
            );
1✔
72
        }
73

74
        return $this;
1✔
75
    }
76
}
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