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

SeasonProxy   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 44.44%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 4
dl 0
loc 56
ccs 8
cts 18
cp 0.4444
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A loadEvents() 0 9 2
A getId() 0 3 1
A getName() 0 3 1
A getEvents() 0 3 1
A getLeague() 0 3 1
A load() 0 3 1
1
<?php
2
/**
3
 * @file
4
 * Contains \TheSportsDb\Entity\Proxy\SeasonProxy.
5
 */
6
7
namespace TheSportsDb\Entity\Proxy;
8
9
use TheSportsDb\Entity\SeasonInterface;
10
11
/**
12
 * A season object that is not yet fully loaded.
13
 *
14
 * @author Jelle Sebreghts
15
 */
16
class SeasonProxy extends Proxy implements SeasonInterface {
17
18
  /**
19
   * {@inheritdoc}
20
   */
21
  public function load() {
22
    $this->loadEvents();
23
  }
24
25
  /**
26
   * Lazy loads the events for this season.
27
   *
28
   * @throws \Exception
29
   *   When the events cannot be loaded.
30
   *
31
   * @return void
32
   */
33
  protected function loadEvents() {
34
    $id = explode('|', $this->getId());
35
    $eventData = $this->sportsDbClient->doRequest('eventsseason.php', array('id' => $this->getLeague()->getId(), 's' => reset($id)));
36
    if (isset($eventData->events)) {
37
      $this->update($this->entityManager->mapProperties((object) array('events' => $eventData->events), $this->getEntityType()));
38
      return;
39
    }
40
    throw new \Exception('Could not fully load season with id ' . $this->getId() . '.');
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 getName() {
54 1
    return $this->get('name');
55
  }
56
57
  /**
58
   * {@inheritdoc}
59
   */
60 1
  public function getEvents() {
61 1
    return $this->get('events');
62
  }
63
64
  /**
65
   * {@inheritdoc}
66
   */
67 1
  public function getLeague() {
68 1
    return $this->get('league');
69
  }
70
71
}
72