SportProxy   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 64
Duplicated Lines 12.5 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 87.5%

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 3 1
A loadLeagues() 8 8 2
A getId() 0 3 1
A getLeagues() 0 3 1
A getName() 0 3 1
A addLeague() 0 12 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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