Completed
Push — master ( a73180...86ff1d )
by Jelle
09:42
created

SeasonProxy::loadEvents()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.0116

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 6
cts 7
cp 0.8571
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 0
crap 2.0116
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 1
  public function load() {
22 1
    $this->loadEvents();
23 1
  }
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 1
  protected function loadEvents() {
34 1
    $id = explode('|', $this->getId());
35 1
    $eventData = $this->sportsDbClient->doRequest('eventsseason.php', array('id' => $this->getLeague()->getId(), 's' => reset($id)));
36 1
    if (isset($eventData->events)) {
37 1
      $this->update($this->entityManager->mapProperties((object) array('events' => $eventData->events), $this->getEntityType()));
38 1
      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