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

varhall / restino / 8143456103

04 Mar 2024 04:17PM UTC coverage: 94.805% (-0.5%) from 95.276%
8143456103

push

github

feropeterko
cleanup old classes

365 of 385 relevant lines covered (94.81%)

0.95 hits per line

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

65.22
/src/Controllers/Action.php
1
<?php
2

3
namespace Varhall\Restino\Controllers;
4

5
use Nette\Http\IResponse;
6
use Varhall\Restino\Mapping\MappingService;
7
use Varhall\Restino\Results\IResult;
8
use Varhall\Restino\Results\Result;
9
use Varhall\Restino\Results\Termination;
10
use Varhall\Utilino\Mapping\Target;
11

12
class Action
13
{
14
    protected \ReflectionMethod $function;
15
    protected RestController $controller;
16
    protected MappingService $mapping;
17

18
    public function __construct(\ReflectionMethod $function, RestController $controller, MappingService $mapping)
1✔
19
    {
20
        $this->function = $function;
1✔
21
        $this->controller = $controller;
1✔
22
        $this->mapping = $mapping;
1✔
23
    }
1✔
24

25
    public function getName(): string
26
    {
27
        return $this->getFunction()->getName();
1✔
28
    }
29

30
    public function getFunction(): \ReflectionMethod
31
    {
32
        return $this->function;
1✔
33
    }
34

35
    public function invoke(RestRequest $request): IResult
1✔
36
    {
37
        $parameters = [];
1✔
38
        $errors = [];
1✔
39
        foreach ($this->function->getParameters() as $parameter) {
1✔
40
            try {
41
                $parameters[] = $this->mapping->process(new Target($parameter), $request);
1✔
42
            } catch (\Nette\Schema\ValidationException $ex) {
×
43
                $errors = array_merge($errors, $ex->getMessageObjects());
×
44
            }
45
        }
46

47
        // handle errors
48
        if (!empty($errors)) {
1✔
49
            $res = array_combine(
×
50
                array_map(fn($e) => implode('.', $e->path), $errors),
×
51
                array_map(fn($e) => $e->toString(), $errors)
×
52
            );
53

54
            $res['_action'] = $this->getName();
×
55
            $res['_controller'] = $request->getRequest()->getPresenterName();
×
56

57
            return new Termination($res, IResponse::S400_BadRequest);
×
58
        }
59

60
        // call controller action and create result from it
61
        return new Result($this->function->invokeArgs($this->controller, $parameters));
1✔
62
    }
63
}
1✔
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