GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 48ef9d...490df9 )
by Christian
01:26
created

src/Service/CityService.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * (c) Christian Gripp <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Core23\SetlistFm\Service;
13
14
use Core23\SetlistFm\Exception\ApiException;
15
use Core23\SetlistFm\Exception\NotFoundException;
16
use Core23\SetlistFm\Model\City;
17
18 View Code Duplication
final class CityService extends AbstractService
0 ignored issues
show
This class 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...
19
{
20
    /**
21
     * Get the city data for an id.
22
     *
23
     * @param int $cityId
24
     *
25
     * @throws ApiException
26
     * @throws NotFoundException
27
     *
28
     * @return City
29
     */
30
    public function getCity(int $cityId): City
31
    {
32
        return City::fromApi(
33
            $this->call('city/'.$cityId)
34
        );
35
    }
36
37
    /**
38
     * Search for cities. Returns cities sorted by relevance.
39
     *
40
     * @param array $fields
41
     * @param int   $page
42
     *
43
     * @throws ApiException
44
     * @throws NotFoundException
45
     *
46
     * @return City[]
47
     */
48
    public function search(array $fields, int $page = 1): array
49
    {
50
        $response = $this->call('search/cities', array_merge($fields, [
51
            'p' => $page,
52
        ]));
53
54
        if (!\array_key_exists('cities', $response)) {
55
            return [];
56
        }
57
58
        return array_map(function ($data) {
59
            return City::fromApi($data);
60
        }, $response['cities']);
61
    }
62
}
63