修改理由:

代码内容不符

相关信息:


此投稿已在 5年前 合并。

内容修改:

红色背景 为原始内容

绿色背景 为新增或者修改的内容

OldNewDifferences
6767
6868```php
6969<?php
70 namespace Overtrue\Weather\Tests;
71 
72 use GuzzleHttp\Client;
73 use GuzzleHttp\ClientInterface;
74 use GuzzleHttp\Psr7\Response;
75 use Mockery\Matcher\AnyArgs;
76 use Overtrue\Weather\Exceptions\HttpException;
77 use Overtrue\Weather\Exceptions\InvalidArgumentException;
78 use Overtrue\Weather\Weather;
79 use PHPUnit\Framework\TestCase;
80 
81 class WeatherTest extends TestCase
 70namespace Overtrue\Weather;
 71
 72use GuzzleHttp\Client;
 73use Overtrue\Weather\Exceptions\HttpException;
 74use Overtrue\Weather\Exceptions\InvalidArgumentException;
 75
 76class Weather
8277{
8378   .
8479   .
8580   .
86    public function getWeather($city, $type = 'base', $format = 'json')
 81   public function getWeather($city, string $type = 'base', string $format = 'json')
8782   {
8883       $url = 'https://restapi.amap.com/v3/weather/weatherInfo';
8984
9085       // 1. 对 `$format` 与 `$extensions` 参数进行检查,不在范围内的抛出异常。
91        if (!\in_array($format, ['xml', 'json'])) {
 86       if (!\in_array(\strtolower($format), ['xml', 'json'])) {
9287           throw new InvalidArgumentException('Invalid response format: '. $format);
9388       }
9489
9590       if (!\in_array(\strtolower($type), ['base', 'all'])) {
96            throw new InvalidArgumentException('Invalid type value(base/all): '.$type);
 91           throw new InvalidArgumentException('Invalid type value(base/all): '. $type);
9792       }
9893
9994       // 2. 封装 query 参数,并对空值进行过滤。