Skip to content

Commit

Permalink
Merge pull request #60 from rpkamp/php8.0
Browse files Browse the repository at this point in the history
Drop support for PHP 7.x
  • Loading branch information
rpkamp committed Mar 2, 2024
2 parents 1f6e713 + 4c1eafa commit 6da09c2
Show file tree
Hide file tree
Showing 21 changed files with 65 additions and 301 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.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
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"minimum-stability": "stable",
"require": {
"php": "^7.2 || ^8.0",
"php": "^8.1",
"ext-json": "*",
"ext-iconv": "*",
"php-http/client-implementation": "^1.0",
Expand All @@ -31,12 +31,12 @@
},
"require-dev": {
"phpmd/phpmd": "^2.9.1",
"phpunit/phpunit": "^8.0 || ^9.0 || ^10.0",
"phpunit/phpunit": "^10.0",
"php-http/curl-client": "^2.0",
"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
3 changes: 1 addition & 2 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@
<!-- 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="linesCountBeforeDeclare" value="0" />
<property name="spacesCountAroundEqualsSign" value="0" />
<property name="newlinesCountAfterDeclare" value="2" />
</properties>
</rule>

Expand Down
42 changes: 18 additions & 24 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.3/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<php>
<env name="mailhog_smtp_dsn" value="smtp://localhost:2025" />
<env name="mailhog_api_uri" value="http://localhost:9025" />
</php>

<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>

<testsuites>
<testsuite name="unit">
<directory>tests/unit</directory>
</testsuite>
<testsuite name="integration">
<directory>tests/integration/</directory>
</testsuite>
</testsuites>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true" cacheDirectory=".phpunit.cache">
<php>
<env name="mailhog_smtp_dsn" value="smtp://localhost:2025"/>
<env name="mailhog_api_uri" value="http://localhost:9025"/>
</php>
<testsuites>
<testsuite name="unit">
<directory>tests/unit</directory>
</testsuite>
<testsuite name="integration">
<directory>tests/integration/</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
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,
) {
}
}
Loading

0 comments on commit 6da09c2

Please sign in to comment.