mirror of
https://github.com/retailcrm/mailgun-php.git
synced 2024-11-29 00:25:37 +03:00
Update php-cs-fixer. Fix code style issues (#833)
Signed-off-by: Alexander Mykhailenko <mihaskep@gmail.com> Update php-cs-fixer. Fix code style issues Signed-off-by: Alexander Mykhailenko <mihaskep@gmail.com> Fix tests Signed-off-by: Alexander Mykhailenko <mihaskep@gmail.com> Fix test Signed-off-by: Alexander Mykhailenko <mihaskep@gmail.com> Prevent Uncaught InvalidArgumentException Signed-off-by: Alexander Mykhailenko <mihaskep@gmail.com>
This commit is contained in:
parent
c04197362b
commit
be083541bf
2
.github/workflows/static.yml
vendored
2
.github/workflows/static.yml
vendored
@ -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
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -8,3 +8,4 @@ modd.conf
|
||||
.phpunit.result.cache
|
||||
.php_cs.cache
|
||||
.idea
|
||||
.php-cs-fixer.cache
|
||||
|
@ -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',
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -56,7 +56,7 @@ class DomainTest extends TestCase
|
||||
]
|
||||
}
|
||||
JSON
|
||||
));
|
||||
));
|
||||
|
||||
$api = $this->getApiInstance();
|
||||
/** @var IndexResponse $response */
|
||||
|
@ -72,7 +72,7 @@ class EventTest extends TestCase
|
||||
}
|
||||
}
|
||||
JSON
|
||||
));
|
||||
));
|
||||
|
||||
$api = $this->getApiInstance();
|
||||
$event = $api->get('example.com');
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user