diff --git a/data/migrations/Version20180913205455.php b/data/migrations/Version20180913205455.php index 0b2b60d9..5de96361 100644 --- a/data/migrations/Version20180913205455.php +++ b/data/migrations/Version20180913205455.php @@ -7,8 +7,8 @@ use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; use PDO; +use Shlinkio\Shlink\Common\Exception\InvalidArgumentException; use Shlinkio\Shlink\Common\Util\IpAddress; -use Shlinkio\Shlink\IpGeolocation\Exception\WrongIpException; /** * Auto-generated Migration: Please modify to your needs! @@ -60,7 +60,7 @@ final class Version20180913205455 extends AbstractMigration try { return (string) IpAddress::fromString($addr)->getObfuscatedCopy(); - } catch (WrongIpException $e) { + } catch (InvalidArgumentException $e) { return null; } } diff --git a/module/Common/src/Util/IpAddress.php b/module/Common/src/Util/IpAddress.php index c237cd15..a71bac14 100644 --- a/module/Common/src/Util/IpAddress.php +++ b/module/Common/src/Util/IpAddress.php @@ -3,11 +3,12 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Common\Util; -use Shlinkio\Shlink\IpGeolocation\Exception\WrongIpException; +use Shlinkio\Shlink\Common\Exception\InvalidArgumentException; use function count; use function explode; use function implode; +use function sprintf; use function trim; final class IpAddress @@ -36,14 +37,14 @@ final class IpAddress /** * @param string $address * @return IpAddress - * @throws WrongIpException + * @throws InvalidArgumentException */ public static function fromString(string $address): self { $address = trim($address); $parts = explode('.', $address); if (count($parts) !== self::IPV4_PARTS_COUNT) { - throw WrongIpException::fromIpAddress($address); + throw new InvalidArgumentException(sprintf('Provided IP "%s" is invalid', $address)); } return new self(...$parts); diff --git a/module/Common/test-db/ApiTest/ApiTestCase.php b/module/Common/test-db/ApiTest/ApiTestCase.php index 1c6e3d0d..160ed2cc 100644 --- a/module/Common/test-db/ApiTest/ApiTestCase.php +++ b/module/Common/test-db/ApiTest/ApiTestCase.php @@ -9,7 +9,6 @@ use GuzzleHttp\ClientInterface; use GuzzleHttp\RequestOptions; use PHPUnit\Framework\TestCase; use Psr\Http\Message\ResponseInterface; -use Shlinkio\Shlink\Rest\Authentication\Plugin\ApiKeyHeaderPlugin; use function Shlinkio\Shlink\Common\json_decode; use function sprintf; @@ -48,7 +47,7 @@ abstract class ApiTestCase extends TestCase implements StatusCodeInterface, Requ protected function callApiWithKey(string $method, string $uri, array $options = []): ResponseInterface { $headers = $options[RequestOptions::HEADERS] ?? []; - $headers[ApiKeyHeaderPlugin::HEADER_NAME] = 'valid_api_key'; + $headers['X-Api-Key'] = 'valid_api_key'; $options[RequestOptions::HEADERS] = $headers; return $this->callApi($method, $uri, $options); diff --git a/module/Core/src/Entity/Visit.php b/module/Core/src/Entity/Visit.php index a6e87bad..f035f2ae 100644 --- a/module/Core/src/Entity/Visit.php +++ b/module/Core/src/Entity/Visit.php @@ -6,11 +6,11 @@ namespace Shlinkio\Shlink\Core\Entity; use Cake\Chronos\Chronos; use JsonSerializable; use Shlinkio\Shlink\Common\Entity\AbstractEntity; +use Shlinkio\Shlink\Common\Exception\InvalidArgumentException; use Shlinkio\Shlink\Common\Util\IpAddress; use Shlinkio\Shlink\Core\Model\Visitor; use Shlinkio\Shlink\Core\Visit\Model\UnknownVisitLocation; use Shlinkio\Shlink\Core\Visit\Model\VisitLocationInterface; -use Shlinkio\Shlink\IpGeolocation\Exception\WrongIpException; class Visit extends AbstractEntity implements JsonSerializable { @@ -45,7 +45,7 @@ class Visit extends AbstractEntity implements JsonSerializable try { return (string) IpAddress::fromString($address)->getObfuscatedCopy(); - } catch (WrongIpException $e) { + } catch (InvalidArgumentException $e) { return null; } } diff --git a/module/Rest/test-api/Action/OptionsRequestTest.php b/module/Rest/test-api/Action/OptionsRequestTest.php index 121e9328..1be10ee0 100644 --- a/module/Rest/test-api/Action/OptionsRequestTest.php +++ b/module/Rest/test-api/Action/OptionsRequestTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace ShlinkioApiTest\Shlink\Rest\Action; use ShlinkioTest\Shlink\Common\ApiTest\ApiTestCase; + use function explode; class OptionsRequestTest extends ApiTestCase