YumlController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 31
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A indexAction() 0 15 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DoctrineORMModule\Yuml;
6
7
use Laminas\Http\Client;
8
use Laminas\Http\Request;
9
use Laminas\Http\Response;
10
use Laminas\Mvc\Controller\AbstractActionController;
11
use UnexpectedValueException;
12
13
/**
14
 * Utility to generate Yuml compatible strings from metadata graphs
15
 */
16
class YumlController extends AbstractActionController
17
{
18
    /** @var Client */
19
    protected $httpClient;
20
21 1
    public function __construct(Client $httpClient)
22
    {
23 1
        $this->httpClient = $httpClient;
24 1
    }
25
26
    /**
27
     * Redirects the user to a YUML graph drawn with the provided `dsl_text`
28
     *
29
     * @throws UnexpectedValueException if the YUML service answered incorrectly.
30
     */
31 2
    public function indexAction() : Response
32
    {
33 2
        $request = $this->getRequest();
34 2
        $this->httpClient->setMethod(Request::METHOD_POST);
35 2
        $this->httpClient->setParameterPost(['dsl_text' => $request->getPost('dsl_text')]);
36 2
        $response = $this->httpClient->send();
37
38 2
        if (! $response->isSuccess()) {
39 1
            throw new UnexpectedValueException('HTTP Request failed');
40
        }
41
42 1
        $redirect = $this->plugin('redirect');
43
44 1
        return $redirect->toUrl('https://yuml.me/' . $response->getBody());
0 ignored issues
show
Bug introduced by
The method toUrl() does not seem to exist on object<Laminas\Stdlib\DispatchableInterface>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
45
    }
46
}
47