Skip to content

Commit

Permalink
Drop support for PHP 7.x
Browse files Browse the repository at this point in the history
  • Loading branch information
rpkamp committed Mar 2, 2024
1 parent 1f6e713 commit a18c81f
Show file tree
Hide file tree
Showing 20 changed files with 48 additions and 276 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ["7.2", "7.3", "7.4", "8.0"]
composer-flags: ["", "--prefer-lowest"]
env:
COMPOSER_ROOT_VERSION: dev-master
php: ["8.0", "8.1", "8.2", "8.3"]

steps:
- uses: actions/checkout@v2

Expand All @@ -36,7 +34,7 @@ jobs:
coverage: pcov

- name: Install dependencies
run: composer update ${{ matrix.composer-flags }}
run: composer update

- name: Run tests
run: make test
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"phpstan/phpstan": "^0.12.64",
"pdepend/pdepend": "^2.5",
"nyholm/psr7": "^1.2",
"doctrine/coding-standard": "^8.0",
"doctrine/coding-standard": "^9.0",
"php-parallel-lint/php-parallel-lint": "^1.2",
"egulias/email-validator": "^2.1.23",
"symfony/mailer": "^5.0"
Expand Down
5 changes: 3 additions & 2 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
<!-- require declare(strict_types=1) in each file, with 0 empty lines above and 1 empty line below -->
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
<properties>
<property name="newlinesCountBetweenOpenTagAndDeclare" value="1" />
<!-- <property name="newlinesCountBetweenOpenTagAndDeclare" value="1" /> -->
<property name="linesCountBeforeDeclare" value="0" />
<property name="spacesCountAroundEqualsSign" value="0" />
<property name="newlinesCountAfterDeclare" value="2" />
<!-- <property name="newlinesCountAfterDeclare" value="2" /> -->
</properties>
</rule>

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

declare(strict_types=1);

namespace rpkamp\Mailhog;
Expand All @@ -25,42 +24,19 @@

