From 2acb1c9fb6c74bd9424884bad3c71e8ef5d5dd3b Mon Sep 17 00:00:00 2001 From: Daniel Seifert Date: Wed, 13 Jul 2022 10:41:23 +0200 Subject: [PATCH] apply PSR-12 rules --- .php-cs-fixer.php | 13 ++++ Tests/ApiTestCase.php | 2 +- Tests/ClientTest.php | 4 +- Tests/RecipientsList/RecipientsListTest.php | 40 ++++++------- Tests/Request/AbstractRequest.php | 4 +- Tests/Response/AbstractResponse.php | 7 +-- Tests/SMS/BinaryRequestTest.php | 4 +- Tests/SMS/RequestFactoryTest.php | 4 +- Tests/SMS/ResponseTest.php | 4 +- Tests/SMS/TextRequestTest.php | 4 +- Tests/UrlTest.php | 4 +- Tests/ValueObject/RecipientTest.php | 10 ++-- Tests/ValueObject/SenderTest.php | 12 ++-- Tests/ValueObject/SmsBinaryMessageTest.php | 12 ++-- Tests/ValueObject/SmsTextMessageTest.php | 12 ++-- src/Client.php | 22 ++++--- src/Exceptions/ApiException.php | 3 +- src/Exceptions/ExceptionMessages.php | 10 ++-- src/Exceptions/LinkmobilityException.php | 3 +- src/Exceptions/RecipientException.php | 3 +- src/RecipientsList/RecipientsList.php | 29 +++++---- .../RecipientsListInterface.php | 8 +-- src/Request/Request.php | 60 +++++++++---------- src/Request/RequestInterface.php | 40 ++++++------- src/Response/Response.php | 23 +++---- src/Response/ResponseInterface.php | 8 +-- src/SMS/BinaryRequest.php | 8 +-- src/SMS/RequestFactory.php | 10 ++-- src/SMS/RequestFactoryInterface.php | 6 +- src/SMS/SmsRequestInterface.php | 4 +- src/SMS/TextRequest.php | 8 +-- src/Url.php | 4 +- src/UrlInterface.php | 2 +- src/ValueObject/Recipient.php | 2 +- src/ValueObject/Sender.php | 6 +- src/ValueObject/SmsBinaryMessage.php | 2 +- src/ValueObject/SmsMessageAbstract.php | 4 +- src/ValueObject/SmsMessageInterface.php | 6 +- src/ValueObject/SmsTextMessage.php | 2 +- src/ValueObject/StringValueObject.php | 2 +- 40 files changed, 213 insertions(+), 198 deletions(-) create mode 100644 .php-cs-fixer.php diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 0000000..244806f --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,13 @@ +in(__DIR__) +; + +$config = new PhpCsFixer\Config(); +return $config->setRules([ + '@PHP70Migration' => true, + '@PSR12' => true + ]) + ->setFinder($finder) +; \ No newline at end of file diff --git a/Tests/ApiTestCase.php b/Tests/ApiTestCase.php index 7b925cf..90ff082 100644 --- a/Tests/ApiTestCase.php +++ b/Tests/ApiTestCase.php @@ -18,7 +18,7 @@ abstract class ApiTestCase extends TestCase * @return mixed * @throws ReflectionException */ - public function callMethod(object $object, string $methodName, array $arguments = array()) + public function callMethod(object $object, string $methodName, array $arguments = []) { $class = new ReflectionClass($object); $method = $class->getMethod($methodName); diff --git a/Tests/ClientTest.php b/Tests/ClientTest.php index 3cc8678..10c8b63 100644 --- a/Tests/ClientTest.php +++ b/Tests/ClientTest.php @@ -13,7 +13,7 @@ * @link http://www.oxidmodule.com */ -declare( strict_types = 1 ); +declare(strict_types=1); namespace D3\LinkmobilityClient\Tests; @@ -44,7 +44,7 @@ class ClientTest extends ApiTestCase /** * @return void */ - public function setUp():void + public function setUp(): void { parent::setUp(); diff --git a/Tests/RecipientsList/RecipientsListTest.php b/Tests/RecipientsList/RecipientsListTest.php index a8021b5..d2b1ad7 100644 --- a/Tests/RecipientsList/RecipientsListTest.php +++ b/Tests/RecipientsList/RecipientsListTest.php @@ -13,7 +13,7 @@ * @link http://www.oxidmodule.com */ -declare( strict_types = 1 ); +declare(strict_types=1); namespace D3\LinkmobilityClient\Tests\RecipientsList; @@ -42,7 +42,7 @@ class RecipientsListTest extends ApiTestCase /** * @return void */ - public function setUp():void + public function setUp(): void { parent::setUp(); @@ -164,11 +164,11 @@ class RecipientsListTest extends ApiTestCase ->getMock(); if ($unparsable) { - $phoneNumberUtilMock->method( 'parse' )->willThrowException(new NumberParseException(0, 'message')); + $phoneNumberUtilMock->method('parse')->willThrowException(new NumberParseException(0, 'message')); } else { - $phoneNumberUtilMock->method( 'parse' )->willReturn( new PhoneNumber() ); + $phoneNumberUtilMock->method('parse')->willReturn(new PhoneNumber()); } - $phoneNumberUtilMock->method( 'isValidNumber' )->willReturn( !$invalidNumber ); + $phoneNumberUtilMock->method('isValidNumber')->willReturn(!$invalidNumber); $phoneNumberUtilMock->method('getNumberType')->willReturn($invalidNumberType ? PhoneNumberType::FIXED_LINE : PhoneNumberType::MOBILE); /** @var Recipient|MockObject $recipientMock */ @@ -435,32 +435,32 @@ class RecipientsListTest extends ApiTestCase protected function addRecipientFixture(): array { /** @var Recipient|MockObject $recipientMock */ - $recipientMock = $this->getMockBuilder( Recipient::class ) - ->onlyMethods( [ + $recipientMock = $this->getMockBuilder(Recipient::class) + ->onlyMethods([ 'get', 'getCountryCode' - ] ) - ->setConstructorArgs( [ + ]) + ->setConstructorArgs([ $this->phoneNumberFixture, $this->phoneCountryFixture - ] ) + ]) ->getMock(); - $recipientMock->method( 'get' )->willReturn( $this->phoneNumberFixture ); - $recipientMock->method( 'getCountryCode' )->willReturn( $this->phoneCountryFixture ); + $recipientMock->method('get')->willReturn($this->phoneNumberFixture); + $recipientMock->method('getCountryCode')->willReturn($this->phoneCountryFixture); /** @var Recipient|MockObject $recipientMock2 */ - $recipientMock2 = $this->getMockBuilder( Recipient::class ) - ->onlyMethods( [ + $recipientMock2 = $this->getMockBuilder(Recipient::class) + ->onlyMethods([ 'get', 'getCountryCode' - ] ) - ->setConstructorArgs( [ + ]) + ->setConstructorArgs([ $this->phoneNumberFixture, $this->phoneCountryFixture - ] ) + ]) ->getMock(); - $recipientMock2->method( 'get' )->willReturn( $this->phoneNumberFixture ); - $recipientMock2->method( 'getCountryCode' )->willReturn( $this->phoneCountryFixture ); + $recipientMock2->method('get')->willReturn($this->phoneNumberFixture); + $recipientMock2->method('getCountryCode')->willReturn($this->phoneCountryFixture); $list = [ 'fixture' => $recipientMock, @@ -475,4 +475,4 @@ class RecipientsListTest extends ApiTestCase return $list; } -} \ No newline at end of file +} diff --git a/Tests/Request/AbstractRequest.php b/Tests/Request/AbstractRequest.php index 2f96cab..41f6d57 100644 --- a/Tests/Request/AbstractRequest.php +++ b/Tests/Request/AbstractRequest.php @@ -13,7 +13,7 @@ * @link http://www.oxidmodule.com */ -declare( strict_types = 1 ); +declare(strict_types=1); namespace D3\LinkmobilityClient\Tests\Request; @@ -554,4 +554,4 @@ abstract class AbstractRequest extends ApiTestCase $this->checkGetterSetter($clientMock, 'setClient', 'getClient'); } -} \ No newline at end of file +} diff --git a/Tests/Response/AbstractResponse.php b/Tests/Response/AbstractResponse.php index 4fcf196..4cf236f 100644 --- a/Tests/Response/AbstractResponse.php +++ b/Tests/Response/AbstractResponse.php @@ -13,7 +13,7 @@ * @link http://www.oxidmodule.com */ -declare( strict_types = 1 ); +declare(strict_types=1); namespace D3\LinkmobilityClient\Tests\Response; @@ -72,8 +72,7 @@ abstract class AbstractResponse extends ApiTestCase "contentCategory" => "informational", "messageContent" => "fixture", "senderAddressType" => "international", - ] - , + ], $this->callMethod( $response, 'getContent' @@ -213,4 +212,4 @@ abstract class AbstractResponse extends ApiTestCase 'not successful'=> [false, 'fixtureMessage'] ]; } -} \ No newline at end of file +} diff --git a/Tests/SMS/BinaryRequestTest.php b/Tests/SMS/BinaryRequestTest.php index 5e15ac6..4647cec 100644 --- a/Tests/SMS/BinaryRequestTest.php +++ b/Tests/SMS/BinaryRequestTest.php @@ -13,7 +13,7 @@ * @link http://www.oxidmodule.com */ -declare( strict_types = 1 ); +declare(strict_types=1); namespace D3\LinkmobilityClient\Tests\SMS; @@ -25,4 +25,4 @@ class BinaryRequestTest extends AbstractRequest { protected $testClassName = BinaryRequest::class; protected $messageClassName = SmsBinaryMessage::class; -} \ No newline at end of file +} diff --git a/Tests/SMS/RequestFactoryTest.php b/Tests/SMS/RequestFactoryTest.php index 6c2e5d3..f063228 100644 --- a/Tests/SMS/RequestFactoryTest.php +++ b/Tests/SMS/RequestFactoryTest.php @@ -13,7 +13,7 @@ * @link http://www.oxidmodule.com */ -declare( strict_types = 1 ); +declare(strict_types=1); namespace D3\LinkmobilityClient\Tests\SMS; @@ -132,4 +132,4 @@ class RequestFactoryTest extends ApiTestCase ) ); } -} \ No newline at end of file +} diff --git a/Tests/SMS/ResponseTest.php b/Tests/SMS/ResponseTest.php index c36966d..a7b7559 100644 --- a/Tests/SMS/ResponseTest.php +++ b/Tests/SMS/ResponseTest.php @@ -13,7 +13,7 @@ * @link http://www.oxidmodule.com */ -declare( strict_types = 1 ); +declare(strict_types=1); namespace D3\LinkmobilityClient\Tests\SMS; @@ -23,4 +23,4 @@ use D3\LinkmobilityClient\Tests\Response\AbstractResponse; class ResponseTest extends AbstractResponse { protected $testClassName = Response::class; -} \ No newline at end of file +} diff --git a/Tests/SMS/TextRequestTest.php b/Tests/SMS/TextRequestTest.php index 6e666f2..d6cb3d7 100644 --- a/Tests/SMS/TextRequestTest.php +++ b/Tests/SMS/TextRequestTest.php @@ -13,7 +13,7 @@ * @link http://www.oxidmodule.com */ -declare( strict_types = 1 ); +declare(strict_types=1); namespace D3\LinkmobilityClient\Tests\SMS; @@ -25,4 +25,4 @@ class TextRequestTest extends AbstractRequest { protected $testClassName = TextRequest::class; protected $messageClassName = SmsTextMessage::class; -} \ No newline at end of file +} diff --git a/Tests/UrlTest.php b/Tests/UrlTest.php index 0948d17..43405ab 100644 --- a/Tests/UrlTest.php +++ b/Tests/UrlTest.php @@ -13,7 +13,7 @@ * @link http://www.oxidmodule.com */ -declare( strict_types = 1 ); +declare(strict_types=1); namespace D3\LinkmobilityClient\Tests; @@ -28,7 +28,7 @@ class UrlTest extends ApiTestCase /** * @return void */ - public function setUp():void + public function setUp(): void { parent::setUp(); diff --git a/Tests/ValueObject/RecipientTest.php b/Tests/ValueObject/RecipientTest.php index c47464f..8e60ebb 100644 --- a/Tests/ValueObject/RecipientTest.php +++ b/Tests/ValueObject/RecipientTest.php @@ -13,7 +13,7 @@ * @link http://www.oxidmodule.com */ -declare( strict_types = 1 ); +declare(strict_types=1); namespace D3\LinkmobilityClient\Tests\ValueObject; @@ -38,7 +38,7 @@ class RecipientTest extends ApiTestCase * @return void * @throws NumberParseException */ - public function setUp():void + public function setUp(): void { parent::setUp(); @@ -116,9 +116,9 @@ class RecipientTest extends ApiTestCase ->disableOriginalConstructor() ->getMock(); if ($number === 'abc') { - $phoneNumberUtilMock->method( 'parse' )->willThrowException(new NumberParseException(0, 'message')); + $phoneNumberUtilMock->method('parse')->willThrowException(new NumberParseException(0, 'message')); } else { - $phoneNumberUtilMock->method( 'parse' )->willReturn( new PhoneNumber() ); + $phoneNumberUtilMock->method('parse')->willReturn(new PhoneNumber()); } $phoneNumberUtilMock->method('format')->willReturn($number); $phoneNumberUtilMock->method('isValidNumber')->willReturn($validNumber); @@ -161,4 +161,4 @@ class RecipientTest extends ApiTestCase ) ); } -} \ No newline at end of file +} diff --git a/Tests/ValueObject/SenderTest.php b/Tests/ValueObject/SenderTest.php index 5cd0941..7816844 100644 --- a/Tests/ValueObject/SenderTest.php +++ b/Tests/ValueObject/SenderTest.php @@ -13,7 +13,7 @@ * @link http://www.oxidmodule.com */ -declare( strict_types = 1 ); +declare(strict_types=1); namespace D3\LinkmobilityClient\Tests\ValueObject; @@ -40,11 +40,11 @@ class SenderTest extends ApiTestCase * @throws NumberParseException * @throws RecipientException */ - public function setUp():void + public function setUp(): void { parent::setUp(); - $this->sender = new Sender( $this->phoneNumberFixture, $this->phoneCountryFixture); + $this->sender = new Sender($this->phoneNumberFixture, $this->phoneCountryFixture); } /** @@ -111,9 +111,9 @@ class SenderTest extends ApiTestCase ->disableOriginalConstructor() ->getMock(); if ($number === 'abc') { - $phoneNumberUtilMock->method( 'parse' )->willThrowException(new NumberParseException(0, 'message')); + $phoneNumberUtilMock->method('parse')->willThrowException(new NumberParseException(0, 'message')); } else { - $phoneNumberUtilMock->method( 'parse' )->willReturn( new PhoneNumber() ); + $phoneNumberUtilMock->method('parse')->willReturn(new PhoneNumber()); } $phoneNumberUtilMock->method('format')->willReturn($number); $phoneNumberUtilMock->method('isValidNumber')->willReturn($validNumber); @@ -156,4 +156,4 @@ class SenderTest extends ApiTestCase ) ); } -} \ No newline at end of file +} diff --git a/Tests/ValueObject/SmsBinaryMessageTest.php b/Tests/ValueObject/SmsBinaryMessageTest.php index 13fd6ed..133dfc0 100644 --- a/Tests/ValueObject/SmsBinaryMessageTest.php +++ b/Tests/ValueObject/SmsBinaryMessageTest.php @@ -13,7 +13,7 @@ * @link http://www.oxidmodule.com */ -declare( strict_types = 1 ); +declare(strict_types=1); namespace D3\LinkmobilityClient\Tests\ValueObject; @@ -34,11 +34,11 @@ class SmsBinaryMessageTest extends ApiTestCase /** * @return void */ - public function setUp():void + public function setUp(): void { parent::setUp(); - $this->message = new SmsBinaryMessage( $this->messageFixture); + $this->message = new SmsBinaryMessage($this->messageFixture); } /** @@ -100,9 +100,9 @@ class SmsBinaryMessageTest extends ApiTestCase ->onlyMethods(['validate']) ->getMock(); if ($valid) { - $smsLengthMock->expects( $this->never() )->method( 'validate' )->willReturn( true ); + $smsLengthMock->expects($this->never())->method('validate')->willReturn(true); } else { - $smsLengthMock->expects( $this->atLeastOnce() )->method( 'validate' )->willThrowException(new \Phlib\SmsLength\Exception\InvalidArgumentException()); + $smsLengthMock->expects($this->atLeastOnce())->method('validate')->willThrowException(new \Phlib\SmsLength\Exception\InvalidArgumentException()); } /** @var SmsBinaryMessage|MockObject $message */ @@ -240,4 +240,4 @@ class SmsBinaryMessageTest extends ApiTestCase ) ); } -} \ No newline at end of file +} diff --git a/Tests/ValueObject/SmsTextMessageTest.php b/Tests/ValueObject/SmsTextMessageTest.php index 59eb580..0ef485e 100644 --- a/Tests/ValueObject/SmsTextMessageTest.php +++ b/Tests/ValueObject/SmsTextMessageTest.php @@ -13,7 +13,7 @@ * @link http://www.oxidmodule.com */ -declare( strict_types = 1 ); +declare(strict_types=1); namespace D3\LinkmobilityClient\Tests\ValueObject; @@ -33,11 +33,11 @@ class SmsTextMessageTest extends SmsBinaryMessageTest /** * @return void */ - public function setUp():void + public function setUp(): void { parent::setUp(); - $this->message = new SmsTextMessage( $this->messageFixture); + $this->message = new SmsTextMessage($this->messageFixture); } /** @@ -89,9 +89,9 @@ class SmsTextMessageTest extends SmsBinaryMessageTest ->onlyMethods(['validate']) ->getMock(); if ($valid) { - $smsLengthMock->expects( $this->never() )->method( 'validate' )->willReturn( true ); + $smsLengthMock->expects($this->never())->method('validate')->willReturn(true); } else { - $smsLengthMock->expects( $this->atLeastOnce() )->method( 'validate' )->willThrowException(new InvalidArgumentException()); + $smsLengthMock->expects($this->atLeastOnce())->method('validate')->willThrowException(new InvalidArgumentException()); } /** @var SmsTextMessage|MockObject $message */ @@ -112,4 +112,4 @@ class SmsTextMessageTest extends SmsBinaryMessageTest ) ); } -} \ No newline at end of file +} diff --git a/src/Client.php b/src/Client.php index 31ee96e..5eb0c16 100644 --- a/src/Client.php +++ b/src/Client.php @@ -13,7 +13,7 @@ * @link http://www.oxidmodule.com */ -declare( strict_types = 1 ); +declare(strict_types=1); namespace D3\LinkmobilityClient; @@ -38,7 +38,7 @@ class Client { $this->accessToken = $accessToken; $this->apiUrl = $apiUrl ?: new Url(); - $this->requestClient = $client ?: new \GuzzleHttp\Client( [ 'base_uri' => $this->apiUrl->getBaseUri() ] ); + $this->requestClient = $client ?: new \GuzzleHttp\Client([ 'base_uri' => $this->apiUrl->getBaseUri() ]); } /** @@ -49,7 +49,7 @@ class Client * @throws GuzzleException * @throws InvalidArgumentException */ - public function request(RequestInterface $request) : Response\ResponseInterface + public function request(RequestInterface $request): Response\ResponseInterface { $request->validate(); @@ -67,11 +67,13 @@ class Client * @throws ApiException * @throws GuzzleException */ - protected function rawRequest( $url, string $method = RequestInterface::METHOD_GET, array $options = []): ResponseInterface + protected function rawRequest($url, string $method = RequestInterface::METHOD_GET, array $options = []): ResponseInterface { $options['headers']['Authorization'] = 'Bearer '.$this->accessToken; - if ($this->hasLogger()) $this->getLogger()->debug('request '.$url, $options); + if ($this->hasLogger()) { + $this->getLogger()->debug('request '.$url, $options); + } $response = $this->requestClient->request( $method, @@ -81,7 +83,9 @@ class Client if ($response->getStatusCode() != 200) { $message = sprintf(ExceptionMessages::NOK_REQUEST_RETURN, $url, $response->getStatusCode()); - if ($this->hasLogger()) $this->getLogger()->error($message); + if ($this->hasLogger()) { + $this->getLogger()->error($message); + } throw new ApiException($message); } @@ -98,7 +102,7 @@ class Client * * @return Client */ - public function setLogger(LoggerInterface $logger ) : Client + public function setLogger(LoggerInterface $logger): Client { $this->logger = $logger; @@ -108,7 +112,7 @@ class Client /** * @return bool */ - public function hasLogger() : bool + public function hasLogger(): bool { return $this->logger instanceof LoggerInterface; } @@ -120,4 +124,4 @@ class Client { return $this->hasLogger() ? $this->logger : null; } -} \ No newline at end of file +} diff --git a/src/Exceptions/ApiException.php b/src/Exceptions/ApiException.php index ce6c9bb..a199851 100644 --- a/src/Exceptions/ApiException.php +++ b/src/Exceptions/ApiException.php @@ -19,5 +19,4 @@ namespace D3\LinkmobilityClient\Exceptions; class ApiException extends LinkmobilityException { - -} \ No newline at end of file +} diff --git a/src/Exceptions/ExceptionMessages.php b/src/Exceptions/ExceptionMessages.php index c8bcaa7..13ab429 100644 --- a/src/Exceptions/ExceptionMessages.php +++ b/src/Exceptions/ExceptionMessages.php @@ -17,11 +17,11 @@ namespace D3\LinkmobilityClient\Exceptions; class ExceptionMessages { - const INVALID_SENDER = 'invalid sender phone number'; + public const INVALID_SENDER = 'invalid sender phone number'; - const NOK_REQUEST_RETURN = 'request %1$s returns status code %2$s'; + public const NOK_REQUEST_RETURN = 'request %1$s returns status code %2$s'; - const INVALID_RECIPIENT_PHONE = 'invalid recipient phone number'; + public const INVALID_RECIPIENT_PHONE = 'invalid recipient phone number'; - const NOT_A_MOBILE_NUMBER = 'not a mobile number'; -} \ No newline at end of file + public const NOT_A_MOBILE_NUMBER = 'not a mobile number'; +} diff --git a/src/Exceptions/LinkmobilityException.php b/src/Exceptions/LinkmobilityException.php index 462d3eb..d822d44 100644 --- a/src/Exceptions/LinkmobilityException.php +++ b/src/Exceptions/LinkmobilityException.php @@ -21,5 +21,4 @@ use Exception; class LinkmobilityException extends Exception { - -} \ No newline at end of file +} diff --git a/src/Exceptions/RecipientException.php b/src/Exceptions/RecipientException.php index 9e82f70..180a246 100644 --- a/src/Exceptions/RecipientException.php +++ b/src/Exceptions/RecipientException.php @@ -19,5 +19,4 @@ namespace D3\LinkmobilityClient\Exceptions; class RecipientException extends LinkmobilityException { - -} \ No newline at end of file +} diff --git a/src/RecipientsList/RecipientsList.php b/src/RecipientsList/RecipientsList.php index 7030b00..bf219b7 100644 --- a/src/RecipientsList/RecipientsList.php +++ b/src/RecipientsList/RecipientsList.php @@ -38,7 +38,7 @@ class RecipientsList implements RecipientsListInterface, Iterator */ private $recipients = []; - public function __construct( Client $client ) + public function __construct(Client $client) { $this->setClient($client); } @@ -56,28 +56,27 @@ class RecipientsList implements RecipientsListInterface, Iterator * * @return RecipientsListInterface */ - public function add(Recipient $recipient) : RecipientsListInterface + public function add(Recipient $recipient): RecipientsListInterface { $phoneUtil = $this->getPhoneNumberUtil(); try { - $phoneNumber = $phoneUtil->parse( $recipient->get(), $recipient->getCountryCode() ); + $phoneNumber = $phoneUtil->parse($recipient->get(), $recipient->getCountryCode()); - if ( false === $phoneUtil->isValidNumber( $phoneNumber ) ) { - throw new RecipientException( ExceptionMessages::INVALID_RECIPIENT_PHONE ); + if (false === $phoneUtil->isValidNumber($phoneNumber)) { + throw new RecipientException(ExceptionMessages::INVALID_RECIPIENT_PHONE); } elseif ( false === in_array( - $phoneUtil->getNumberType( $phoneNumber ), + $phoneUtil->getNumberType($phoneNumber), [ PhoneNumberType::MOBILE, PhoneNumberType::FIXED_LINE_OR_MOBILE ] ) ) { - throw new RecipientException( ExceptionMessages::NOT_A_MOBILE_NUMBER ); + throw new RecipientException(ExceptionMessages::NOT_A_MOBILE_NUMBER); } - $this->recipients[ md5( serialize( $recipient ) ) ] = $recipient; - + $this->recipients[ md5(serialize($recipient)) ] = $recipient; } catch (NumberParseException $e) { if ($this->getClient()->hasLogger()) { $this->getClient()->getLogger()->info($e->getMessage()); @@ -87,21 +86,21 @@ class RecipientsList implements RecipientsListInterface, Iterator $this->getClient()->getLogger()->info($e->getMessage()); } } - + return $this; } /** * @return RecipientsListInterface */ - public function clearRecipents() : RecipientsListInterface + public function clearRecipents(): RecipientsListInterface { $this->recipients = []; return $this; } - public function getRecipients() : array + public function getRecipients(): array { return array_values( array_map( @@ -116,7 +115,7 @@ class RecipientsList implements RecipientsListInterface, Iterator /** * @return array */ - public function getRecipientsList() : array + public function getRecipientsList(): array { return $this->recipients; } @@ -165,10 +164,10 @@ class RecipientsList implements RecipientsListInterface, Iterator * * @return RecipientsList */ - public function setClient( Client $client ): RecipientsList + public function setClient(Client $client): RecipientsList { $this->client = $client; return $this; } -} \ No newline at end of file +} diff --git a/src/RecipientsList/RecipientsListInterface.php b/src/RecipientsList/RecipientsListInterface.php index 4489d3d..ff6d7f2 100644 --- a/src/RecipientsList/RecipientsListInterface.php +++ b/src/RecipientsList/RecipientsListInterface.php @@ -24,9 +24,9 @@ interface RecipientsListInterface { public function __construct(Client $client); - public function add(Recipient $recipient) : RecipientsListInterface; + public function add(Recipient $recipient): RecipientsListInterface; - public function clearRecipents() : RecipientsListInterface; + public function clearRecipents(): RecipientsListInterface; - public function getRecipients() : array; -} \ No newline at end of file + public function getRecipients(): array; +} diff --git a/src/Request/Request.php b/src/Request/Request.php index 8c9e6a4..d2760f5 100644 --- a/src/Request/Request.php +++ b/src/Request/Request.php @@ -13,7 +13,7 @@ * @link http://www.oxidmodule.com */ -declare( strict_types = 1 ); +declare(strict_types=1); namespace D3\LinkmobilityClient\Request; @@ -118,7 +118,7 @@ abstract class Request implements RequestInterface public function __construct(SmsMessageInterface $message, Client $client) { $this->recipientsList = new RecipientsList($client); - $this->setMessage( $message ); + $this->setMessage($message); $this->setClient($client); return $this; @@ -129,30 +129,30 @@ abstract class Request implements RequestInterface */ public function validate() { - Assert::that( $this->getMethod() )->choice( self::getMethods() ); - Assert::that( $this->getUri() )->string()->startsWith( '/' ); + Assert::that($this->getMethod())->choice(self::getMethods()); + Assert::that($this->getUri())->string()->startsWith('/'); Assert::that($this->getBody())->isArray(); Assert::that($this->getResponseClass())->implementsInterface(ResponseInterface::class); Assert::that($this->getOptions())->isArray(); - Assert::that( $this->getRecipientsList() )->isInstanceOf(RecipientsList::class)->notEmpty(); - Assert::that( $this->getRecipientsList()->getRecipients())->notEmpty('request must contain a valid recipient'); - Assert::thatAll( $this->getRecipientsList() )->isInstanceOf( Recipient::class )->notEmpty(); + Assert::that($this->getRecipientsList())->isInstanceOf(RecipientsList::class)->notEmpty(); + Assert::that($this->getRecipientsList()->getRecipients())->notEmpty('request must contain a valid recipient'); + Assert::thatAll($this->getRecipientsList())->isInstanceOf(Recipient::class)->notEmpty(); // optional properties - Assert::thatNullOr( $this->getClientMessageId() )->string(); - Assert::thatNullOr( $this->getContentCategory() )->choice(self::getContentCategories()); - Assert::thatNullOr( $this->getNotificationCallbackUrl() )->url(); - Assert::thatNullOr( $this->getPriority() )->integer(); - Assert::thatNullOr( $this->doSendAsFlashSms() )->boolean(); - Assert::thatNullOr( $this->getSenderAddress() )->isInstanceOf(Sender::class); - Assert::thatNullOr( $this->getSenderAddressType() )->choice(self::getSenderAddressTypes()); - Assert::thatNullOr( $this->getTestMode() )->boolean(); - Assert::thatNullOr( $this->getValidityPeriode() )->integer(); + Assert::thatNullOr($this->getClientMessageId())->string(); + Assert::thatNullOr($this->getContentCategory())->choice(self::getContentCategories()); + Assert::thatNullOr($this->getNotificationCallbackUrl())->url(); + Assert::thatNullOr($this->getPriority())->integer(); + Assert::thatNullOr($this->doSendAsFlashSms())->boolean(); + Assert::thatNullOr($this->getSenderAddress())->isInstanceOf(Sender::class); + Assert::thatNullOr($this->getSenderAddressType())->choice(self::getSenderAddressTypes()); + Assert::thatNullOr($this->getTestMode())->boolean(); + Assert::thatNullOr($this->getValidityPeriode())->integer(); } - public function getRawBody() : array + public function getRawBody(): array { return [ 'clientMessageId' => $this->getClientMessageId(), @@ -174,9 +174,9 @@ abstract class Request implements RequestInterface */ public function getBody(): array { - $body = array_filter( $this->getRawBody(), function( $elm ) { - return ! is_null( $elm ); - } ); + $body = array_filter($this->getRawBody(), function ($elm) { + return ! is_null($elm); + }); switch ($this->getContentType()) { case RequestInterface::CONTENTTYPE_JSON: @@ -259,7 +259,7 @@ abstract class Request implements RequestInterface return $this; } - public function getContentType() : string + public function getContentType(): string { return $this->contentType; } @@ -293,7 +293,7 @@ abstract class Request implements RequestInterface return $this; } - public function getContentCategory() : string + public function getContentCategory(): string { return $this->contentCategory; } @@ -318,7 +318,7 @@ abstract class Request implements RequestInterface return $this; } - public function getTestMode() : bool + public function getTestMode(): bool { return $this->test; } @@ -335,7 +335,7 @@ abstract class Request implements RequestInterface return $this; } - public function getMaxSmsPerMessage() : int + public function getMaxSmsPerMessage(): int { return $this->maxSmsPerMessage; } @@ -352,7 +352,7 @@ abstract class Request implements RequestInterface return $this; } - public function getMessageType() : string + public function getMessageType(): string { return $this->messageType; } @@ -400,7 +400,7 @@ abstract class Request implements RequestInterface /** * @return RecipientsListInterface */ - public function getRecipientsList() : RecipientsListInterface + public function getRecipientsList(): RecipientsListInterface { return $this->recipientsList; } @@ -420,7 +420,7 @@ abstract class Request implements RequestInterface /** * @return bool|null */ - public function doSendAsFlashSms() : bool + public function doSendAsFlashSms(): bool { return $this->sendAsFlashSms; } @@ -483,7 +483,7 @@ abstract class Request implements RequestInterface * * @return $this */ - public function setValidityPeriode( int $validityPeriode): Request + public function setValidityPeriode(int $validityPeriode): Request { $this->validityPeriode = $validityPeriode; @@ -520,10 +520,10 @@ abstract class Request implements RequestInterface /** * @param Client $client */ - public function setClient( Client $client ): Request + public function setClient(Client $client): Request { $this->client = $client; return $this; } -} \ No newline at end of file +} diff --git a/src/Request/RequestInterface.php b/src/Request/RequestInterface.php index d19c6da..226b15e 100644 --- a/src/Request/RequestInterface.php +++ b/src/Request/RequestInterface.php @@ -25,24 +25,24 @@ use D3\LinkmobilityClient\Response\ResponseInterface as LMResponseInterface; interface RequestInterface { - const METHOD_GET = 'GET'; - const METHOD_POST = 'POST'; - const METHOD_PUT = 'PUT'; - const METHOD_PATCH = 'PATCH'; - const METHOD_DELETE = 'DELETE'; + public const METHOD_GET = 'GET'; + public const METHOD_POST = 'POST'; + public const METHOD_PUT = 'PUT'; + public const METHOD_PATCH = 'PATCH'; + public const METHOD_DELETE = 'DELETE'; - const CONTENTTYPE_JSON = 'application/json'; + public const CONTENTTYPE_JSON = 'application/json'; - const CONTENTCATEGORY_INFORMATIONAL = 'informational'; - const CONTENTCATEGORY_ADVERTISEMENT = 'advertisement'; + public const CONTENTCATEGORY_INFORMATIONAL = 'informational'; + public const CONTENTCATEGORY_ADVERTISEMENT = 'advertisement'; - const MESSAGETYPE_DEFAULT = 'default'; - const MESSAGETYPE_VOICE = 'voice'; + public const MESSAGETYPE_DEFAULT = 'default'; + public const MESSAGETYPE_VOICE = 'voice'; - const SENDERADDRESSTYPE_NATIONAL = 'national'; - const SENDERADDRESSTYPE_INTERNATIONAL = 'international'; - const SENDERADDRESSTYPE_ALPHANUMERIC = 'alphanumeric'; - const SENDERADDRESSTYPE_SHORTCODE = 'shortcode'; + public const SENDERADDRESSTYPE_NATIONAL = 'national'; + public const SENDERADDRESSTYPE_INTERNATIONAL = 'international'; + public const SENDERADDRESSTYPE_ALPHANUMERIC = 'alphanumeric'; + public const SENDERADDRESSTYPE_SHORTCODE = 'shortcode'; public function __construct(SmsMessageInterface $message, Client $client); @@ -53,28 +53,28 @@ interface RequestInterface * * @return string */ - public function getMethod() : string; + public function getMethod(): string; /** * Must return the URI for the request with a leading slash, i.e. /messages.json * * @return string */ - public function getUri() : string; + public function getUri(): string; /** * Must return the body which is being sent as json * * @return array */ - public function getBody() : array; + public function getBody(): array; /** * Must return the class to where the response is handed over. It must implement the ResponseInterface * * @return string */ - public function getResponseClass() : string; + public function getResponseClass(): string; /** * @param PsrResponseInterface $rawResponse @@ -88,7 +88,7 @@ interface RequestInterface * * @return array */ - public function getOptions() : array; + public function getOptions(): array; /** * Must validate the input of the request @@ -98,4 +98,4 @@ interface RequestInterface * @throws InvalidArgumentException */ public function validate(); -} \ No newline at end of file +} diff --git a/src/Response/Response.php b/src/Response/Response.php index 2ceff07..6213178 100644 --- a/src/Response/Response.php +++ b/src/Response/Response.php @@ -1,4 +1,5 @@ -rawResponse->getBody()->rewind(); $this->content = json_decode($this->rawResponse->getBody()->getContents(), true); } - - public function getRawResponse() : \Psr\Http\Message\ResponseInterface + + public function getRawResponse(): \Psr\Http\Message\ResponseInterface { return $this->rawResponse; } @@ -45,7 +46,7 @@ abstract class Response implements ResponseInterface /** * @return int */ - public function getInternalStatus() : int + public function getInternalStatus(): int { return $this->getContent()[self::STATUSCODE]; } @@ -53,7 +54,7 @@ abstract class Response implements ResponseInterface /** * @return string */ - public function getStatusMessage() : string + public function getStatusMessage(): string { return $this->getContent()[self::STATUSMESSAGE]; } @@ -77,7 +78,7 @@ abstract class Response implements ResponseInterface /** * @return string|null */ - public function getSmsCount() : int + public function getSmsCount(): int { return $this->getContent()[self::SMSCOUNT]; } diff --git a/src/Response/ResponseInterface.php b/src/Response/ResponseInterface.php index 66cae6d..b807b82 100644 --- a/src/Response/ResponseInterface.php +++ b/src/Response/ResponseInterface.php @@ -8,17 +8,17 @@ interface ResponseInterface { public function __construct(\Psr\Http\Message\ResponseInterface $rawResponse); - public function getRawResponse() : \Psr\Http\Message\ResponseInterface; + public function getRawResponse(): \Psr\Http\Message\ResponseInterface; - public function getInternalStatus() : int; + public function getInternalStatus(): int; - public function getStatusMessage() : string; + public function getStatusMessage(): string; public function getClientMessageId(); public function getTransferId(); - public function getSmsCount() : int; + public function getSmsCount(): int; public function isSuccessful(): bool; diff --git a/src/SMS/BinaryRequest.php b/src/SMS/BinaryRequest.php index b10ee9e..0fde0d6 100644 --- a/src/SMS/BinaryRequest.php +++ b/src/SMS/BinaryRequest.php @@ -13,7 +13,7 @@ * @link http://www.oxidmodule.com */ -declare( strict_types = 1 ); +declare(strict_types=1); namespace D3\LinkmobilityClient\SMS; @@ -32,7 +32,7 @@ class BinaryRequest extends Request implements SmsRequestInterface return '/rest/smsmessaging/binary'; } - public function getRawBody() : array + public function getRawBody(): array { return array_merge( parent::getRawBody(), @@ -49,7 +49,7 @@ class BinaryRequest extends Request implements SmsRequestInterface { parent::validate(); - Assert::thatNullOr( $this->getMessage() )->isInstanceOf(SmsBinaryMessage::class); + Assert::thatNullOr($this->getMessage())->isInstanceOf(SmsBinaryMessage::class); } /** @@ -59,4 +59,4 @@ class BinaryRequest extends Request implements SmsRequestInterface { return Response::class; } -} \ No newline at end of file +} diff --git a/src/SMS/RequestFactory.php b/src/SMS/RequestFactory.php index 59ded4f..236e625 100644 --- a/src/SMS/RequestFactory.php +++ b/src/SMS/RequestFactory.php @@ -13,7 +13,7 @@ * @link http://www.oxidmodule.com */ -declare( strict_types = 1 ); +declare(strict_types=1); namespace D3\LinkmobilityClient\SMS; @@ -27,12 +27,12 @@ class RequestFactory /** * @deprecated is SmsLength constant from version 2.1 */ - const GSM_7BIT = '7-bit'; + public const GSM_7BIT = '7-bit'; /** * @deprecated is SmsLength constant from version 2.1 */ - const GSM_UCS2 = 'ucs-2'; + public const GSM_UCS2 = 'ucs-2'; protected $message; protected $client; @@ -46,7 +46,7 @@ class RequestFactory /** * @return SmsRequestInterface */ - public function getSmsRequest() : SmsRequestInterface + public function getSmsRequest(): SmsRequestInterface { if ($this->getSmsLength()->getEncoding() === self::GSM_7BIT) { $message = new SmsTextMessage($this->message); @@ -64,4 +64,4 @@ class RequestFactory { return new SmsLength($this->message); } -} \ No newline at end of file +} diff --git a/src/SMS/RequestFactoryInterface.php b/src/SMS/RequestFactoryInterface.php index 9fbdee2..b481ac5 100644 --- a/src/SMS/RequestFactoryInterface.php +++ b/src/SMS/RequestFactoryInterface.php @@ -13,7 +13,7 @@ * @link http://www.oxidmodule.com */ -declare( strict_types = 1 ); +declare(strict_types=1); namespace D3\LinkmobilityClient\SMS; @@ -21,5 +21,5 @@ interface RequestFactoryInterface { public function __construct($message); - public function getRequest() : SmsRequestInterface; -} \ No newline at end of file + public function getRequest(): SmsRequestInterface; +} diff --git a/src/SMS/SmsRequestInterface.php b/src/SMS/SmsRequestInterface.php index 9241587..4f84a89 100644 --- a/src/SMS/SmsRequestInterface.php +++ b/src/SMS/SmsRequestInterface.php @@ -17,4 +17,6 @@ namespace D3\LinkmobilityClient\SMS; use D3\LinkmobilityClient\Request\RequestInterface; -interface SmsRequestInterface extends RequestInterface {} \ No newline at end of file +interface SmsRequestInterface extends RequestInterface +{ +} diff --git a/src/SMS/TextRequest.php b/src/SMS/TextRequest.php index 83da1dc..e05a9d4 100644 --- a/src/SMS/TextRequest.php +++ b/src/SMS/TextRequest.php @@ -13,7 +13,7 @@ * @link http://www.oxidmodule.com */ -declare( strict_types = 1 ); +declare(strict_types=1); namespace D3\LinkmobilityClient\SMS; @@ -39,7 +39,7 @@ class TextRequest extends Request implements SmsRequestInterface { parent::validate(); - Assert::thatNullOr( $this->getMessage() )->isInstanceOf(SmsTextMessage::class); + Assert::thatNullOr($this->getMessage())->isInstanceOf(SmsTextMessage::class); } /** @@ -50,7 +50,7 @@ class TextRequest extends Request implements SmsRequestInterface return Response::class; } - public function getRawBody() : array + public function getRawBody(): array { return array_merge( parent::getRawBody(), @@ -60,4 +60,4 @@ class TextRequest extends Request implements SmsRequestInterface ] ); } -} \ No newline at end of file +} diff --git a/src/Url.php b/src/Url.php index 6e7c3d5..b76a0ce 100644 --- a/src/Url.php +++ b/src/Url.php @@ -13,7 +13,7 @@ * @link http://www.oxidmodule.com */ -declare( strict_types = 1 ); +declare(strict_types=1); namespace D3\LinkmobilityClient; @@ -28,4 +28,4 @@ class Url implements UrlInterface { return $this->baseUri; } -} \ No newline at end of file +} diff --git a/src/UrlInterface.php b/src/UrlInterface.php index 6507feb..63a4bde 100644 --- a/src/UrlInterface.php +++ b/src/UrlInterface.php @@ -18,4 +18,4 @@ namespace D3\LinkmobilityClient; interface UrlInterface { public function getBaseUri(): string; -} \ No newline at end of file +} diff --git a/src/ValueObject/Recipient.php b/src/ValueObject/Recipient.php index 2139dd6..b15f600 100644 --- a/src/ValueObject/Recipient.php +++ b/src/ValueObject/Recipient.php @@ -46,7 +46,7 @@ class Recipient extends StringValueObject /** * @return string */ - public function getCountryCode() :string + public function getCountryCode(): string { return $this->countryCode; } diff --git a/src/ValueObject/Sender.php b/src/ValueObject/Sender.php index 1a8c13a..c7866ea 100644 --- a/src/ValueObject/Sender.php +++ b/src/ValueObject/Sender.php @@ -26,14 +26,14 @@ class Sender extends StringValueObject $phoneUtil = $this->getPhoneNumberUtil(); - $phoneNumber = $phoneUtil->parse( $number, strtoupper($iso2CountryCode) ); + $phoneNumber = $phoneUtil->parse($number, strtoupper($iso2CountryCode)); $number = ltrim($phoneUtil->format($phoneNumber, PhoneNumberFormat::E164), '+'); if (false === $phoneUtil->isValidNumber($phoneNumber)) { - throw new RecipientException( ExceptionMessages::INVALID_SENDER ); + throw new RecipientException(ExceptionMessages::INVALID_SENDER); } - parent::__construct( $number); + parent::__construct($number); } /** diff --git a/src/ValueObject/SmsBinaryMessage.php b/src/ValueObject/SmsBinaryMessage.php index 8f84db6..c1288e9 100644 --- a/src/ValueObject/SmsBinaryMessage.php +++ b/src/ValueObject/SmsBinaryMessage.php @@ -13,7 +13,7 @@ class SmsBinaryMessage extends SmsMessageAbstract */ public function __construct(string $message) { - parent::__construct( $message); + parent::__construct($message); $this->getSmsLength()->validate(); } diff --git a/src/ValueObject/SmsMessageAbstract.php b/src/ValueObject/SmsMessageAbstract.php index a67e7c2..723c58e 100644 --- a/src/ValueObject/SmsMessageAbstract.php +++ b/src/ValueObject/SmsMessageAbstract.php @@ -19,7 +19,7 @@ abstract class SmsMessageAbstract extends StringValueObject implements SmsMessag /** * @return int */ - public function chunkCount() : int + public function chunkCount(): int { return $this->getSmsLength()->getMessageCount(); } @@ -27,7 +27,7 @@ abstract class SmsMessageAbstract extends StringValueObject implements SmsMessag /** * @return int */ - public function length() : int + public function length(): int { return $this->getSmsLength()->getSize(); } diff --git a/src/ValueObject/SmsMessageInterface.php b/src/ValueObject/SmsMessageInterface.php index 34e927a..c0605b5 100644 --- a/src/ValueObject/SmsMessageInterface.php +++ b/src/ValueObject/SmsMessageInterface.php @@ -17,9 +17,9 @@ namespace D3\LinkmobilityClient\ValueObject; interface SmsMessageInterface { - public function chunkCount() : int; + public function chunkCount(): int; - public function length() : int; + public function length(): int; public function getMessageContent(); -} \ No newline at end of file +} diff --git a/src/ValueObject/SmsTextMessage.php b/src/ValueObject/SmsTextMessage.php index a0368db..9736bcc 100644 --- a/src/ValueObject/SmsTextMessage.php +++ b/src/ValueObject/SmsTextMessage.php @@ -14,7 +14,7 @@ class SmsTextMessage extends SmsMessageAbstract */ public function __construct(string $message) { - parent::__construct( $message); + parent::__construct($message); $smsLength = $this->getSmsLength(); $smsLength->validate(); diff --git a/src/ValueObject/StringValueObject.php b/src/ValueObject/StringValueObject.php index 307e981..3dea9c5 100644 --- a/src/ValueObject/StringValueObject.php +++ b/src/ValueObject/StringValueObject.php @@ -10,7 +10,7 @@ abstract class StringValueObject extends ValueObject { public function __construct(string $number) { - Assert::that( $number)->notEmpty(); + Assert::that($number)->notEmpty(); $this->value = $number; }