コード例 #1
0
 public function transform(Pokemon $pokemon)
 {
     $number = str_pad($pokemon->id, 3, '0', STR_PAD_LEFT);
     return ['number' => $number, 'name' => $pokemon->identifier, 'types' => $pokemon->types->map(function (Type $type) {
         return $type->identifier;
     }), 'sprite' => $number, 'type-defenses' => $this->efficacyComparator->getDefences($pokemon->types), 'stats' => $this->statRepository->getStatsFor($pokemon)];
 }
コード例 #2
0
 public function find()
 {
     if (Input::exists('search')) {
         $search = Input::get('search');
         $result = $this->pokemonRepository->findByPartialName($search);
         if (!$result) {
             return $this->blankSuccess();
         }
         $result = $this->pokemonTransformer->transform($result);
         return $this->success($result);
     } else {
         // instruct calculators to eager load
         $this->typeEfficacyComparator->preloadAllData();
         $this->statRepository->preloadStats();
         $result = $this->pokemonRepository->getAll()->map(function (Pokemon $pokemon) {
             return $this->pokemonTransformer->transform($pokemon);
         });
         return $this->success($result);
     }
 }