Skip to content

Commit

Permalink
psr12 code style compliance
Browse files Browse the repository at this point in the history
  • Loading branch information
dannyvankooten committed Oct 9, 2023
1 parent 5c308b2 commit cb82086
Show file tree
Hide file tree
Showing 16 changed files with 29 additions and 34 deletions.
2 changes: 1 addition & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<ruleset name="rules">
<description>rules</description>
<rule ref="PSR2"/>
<rule ref="PSR12"/>
<file>tests/</file>
<file>src/</file>
<arg name="colors"/>
Expand Down
3 changes: 1 addition & 2 deletions src/Clients/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

interface Client
{

/**
* This method should return an associative array in the following format:
*
Expand All @@ -18,5 +17,5 @@ interface Client
* @return array
* @throws ClientException
*/
public function fetch() : array;
public function fetch(): array;
}
5 changes: 3 additions & 2 deletions src/Clients/IbericodeVatRatesClient.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Ibericode\Vat\Clients;
Expand All @@ -12,7 +13,7 @@ class IbericodeVatRatesClient implements Client
*
* @return array
*/
public function fetch() : array
public function fetch(): array
{
$url = 'https://raw.githubusercontent.com/ibericode/vat-rates/master/vat-rates.json';

Expand All @@ -33,7 +34,7 @@ public function fetch() : array
return $this->parseResponse($body);
}