class MailhogClient
{
/**
* @var ClientInterface
*/
private $httpClient;

/**
* @var RequestFactoryInterface
*/
private $requestFactory;

/**
* @var StreamFactoryInterface
*/
private $streamFactory;

/**
* @var string
*/
private $baseUri;

public function __construct(
ClientInterface $client,
RequestFactoryInterface $requestFactory,
StreamFactoryInterface $streamFactory,
string $baseUri
private ClientInterface $httpClient,
private RequestFactoryInterface $requestFactory,
private StreamFactoryInterface $streamFactory,
private string $baseUri
) {
$this->httpClient = $client;
$this->requestFactory = $requestFactory;
$this->streamFactory = $streamFactory;
$this->baseUri = rtrim($baseUri, '/');
}

/**
* @return Generator|Message[]
*/
public function findAllMessages(int $limit = 50)
public function findAllMessages(int $limit = 50): Generator
{
$start = 0;
while (true) {
Expand Down
14 changes: 1 addition & 13 deletions src/Message/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,8 @@

class Contact
{
/**
* @var string
*/
public $emailAddress;

/**
* @var string|null
*/
public $name;

public function __construct(string $emailAddress, ?string $name = null)
public function __construct(private string $emailAddress, private string |null $name = null)
{
$this->emailAddress = $emailAddress;
$this->name = $name;
}

public static function fromString(string $contact): Contact
Expand Down
8 changes: 1 addition & 7 deletions src/Message/ContactCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,11 @@
*/
class ContactCollection implements Countable, IteratorAggregate
{
/**
* @var array|Contact[]
*/
private $contacts;

/**
* @param Contact[] $contacts
*/
public function __construct(array $contacts)
public function __construct(private array $contacts)
{
$this->contacts = $contacts;
}

public static function fromString(string $contacts): ContactCollection
Expand Down
11 changes: 2 additions & 9 deletions src/Message/Headers.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

declare(strict_types=1);

namespace rpkamp\Mailhog\Message;
Expand All @@ -9,17 +8,11 @@

class Headers
{
/**
* @var array<string, string> $headers
*/
private $headers;

/**
* @param array<string, string> $headers
*/
public function __construct(array $headers)
public function __construct(private array $headers)
{
$this->headers = $headers;
}

/**
Expand Down Expand Up @@ -51,7 +44,7 @@ private static function fromRawHeaders(array $rawHeaders): self

$decoded = iconv_mime_decode($header[0]);

$headers[strtolower($name)] = $decoded ? $decoded : $header[0];
$headers[strtolower($name)] = $decoded ?: $header[0];
}

return new Headers($headers);
Expand Down
73 changes: 9 additions & 64 deletions src/Message/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,64 +10,19 @@

class Message
{
/**
* @var string
*/
public $messageId;

/**
* @var Contact
*/
public $sender;

/**
* @var ContactCollection
*/
public $recipients;

/**
* @var ContactCollection
*/
public $ccRecipients;

/**
* @var ContactCollection
*/
public $bccRecipients;

/**
* @var string
*/
public $subject;

/**
* @var string
*/
public $body;

/**
* @var Attachment[]
*/
public $attachments;

/**
* @var Headers
*/
public $headers;

/**
* @param Attachment[] $attachments
*/
public function __construct(
string $messageId,
Contact $sender,
ContactCollection $recipients,
ContactCollection $ccRecipients,
ContactCollection $bccRecipients,
string $subject,
string $body,
array $attachments,
Headers $headers
public string $messageId,
public Contact $sender,
public ContactCollection $recipients,
public ContactCollection $ccRecipients,
public ContactCollection $bccRecipients,
public string $subject,
public string $body,
public array $attachments,
public Headers $headers
) {
foreach ($attachments as $i => $attachment) {
if (!$attachment instanceof Attachment) {
Expand All @@ -81,15 +36,5 @@ public function __construct(
);
}
}

$this->messageId = $messageId;
$this->sender = $sender;
$this->recipients = $recipients;
$this->ccRecipients = $ccRecipients;
$this->bccRecipients = $bccRecipients;
$this->subject = $subject;
$this->body = $body;
$this->attachments = $attachments;
$this->headers = $headers;
}
}
25 changes: 5 additions & 20 deletions src/Message/Mime/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,10 @@

class Attachment
{
/**
* @var string
*/
public $filename;

/**
* @var string
*/
public $mimeType;

/**
* @var string
*/
public $content;

public function __construct(string $filename, string $mimeType, string $content)
{
$this->filename = $filename;
$this->mimeType = $mimeType;
$this->content = $content;
public function __construct(
public string $filename,
public string $mimeType,
public string $content,
) {
}
}
40 changes: 5 additions & 35 deletions src/Message/Mime/MimePart.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,13 @@

class MimePart
{
/**
* @var string
*/
private $contentType;

/**
* @var string|null
*/
private $contentTransferEncoding;

/**
* @var bool
*/
private $isAttachment;

/**
* @var string|null
*/
private $filename;

/**
* @var string
*/
private $body;

private function __construct(
string $contentType,
?string $contentTransferEncoding,
bool $isAttachment,
?string $filename,
string $body
private string $contentType,
private string |null $contentTransferEncoding,
private bool $isAttachment,
private string |null $filename,
private string $body
) {
$this->contentType = $contentType;
$this->contentTransferEncoding = $contentTransferEncoding;
$this->isAttachment = $isAttachment;
$this->filename = $filename;
$this->body = $body;
}

/**
Expand Down
10 changes: 2 additions & 8 deletions src/Message/Mime/MimePartCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,10 @@
class MimePartCollection
{
/**
* @var MimePart[]
* @param array<MimePart> $mimeParts
*/
private $mimeParts;

/**
* @param MimePart[] $mimeParts
*/
private function __construct(array $mimeParts)
private function __construct(private array $mimeParts)
{
$this->mimeParts = $mimeParts;
}

/**
Expand Down
14 changes: 1 addition & 13 deletions src/Specification/AndSpecification.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,8 @@

final class AndSpecification implements Specification
{
/**
* @var Specification
*/
private $left;

/**
* @var Specification
*/
private $right;

public function __construct(Specification $left, Specification $right)
public function __construct(private Specification $left, private Specification $right)
{
$this->left = $left;
$this->right = $right;
}

public static function all(Specification $specification, Specification ...$other): Specification
Expand Down
8 changes: 1 addition & 7 deletions src/Specification/AttachmentSpecification.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,8 @@

final class AttachmentSpecification implements Specification
{
/**
* @var string
*/
private $filename;

public function __construct(string $filename)
public function __construct(private string $filename)
{
$this->filename = $filename;
}

public function isSatisfiedBy(Message $message): bool
Expand Down
Loading

0 comments on commit a18c81f

Please sign in to comment.