SportProxy::getId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 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 1
  public function load() {
23 1
    $this->loadLeagues();
24 1
  }
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 1 View Code Duplication
  protected function loadLeagues() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35 1
    $leagueData = $this->sportsDbClient->doRequest('search_all_leagues.php', array('s' => $this->properties->id));
36 1
    if (isset($leagueData->countrys)) {
37 1
      $this->update($this->entityManager->mapProperties((object) array('leagues' => $leagueData->countrys), $this->getEntityType()));
38 1
      return;
39
    }
40 1
    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