private function parseResponse(string $response_body) : array
private function parseResponse(string $response_body): array
{
$result = json_decode($response_body, false);

Expand Down
7 changes: 4 additions & 3 deletions src/Countries.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Ibericode\Vat;
Expand Down Expand Up @@ -274,15 +275,15 @@ class Countries implements \Iterator, \ArrayAccess
* @param string $code
* @return bool
*/
public function hasCountryCode(string $code) : bool
public function hasCountryCode(string $code): bool
{
return $this->offsetExists($code);
}

/**
* @return array
*/
public function getCountryCodesInEU() : array
public function getCountryCodesInEU(): array
{
return ['AT', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', 'GR', 'HU', 'HR', 'IE', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'PL', 'PT', 'RO', 'SE', 'SI', 'SK'];
}
Expand All @@ -291,7 +292,7 @@ public function getCountryCodesInEU() : array
* @param string $code
* @return bool
*/
public function isCountryCodeInEU(string $code) : bool
public function isCountryCodeInEU(string $code): bool
{
return in_array($code, $this->getCountryCodesInEU(), true);
}
Expand Down
3 changes: 1 addition & 2 deletions src/Geolocation/GeolocatorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

interface GeolocatorInterface
{

/**
* @param string $ipAddress The IP address to geolocate
* @return string A ISO-3166-1-alpha2 country code or an empty string on failure
*/
public function locateIpAddress(string $ipAddress) : string;
public function locateIpAddress(string $ipAddress): string;
}
3 changes: 1 addition & 2 deletions src/Geolocation/IP2C.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@
*/
class IP2C implements GeolocatorInterface
{

/**
* @param string $ipAddress
* @return string
*/
public function locateIpAddress(string $ipAddress) : string
public function locateIpAddress(string $ipAddress): string
{
if ($ipAddress === '') {
return '';
Expand Down
2 changes: 1 addition & 1 deletion src/Geolocation/IP2Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class IP2Country implements GeolocatorInterface
* @param string $ipAddress
* @return string
*/
public function locateIpAddress(string $ipAddress) : string
public function locateIpAddress(string $ipAddress): string
{
if ($ipAddress === '') {
return '';
Expand Down
2 changes: 1 addition & 1 deletion src/Geolocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(string $service = 'ip2c.org')
$this->service = new $this->services[$service]();
}

public function locateIpAddress(string $ipAddress) : string
public function locateIpAddress(string $ipAddress): string
{
if ($ipAddress === '') {
return '';
Expand Down
4 changes: 2 additions & 2 deletions src/Period.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public function __construct(DateTimeInterface $effectiveFrom, array $rates)
$this->rates = $rates;
}

public function getEffectiveFrom() : DateTimeInterface
public function getEffectiveFrom(): DateTimeInterface
{
return $this->effectiveFrom;
}

public function getRate(string $level) : float
public function getRate(string $level): float
{
if (!isset($this->rates[$level])) {
throw new InvalidArgumentException("Invalid rate level: {$level}");
Expand Down
8 changes: 4 additions & 4 deletions src/Rates.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

declare(strict_types=1);

namespace Ibericode\Vat;

use DateTime;
use DateTimeInterface;
use DateTimeImmutable;

use Ibericode\Vat\Clients\ClientException;
use Ibericode\Vat\Clients\IbericodeVatRatesClient;
use Ibericode\Vat\Clients\Client;
Expand Down Expand Up @@ -110,7 +110,7 @@ private function loadFromRemote()
}
}

private function resolvePeriod(string $countryCode, DateTimeInterface $datetime) : Period
private function resolvePeriod(string $countryCode, DateTimeInterface $datetime): Period
{
$this->load();

Expand All @@ -135,7 +135,7 @@ private function resolvePeriod(string $countryCode, DateTimeInterface $datetime)
* @return float
* @throws \Exception
*/
public function getRateForCountry(string $countryCode, string $level = self::RATE_STANDARD) : float
public function getRateForCountry(string $countryCode, string $level = self::RATE_STANDARD): float
{
$todayMidnight = new \DateTimeImmutable('today midnight');
return $this->getRateForCountryOnDate($countryCode, $todayMidnight, $level);
Expand All @@ -148,7 +148,7 @@ public function getRateForCountry(string $countryCode, string $level = self::RAT
* @return float
* @throws Exception
*/
public function getRateForCountryOnDate(string $countryCode, \DateTimeInterface $datetime, string $level = self::RATE_STANDARD) : float
public function getRateForCountryOnDate(string $countryCode, \DateTimeInterface $datetime, string $level = self::RATE_STANDARD): float
{
$activePeriod = $this->resolvePeriod($countryCode, $datetime);
return $activePeriod->getRate($level);
Expand Down
12 changes: 6 additions & 6 deletions src/Validator.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

declare(strict_types=1);

namespace Ibericode\Vat;

class Validator
{

/**
* Regular expression patterns per country code
*
Expand Down Expand Up @@ -66,7 +66,7 @@ public function __construct(Vies\Client $client = null)
* @param string $countryCode
* @return bool
*/
public function validateCountryCode(string $countryCode) : bool
public function validateCountryCode(string $countryCode): bool
{
$countries = new Countries();
return isset($countries[$countryCode]);
Expand All @@ -78,7 +78,7 @@ public function validateCountryCode(string $countryCode) : bool
* @param string $ipAddress
* @return bool
*/
public function validateIpAddress(string $ipAddress) : bool
public function validateIpAddress(string $ipAddress): bool
{
if ($ipAddress === '') {
return false;
Expand All @@ -94,7 +94,7 @@ public function validateIpAddress(string $ipAddress) : bool
*
* @return boolean
*/
public function validateVatNumberFormat(string $vatNumber) : bool
public function validateVatNumberFormat(string $vatNumber): bool
{
if ($vatNumber === '') {
return false;
Expand All @@ -119,7 +119,7 @@ public function validateVatNumberFormat(string $vatNumber) : bool
*
* @throws Vies\ViesException
*/
protected function validateVatNumberExistence(string $vatNumber) : bool
protected function validateVatNumberExistence(string $vatNumber): bool
{
$vatNumber = strtoupper($vatNumber);
$country = substr($vatNumber, 0, 2);
Expand All @@ -136,7 +136,7 @@ protected function validateVatNumberExistence(string $vatNumber) : bool
*
* @throws Vies\ViesException
*/
public function validateVatNumber(string $vatNumber) : bool
public function validateVatNumber(string $vatNumber): bool
{
return $this->validateVatNumberFormat($vatNumber) && $this->validateVatNumberExistence($vatNumber);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Vies/Client.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Ibericode\Vat\Vies;
Expand All @@ -8,7 +9,6 @@

class Client
{

/**
* @const string
*/
Expand Down Expand Up @@ -42,7 +42,7 @@ public function __construct(int $timeout = 10)
*
* @throws ViesException
*/
public function checkVat(string $countryCode, string $vatNumber) : bool
public function checkVat(string $countryCode, string $vatNumber): bool
{
try {
$response = $this->getClient()->checkVat(
Expand All @@ -61,7 +61,7 @@ public function checkVat(string $countryCode, string $vatNumber) : bool
/**
* @return SoapClient
*/
protected function getClient() : SoapClient
protected function getClient(): SoapClient
{
if ($this->client === null) {
$this->client = new SoapClient(self::URL, ['connection_timeout' => $this->timeout]);
Expand Down
1 change: 0 additions & 1 deletion src/Vies/ViesException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

class ViesException extends Exception
{

}
1 change: 0 additions & 1 deletion tests/Clients/ClientsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

class ClientsTest extends TestCase
{

/**
* @group remote-http
* @dataProvider clientProvider
Expand Down
2 changes: 1 addition & 1 deletion tests/RatesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class RatesTest extends TestCase
{
protected function setUp() : void
protected function setUp(): void
{
if (file_exists('vendor/rates')) {
unlink('vendor/rates');
Expand Down
2 changes: 0 additions & 2 deletions tests/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Ibericode\Vat\Tests;

use Ibericode\Vat\Validator;

use PHPUnit\Framework\TestCase;

/**
Expand All @@ -12,7 +11,6 @@
*/
class ValidatorTest extends TestCase
{

/**
* @covers Validator::validateVatNumberFormat
*/
Expand Down

0 comments on commit cb82086

Please sign in to comment.