Completed
Push — master ( a9d592...d707cc )
by Jelle
09:44
created

SportProxy   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
wmc 10
lcom 2
cbo 4
dl 0
loc 64
ccs 12
cts 24
cp 0.5
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A loadLeagues() 0 8 2
A getId() 0 3 1
A getLeagues() 0 3 1
A getName() 0 3 1
A addLeague() 0 12 4
A load() 0 3 1
1
<?php
2
/**
3
 * @file
4
 * Contains \TheSportsDb\Entity\Proxy\SportProxy.
5
 */
6
7
namespace TheSportsDb\Entity\Proxy;
8
9
use TheSportsDb\Entity\LeagueInterface;
10
use TheSportsDb\Entity\SportInterface;
11
12
/**
13
 * A sport object that is not yet fully loaded.
14
 *
15
 * @author Jelle Sebreghts
16
 */
17
class SportProxy extends Proxy implements SportInterface {
18
19
  /**
20
   * {@inheritdoc}
21
   */
22
  public function load() {
23
    $this->loadLeagues();
24
  }
25
26
  /**
27
   * Lazy loads the leagues for this sport.
28
   *
29
   * @throws \Exception
30
   *   When the leagues cannot be loaded.
31
   *
32
   * @return void
33
   */
34
  protected function loadLeagues() {
35
    $leagueData = $this->sportsDbClient->doRequest('search_all_leagues.php', array('s' => $this->properties->id));
36
    if (isset($leagueData->countrys)) {
37
      $this->update($this->entityManager->mapProperties((object) array('leagues' => $leagueData->countrys), $this->getEntityType()));
38
      return;
39
    }
40
    throw new \Exception('Could not fully load sport with id ' . $this->properties->id . '.');
41
  }
42
43
  /**
44
   * {@inheritdoc}
45
   */
46 1
  public function getId() {
47 1
    return $this->get('id');
48
  }
49
50
  /**
51
   * {@inheritdoc}
52
   */
53 1
  public function getLeagues() {
54 1
    return $this->get('leagues');
55
  }
56
57
  /**
58
   * {@inheritdoc}
59
   */
60 1
  public function getName() {
61 1
    return $this->get('name');
62
  }
63
64
  /**
65
   * {@inheritdoc}
66
   */
67 1
  public function addLeague(LeagueInterface $league) {
68 1
    if ($this->entity) {
69
      $this->entity->addLeague($league);
70
      return;
71
    }
72 1
    if (!isset($this->properties->leagues)) {
73
      $this->properties->leagues = array();
74
    }
75 1
    if (!isset($this->properties->leagues[$league->getId()])) {
76 1
      $this->properties->leagues[$league->getId()] = $league;
77
    }
78 1
  }
79
80
}
81