Skip to content

Commit

Permalink
Removed a method in order to be consistent with the rest of the appli…
Browse files Browse the repository at this point in the history
…cation codebase, and also added comments for the achievement parsing service.
  • Loading branch information
petrepatrasc committed Mar 19, 2014
1 parent 43ae807 commit 4ae16a6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
10 changes: 0 additions & 10 deletions Entity/Player/Achievements.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,4 @@ public function getPoints()
{
return $this->points;
}

/**
* @param Entity\Achievement $achievement
* @return $this
*/
public function addAchievements(Entity\Achievement $achievement)
{
$this->achievements[] = $achievement;
return $this;
}
}
42 changes: 36 additions & 6 deletions Service/Parsing/AchievementParsingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,40 @@
use petrepatrasc\BlizzardApiBundle\Entity\Achievement;
use petrepatrasc\BlizzardApiBundle\Entity\Player\Achievements;

/**
* Handles parsing achievements from API data.
* @package petrepatrasc\BlizzardApiBundle\Service\Parsing
*/
class AchievementParsingService implements ParsingInterfaceStandalone
{

/**
* Extract achievement information from an array.
*
* @param array $params
* @param array $params The parameters with the API response where the data should be extracted from.
* @return Achievements
*/
public static function extract($params)
{
$points = new Points();
$points->setTotalPoints($params['points']['totalPoints'])
->setCategoryPoints($params['points']['categoryPoints']);
$points = self::extractAchievementPointsData($params);

$achievementsWrapper = self::extractAchievementEntitiesData($params);

$achievements = new Achievements();
$achievements->setPoints($points);
$achievements->setAchievements($achievementsWrapper);
return $achievements;
}

/**
* Extract an array of achievement Entities from the API data.
*
* @param array $params The parameters with the API response where the data should be extracted from.
* @return array
*/
public static function extractAchievementEntitiesData($params)
{
$achievementsWrapper = array();
foreach ($params['achievements'] as $achievementEntry) {
$completionDate = new \DateTime();
$completionDate->setTimestamp($achievementEntry['completionDate']);
Expand All @@ -33,8 +49,22 @@ public static function extract($params)
$achievementEntity->setAchievementId($achievementEntry['achievementId'])
->setCompletionDate($completionDate);

$achievements->addAchievements($achievementEntity);
$achievementsWrapper[] = $achievementEntity;
}
return $achievements;
return $achievementsWrapper;
}

/**
* Extract achievement points from the API response.
*
* @param array $params The parameters with the API response where the data should be extracted from.
* @return Points
*/
public static function extractAchievementPointsData($params)
{
$points = new Points();
$points->setTotalPoints($params['points']['totalPoints'])
->setCategoryPoints($params['points']['categoryPoints']);
return $points;
}
}

0 comments on commit 4ae16a6

Please sign in to comment.