Completed
Push — master ( d81c19...f57266 )
by Kamil
20s
created

AdminBundle/Controller/NotificationController.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
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 Sylius\Bundle\AdminBundle\Controller;
15
16
use GuzzleHttp\ClientInterface;
17
use GuzzleHttp\Exception\GuzzleException;
18
use GuzzleHttp\Psr7\Uri;
19
use Http\Message\MessageFactory;
20
use Psr\Http\Message\UriInterface;
21
use Sylius\Bundle\CoreBundle\Application\Kernel;
22
use Symfony\Component\HttpFoundation\JsonResponse;
23
use Symfony\Component\HttpFoundation\Request;
24
25
final class NotificationController
26
{
27
    /**
28
     * @var ClientInterface
29
     */
30
    private $client;
31
32
    /**
33
     * @var MessageFactory
34
     */
35
    private $messageFactory;
36
37
    /**
38
     * @var UriInterface
39
     */
40
    private $hubUri;
41
42
    /**
43
     * @var string
44
     */
45
    private $environment;
46
47
    /**
48
     * @param ClientInterface $client
49
     * @param MessageFactory $messageFactory
50
     * @param string $hubUri
51
     * @param string $environment
52
     */
53
    public function __construct(
54
        ClientInterface $client,
55
        MessageFactory $messageFactory,
56
        string $hubUri,
57
        string $environment
58
    ) {
59
        $this->client = $client;
60
        $this->messageFactory = $messageFactory;
61
        $this->hubUri = new Uri($hubUri);
0 ignored issues
show
Documentation Bug introduced by
It seems like new \GuzzleHttp\Psr7\Uri($hubUri) of type object<GuzzleHttp\Psr7\Uri> is incompatible with the declared type object<Psr\Http\Message\UriInterface> of property $hubUri.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
62
        $this->environment = $environment;
63
    }
64
65
    /**
66
     * @param Request $request
67
     *
68
     * @return JsonResponse
69
     */
70
    public function getVersionAction(Request $request): JsonResponse
71
    {
72
        $content = [
73
            'version' => Kernel::VERSION,
74
            'hostname' => $request->getHost(),
75
            'locale' => $request->getLocale(),
76
            'user_agent' => $request->headers->get('User-Agent'),
77
            'environment' => $this->environment,
78
        ];
79
80
        $headers = ['Content-Type' => 'application/json'];
81
82
        $hubRequest = $this->messageFactory->createRequest(
83
            Request::METHOD_GET,
84
            $this->hubUri,
85
            $headers,
86
            json_encode($content)
87
        );
88
89
        try {
90
            $hubResponse = $this->client->send($hubRequest, ['verify' => false]);
91
        } catch (GuzzleException $exception) {
92
            return JsonResponse::create('', JsonResponse::HTTP_NO_CONTENT);
93
        }
94
95
        $hubResponse = json_decode($hubResponse->getBody()->getContents(), true);
96
97
        return new JsonResponse($hubResponse);
98
    }
99
}
100