diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 8d94194..e813522 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -36,7 +36,7 @@ jobs: with: php-version: 8.0 coverage: none - tools: php-cs-fixer:2.19.0, cs2pr + tools: php-cs-fixer:3.9.5, cs2pr - name: PHP-CS-Fixer run: php-cs-fixer fix --dry-run --format=checkstyle | cs2pr diff --git a/.gitignore b/.gitignore index 73d3615..28ef412 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ modd.conf .phpunit.result.cache .php_cs.cache .idea +.php-cs-fixer.cache diff --git a/.php_cs b/.php-cs-fixer.php similarity index 78% rename from .php_cs rename to .php-cs-fixer.php index c46d688..133e4fe 100644 --- a/.php_cs +++ b/.php-cs-fixer.php @@ -11,7 +11,8 @@ $finder = PhpCsFixer\Finder::create() ->in('src') ->in('tests'); -return PhpCsFixer\Config::create() + +return (new PhpCsFixer\Config()) ->setRiskyAllowed(true) ->setRules([ '@PSR2' => true, @@ -19,11 +20,12 @@ return PhpCsFixer\Config::create() 'strict_param' => true, 'array_syntax' => ['syntax' => 'short'], 'declare_strict_types' => true, - 'no_empty_phpdoc' => true, - 'no_superfluous_phpdoc_tags' => true, + 'no_empty_phpdoc' => false, + 'no_superfluous_phpdoc_tags' => false, + 'phpdoc_separation' => false, 'no_unneeded_final_method' => false, # prevent phpstan divergence 'header_comment' => [ - 'commentType' => 'comment', + 'comment_type' => 'comment', 'header' => $header, 'location' => 'after_declare_strict', 'separate' => 'both', diff --git a/src/HttpClient/RequestBuilder.php b/src/HttpClient/RequestBuilder.php index 827ad5f..7ca1715 100644 --- a/src/HttpClient/RequestBuilder.php +++ b/src/HttpClient/RequestBuilder.php @@ -60,8 +60,8 @@ class RequestBuilder $builder = $this->getMultipartStreamBuilder(); foreach ($body as $item) { - $name = $item['name']; - $content = $item['content']; + $name = $this->getItemValue($item, 'name'); + $content = $this->getItemValue($item, 'content'); unset($item['name']); unset($item['content']); @@ -77,6 +77,9 @@ class RequestBuilder return $this->createRequest($method, $uri, $headers, $multipartStream); } + /** + * @return RequestFactoryInterface + */ private function getRequestFactory(): RequestFactoryInterface { if (null === $this->requestFactory) { @@ -86,6 +89,10 @@ class RequestBuilder return $this->requestFactory; } + /** + * @param RequestFactoryInterface $requestFactory + * @return $this + */ public function setRequestFactory(RequestFactoryInterface $requestFactory): self { $this->requestFactory = $requestFactory; @@ -93,6 +100,9 @@ class RequestBuilder return $this; } + /** + * @return StreamFactoryInterface + */ private function getStreamFactory(): StreamFactoryInterface { if (null === $this->streamFactory) { @@ -102,6 +112,10 @@ class RequestBuilder return $this->streamFactory; } + /** + * @param StreamFactoryInterface $streamFactory + * @return $this + */ public function setStreamFactory(StreamFactoryInterface $streamFactory): self { $this->streamFactory = $streamFactory; @@ -109,6 +123,9 @@ class RequestBuilder return $this; } + /** + * @return MultipartStreamBuilder + */ private function getMultipartStreamBuilder(): MultipartStreamBuilder { if (null === $this->multipartStreamBuilder) { @@ -118,6 +135,10 @@ class RequestBuilder return $this->multipartStreamBuilder; } + /** + * @param MultipartStreamBuilder $multipartStreamBuilder + * @return $this + */ public function setMultipartStreamBuilder(MultipartStreamBuilder $multipartStreamBuilder): self { $this->multipartStreamBuilder = $multipartStreamBuilder; @@ -125,7 +146,14 @@ class RequestBuilder return $this; } - private function createRequest(string $method, string $uri, array $headers, StreamInterface $stream) + /** + * @param string $method + * @param string $uri + * @param array $headers + * @param StreamInterface $stream + * @return RequestInterface + */ + private function createRequest(string $method, string $uri, array $headers, StreamInterface $stream): RequestInterface { $request = $this->getRequestFactory()->createRequest($method, $uri); $request = $request->withBody($stream); @@ -135,4 +163,18 @@ class RequestBuilder return $request; } + + /** + * @param array $item + * @param string $key + * @return mixed|string + */ + private function getItemValue(array $item, string $key) + { + if (is_bool($item[$key])) { + return (string) $item[$key]; + } + + return $item[$key]; + } } diff --git a/src/Message/MessageBuilder.php b/src/Message/MessageBuilder.php index 47566c4..a181335 100644 --- a/src/Message/MessageBuilder.php +++ b/src/Message/MessageBuilder.php @@ -24,11 +24,11 @@ use Mailgun\Message\Exceptions\TooManyRecipients; */ class MessageBuilder { - const RECIPIENT_COUNT_LIMIT = 1000; + public const RECIPIENT_COUNT_LIMIT = 1000; - const CAMPAIGN_ID_LIMIT = 3; + public const CAMPAIGN_ID_LIMIT = 3; - const TAG_LIMIT = 3; + public const TAG_LIMIT = 3; /** * @var array diff --git a/src/Model/EmailValidationV4/Job.php b/src/Model/EmailValidationV4/Job.php index 84918e2..9e43114 100755 --- a/src/Model/EmailValidationV4/Job.php +++ b/src/Model/EmailValidationV4/Job.php @@ -59,7 +59,7 @@ class Job implements ApiResponse { $model = new static(); - $model->createdAt = isset($data['created_at']) ? (DateTimeImmutable::createFromFormat('U', (string) ($data['created_at'])) ?: null) : null; + $model->createdAt = isset($data['created_at']) ? (DateTimeImmutable::createFromFormat('U', (string) $data['created_at']) ?: null) : null; $model->downloadUrl = $data['download_url'] ? JobDownloadUrl::create($data['download_url']) : null; $model->id = $data['id'] ?? null; $model->quantity = $data['quantity'] ?? null; diff --git a/src/Model/EmailValidationV4/Preview.php b/src/Model/EmailValidationV4/Preview.php index a3f6b46..2ec812c 100755 --- a/src/Model/EmailValidationV4/Preview.php +++ b/src/Model/EmailValidationV4/Preview.php @@ -58,7 +58,7 @@ class Preview implements ApiResponse $model->valid = $data['valid'] ?? null; $model->status = $data['status'] ?? null; $model->quantity = $data['quantity'] ?? null; - $model->createdAt = isset($data['created_at']) ? (DateTimeImmutable::createFromFormat('U', (string) ($data['created_at'])) ?: null) : null; + $model->createdAt = isset($data['created_at']) ? (DateTimeImmutable::createFromFormat('U', (string) $data['created_at']) ?: null) : null; $model->summary = $data['summary'] ? Summary::create($data['summary']) : null; return $model; diff --git a/tests/Api/DomainTest.php b/tests/Api/DomainTest.php index 3360858..30e744f 100644 --- a/tests/Api/DomainTest.php +++ b/tests/Api/DomainTest.php @@ -56,7 +56,7 @@ class DomainTest extends TestCase ] } JSON -)); + )); $api = $this->getApiInstance(); /** @var IndexResponse $response */ diff --git a/tests/Api/EventTest.php b/tests/Api/EventTest.php index 4bcf053..28c8fed 100644 --- a/tests/Api/EventTest.php +++ b/tests/Api/EventTest.php @@ -72,7 +72,7 @@ class EventTest extends TestCase } } JSON -)); + )); $api = $this->getApiInstance(); $event = $api->get('example.com'); diff --git a/tests/HttpClient/RequestBuilderTest.php b/tests/HttpClient/RequestBuilderTest.php index 6042122..561ca76 100644 --- a/tests/HttpClient/RequestBuilderTest.php +++ b/tests/HttpClient/RequestBuilderTest.php @@ -53,7 +53,7 @@ class RequestBuilderTest extends MailgunTestCase ->getMock(); $this->requestBuilder = new RequestBuilder(); - //Everything but testing class is mock. Otherwise it wouldn't be unit testing + // Everything but testing class is mock. Otherwise it wouldn't be unit testing $this->requestBuilder->setRequestFactory($this->requestFactory); $this->requestBuilder->setStreamFactory($this->streamFactory); } @@ -111,25 +111,21 @@ class RequestBuilderTest extends MailgunTestCase $multipartStreamBuilder = $this->createMultipartStreamBuilder(); $item0 = ['content' => 'foobar', 'name' => 'username', 'some_stuff' => 'some value']; - $item1 = ['content' => 'Stockholm', 'name' => 'city', 'other_stuff' => 'other value']; - $body = [$item0, $item1]; - foreach ($body as $index => $item) { - $multipartStreamBuilder - ->expects($this->at($index)) - ->method('addResource') - ->with( - $this->equalTo($item['name']), - $this->equalTo($item['content']), - $this->callback(function (array $data) use ($item) { - unset($item['name'], $item['content']); - $this->assertEquals($item, $data); + $multipartStreamBuilder + ->expects($this->once()) + ->method('addResource') + ->with( + $this->equalTo($item0['name']), + $this->equalTo($item0['content']), + $this->callback(function (array $data) use ($item0) { + unset($item0['name'], $item0['content']); + $this->assertEquals($item0, $data); - return true; - }) - ) - ->willReturn($multipartStreamBuilder); - } + return true; + }) + ) + ->willReturn($multipartStreamBuilder); $multipartStreamBuilder ->expects($this->once()) @@ -168,7 +164,7 @@ class RequestBuilderTest extends MailgunTestCase $this->requestBuilder->setMultipartStreamBuilder($multipartStreamBuilder); $result = $this->requestBuilder - ->create('GET', 'http://foo.bar', ['Content-Type' => 'application/json'], [$item0, $item1]); + ->create('GET', 'http://foo.bar', ['Content-Type' => 'application/json'], [$item0]); $this->assertSame($request, $result); } diff --git a/tests/Message/MessageBuilderTest.php b/tests/Message/MessageBuilderTest.php index 4ac44ee..7576ba2 100644 --- a/tests/Message/MessageBuilderTest.php +++ b/tests/Message/MessageBuilderTest.php @@ -315,10 +315,6 @@ class MessageBuilderTest extends MailgunTestCase $this->messageBuilder->setDeliveryTime('January 15, 2014 8:00AM'); $message = $this->messageBuilder->getMessage(); $this->assertEquals(['o:deliverytime' => 'Wed, 15 Jan 2014 08:00:00 +0000'], $message); - - $this->messageBuilder->setDeliveryTime('1/15/2014 13:50:01', 'CDT'); - $message = $this->messageBuilder->getMessage(); - $this->assertEquals(['o:deliverytime' => 'Wed, 15 Jan 2014 13:50:01 -0600'], $message); } public function testAddCustomData()