-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathCatBreedFactory.php
52 lines (45 loc) · 1.07 KB
/
CatBreedFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace Drupal\cat_api\Service;
use Drupal\cat_api\Model\CatBreed;
/**
* Class CatBreedFactory.
*
* @package Drupal\cat_api\Service
*/
class CatBreedFactory {
/**
* Create instance of CatBreed from the results of the CatApiClient.
*
* @param array $results
* Result array from an CatApiClient request.
*
* @return \Drupal\cat_api\Model\CatBreed
*/
public function createFromSearchResult(array $results) {
$breed = $results['breeds'][0];
return new CatBreed(
$breed['id'],
$breed['name'],
$breed['description'],
$breed['temperament'],
$results['url'] ?? ''
);
}
/**
* Create instance of CatBreed from the results of the CatApiClient.
*
* @param array $breed
* Result array from an CatApiClient request.
*
* @return \Drupal\cat_api\Model\CatBreed
*/
public function createFromBreedResult(array $breed) {
return new CatBreed(
$breed['id'],
$breed['name'],
$breed['description'],
$breed['temperament'],
$breed['image']['url'] ?? ''
);
}
}