Team   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A import() 0 17 3
1
<?php
2
3
4
namespace App\GameApi\Business\ApiFootballData\Import;
5
6
7
use App\GameApi\Business\ApiFootballData\ClientInterface;
8
use Doctrine\Common\Persistence\ManagerRegistry;
9
use Doctrine\ORM\EntityManager;
10
use App\GameCore\Persistence\Entity\Team as TeamEntity;
11
use Doctrine\ORM\EntityManagerInterface;
12
13
class Team implements TeamInterface
14
{
15
    /**
16
     * @var ClientInterface
17
     */
18
    private $client;
19
20
    /**
21
     * @var EntityManagerInterface
22
     */
23
    private $entityManager;
24
25
    /**
26
     * @param ClientInterface $client
27
     * @param EntityManagerInterface $entityManager
28
     */
29
    public function __construct(ClientInterface $client, EntityManagerInterface $entityManager)
30
    {
31
        $this->client = $client;
32
        $this->entityManager = $entityManager;
33
    }
34
35
36
    public function import() : void
37
    {
38
        $teams = $this->client->getTeams();
39
        $teamRepository = $this->entityManager->getRepository(TeamEntity::class);
40
        foreach ($teams['teams'] as $team) {
41
            $teamEntity = $teamRepository->findOneBy([
42
                'name' => $team['name']
43
            ]);
44
45
            if (!$teamEntity instanceof TeamEntity) {
46
                $teamEntity = new TeamEntity();
47
            }
48
            $teamEntity->setName($team['name']);
49
            $teamEntity->setImg($team['crestUrl']);
50
            $this->entityManager->persist($teamEntity);
51
        }
52
        $this->entityManager->flush();
53
    }
54
55
}