GetStreams   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 33
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 20 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ProjetNormandie\TwitchBundle\Controller\Stream;
6
7
use Doctrine\ORM\NonUniqueResultException;
8
use ProjetNormandie\TwitchBundle\DataProvider\TwitchItemDataProvider;
9
use ProjetNormandie\TwitchBundle\Model\Twitch\Stream;
10
use ProjetNormandie\TwitchBundle\Repository\ChannelRepository;
11
use ProjetNormandie\TwitchBundle\Serializer\SerializerRegistry;
12
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
13
14
class GetStreams extends AbstractController
15
{
16
17
    public function __construct(
18
        private readonly TwitchItemDataProvider $twitchItemDataProvider,
19
        private readonly ChannelRepository $channelRepository,
20
    ) {
21
    }
22
23
    /**
24
     * @return array
25
     * @throws NonUniqueResultException
26
     */
27
    public function __invoke(): array
28
    {
29
        $channels = $this->channelRepository->findAll();
30
31
        $streams = [];
32
        foreach ($channels as $channel) {
33
            $response = $this->twitchItemDataProvider->getStream($channel->getUsername());
34
            $data = json_decode($response->getBody()->getContents())->data;
35
            if (count($data) === 0) {
36
                continue;
37
            }
38
39
            $stream = $data[0];
40
            /*$serializer = SerializerRegistry::getSerializer();
41
            $serialized = $serializer->serialize($stream, 'json');
42
            $deserialized = $serializer->deserialize($serialized, Stream::class, 'json');*/
43
            $streams[] = $stream;
44
        }
45
46
        return $streams;
47
    }
48
}
49