Skip to content

Commit

Permalink
Player->fixNameIfCached()
Browse files Browse the repository at this point in the history
  • Loading branch information
villermen committed Feb 4, 2018
1 parent 525428b commit fad44ef
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/Player.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,27 @@ public function __construct(string $name, PlayerDataFetcher $dataFetcher = null)
*
* @return Player
*/
public function fixName()
public function fixName(): Player
{
$this->name = $this->getDataFetcher()->fetchRealName($this->getName());

return $this;
}

/** @noinspection PhpDocMissingThrowsInspection */
/**
* @return Player
*/
public function fixNameIfCached(): Player
{
if ($this->getDataFetcher()->getCachedRealName($this->getName())) {
/** @noinspection PhpUnhandledExceptionInspection */
$this->fixName();
}

return $this;
}

/**
* @return SkillHighScore
* @throws FetchFailedException
Expand Down
2 changes: 1 addition & 1 deletion test/PlayerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function testDataFetchingAndCaching()
self::assertSame($oldSchoolActivityHighScore, $this->player->getOldSchoolActivityHighScore());
self::assertGreaterThanOrEqual(0, $oldSchoolActivityHighScore->getActivity(Activity::ACTIVITY_OLD_SCHOOL_MASTER_CLUE_SCROLLS)->getScore());

$this->player->fixName();
$this->player->fixNameIfCached();
self::assertEquals("Excl", $this->player->getName());
}

Expand Down

0 comments on commit fad44ef

Please sign in to comment.