doyolabs /
code-coverage-bridge
| 1 | <?php |
||
| 2 | |||
| 3 | /* |
||
| 4 | * This file is part of the doyo/code-coverage project. |
||
| 5 | * |
||
| 6 | * (c) Anthonius Munthi <[email protected]> |
||
| 7 | * |
||
| 8 | * For the full copyright and license information, please view the LICENSE |
||
| 9 | * file that was distributed with this source code. |
||
| 10 | */ |
||
| 11 | |||
| 12 | declare(strict_types=1); |
||
| 13 | |||
| 14 | namespace Doyo\Bridge\CodeCoverage\Controller; |
||
| 15 | |||
| 16 | use Doyo\Bridge\CodeCoverage\Session\RemoteSession; |
||
| 17 | use Symfony\Component\HttpFoundation\JsonResponse; |
||
|
0 ignored issues
–
show
|
|||
| 18 | use Symfony\Component\HttpFoundation\Request; |
||
|
0 ignored issues
–
show
The type
Symfony\Component\HttpFoundation\Request was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 19 | use Symfony\Component\HttpFoundation\Response; |
||
|
0 ignored issues
–
show
The type
Symfony\Component\HttpFoundation\Response was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 20 | |||
| 21 | class RemoteController |
||
| 22 | { |
||
| 23 | const SERIALIZED_OBJECT_CONTENT_TYPE = 'application/php-serialized-object'; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @return static |
||
| 27 | */ |
||
| 28 | public static function create() |
||
| 29 | { |
||
| 30 | return new static(); |
||
| 31 | } |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @return Response |
||
| 35 | */ |
||
| 36 | public function getResponse() |
||
| 37 | { |
||
| 38 | $request = Request::createFromGlobals(); |
||
| 39 | $action = $request->get('action').'Action'; |
||
| 40 | $callable = [$this, $action]; |
||
| 41 | |||
| 42 | if (!method_exists($this, $action)) { |
||
| 43 | $callable = [$this, 'notFoundAction']; |
||
| 44 | } |
||
| 45 | |||
| 46 | return \call_user_func_array($callable, [$request]); |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @return JsonResponse |
||
| 51 | */ |
||
| 52 | public function notFoundAction() |
||
| 53 | { |
||
| 54 | $data = [ |
||
| 55 | 'message' => 'The page you requested is not exists', |
||
| 56 | ]; |
||
| 57 | |||
| 58 | return new JsonResponse($data, 404); |
||
| 59 | } |
||
| 60 | |||
| 61 | public function unsupportedMethodAction(Request $request, $supportedMethod) |
||
| 62 | { |
||
| 63 | $data = [ |
||
| 64 | 'message' => sprintf( |
||
| 65 | 'action: %s not support method: %s. Supported method: %s', |
||
| 66 | $request->get('action'), |
||
| 67 | $request->getMethod(), |
||
| 68 | $supportedMethod |
||
| 69 | ), |
||
| 70 | ]; |
||
| 71 | |||
| 72 | return new JsonResponse($data, Response::HTTP_METHOD_NOT_ALLOWED); |
||
| 73 | } |
||
| 74 | |||
| 75 | public function initAction(Request $request) |
||
| 76 | { |
||
| 77 | if (!$request->isMethod(Request::METHOD_POST)) { |
||
| 78 | return $this->unsupportedMethodAction($request, 'POST'); |
||
| 79 | } |
||
| 80 | $name = $request->get('session'); |
||
| 81 | $config = $request->getContent(); |
||
| 82 | $config = json_decode($config, true); |
||
| 83 | |||
| 84 | $session = new RemoteSession($name); |
||
| 85 | $session->init($config); |
||
| 86 | |||
| 87 | $data = [ |
||
| 88 | 'message' => 'coverage session: '.$name.' initialized.', |
||
| 89 | ]; |
||
| 90 | |||
| 91 | return new JsonResponse($data, Response::HTTP_ACCEPTED); |
||
| 92 | } |
||
| 93 | |||
| 94 | public function readAction(Request $request) |
||
| 95 | { |
||
| 96 | if (!$request->isMethod(Request::METHOD_GET)) { |
||
| 97 | return $this->unsupportedMethodAction($request, Request::METHOD_GET); |
||
| 98 | } |
||
| 99 | |||
| 100 | if (!$request->get('session')) { |
||
| 101 | $data = [ |
||
| 102 | 'message' => 'code coverage session not exists', |
||
| 103 | ]; |
||
| 104 | |||
| 105 | return new JsonResponse($data, Response::HTTP_NOT_FOUND); |
||
| 106 | } |
||
| 107 | $session = $request->get('session'); |
||
| 108 | $session = new RemoteSession($session); |
||
| 109 | $data = serialize($session); |
||
| 110 | |||
| 111 | if (null === $session->getProcessor()) { |
||
| 112 | $data = [ |
||
| 113 | 'message' => 'Session '.$session->getName().' is not initialized.', |
||
| 114 | ]; |
||
| 115 | |||
| 116 | return new JsonResponse($data, Response::HTTP_NOT_FOUND); |
||
| 117 | } |
||
| 118 | |||
| 119 | $response = new Response($data, Response::HTTP_OK); |
||
| 120 | $response->headers->set('Content-Type', static::SERIALIZED_OBJECT_CONTENT_TYPE); |
||
| 121 | |||
| 122 | return $response; |
||
| 123 | } |
||
| 124 | } |
||
| 125 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths