Skip to content

Commit

Permalink
Add PHP 8.2 support, drop PHP 8.0 support (#553)
Browse files Browse the repository at this point in the history
  • Loading branch information
Slamdunk authored Jan 9, 2023
1 parent 1a0a86e commit a238641
Show file tree
Hide file tree
Showing 17 changed files with 50 additions and 161 deletions.
30 changes: 15 additions & 15 deletions .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ jobs:
strategy:
matrix:
php-version:
- "8.0"
- "8.1"

steps:
- name: "Checkout"
uses: "actions/checkout@v2"
uses: "actions/checkout@v3"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
Expand All @@ -33,7 +33,7 @@ jobs:
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: "Cache dependencies"
uses: actions/cache@v2
uses: "actions/cache@v3"
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ matrix.dependencies }}-composer-${{ hashFiles('**/composer.json') }}
Expand Down Expand Up @@ -62,8 +62,8 @@ jobs:
strategy:
matrix:
php-version:
- "8.0"
- "8.1"
- "8.2"

env:
IMAP_SERVER_NAME: dovecot.travis.dev
Expand All @@ -74,7 +74,7 @@ jobs:

steps:
- name: "Checkout"
uses: "actions/checkout@v2"
uses: "actions/checkout@v3"

- name: "Start IMAPd services"
run: "sh .github/dovecot_install.sh"
Expand All @@ -94,7 +94,7 @@ jobs:
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: "Cache dependencies"
uses: actions/cache@v2
uses: "actions/cache@v3"
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ matrix.dependencies }}-composer-${{ hashFiles('**/composer.json') }}
Expand All @@ -104,17 +104,17 @@ jobs:
run: "composer update --no-interaction --no-progress"

- name: "Run tests without coverage"
if: ${{ matrix.php-version != '8.0' }}
if: ${{ matrix.php-version != '8.1' }}
timeout-minutes: 3
run: "vendor/bin/phpunit --no-coverage --no-logging"

- name: "Run tests with coverage"
if: ${{ matrix.php-version == '8.0' }}
if: ${{ matrix.php-version == '8.1' }}
timeout-minutes: 3
run: "vendor/bin/phpunit --no-coverage --coverage-clover=coverage.xml"

- name: "Send code coverage report to Codecov.io"
if: ${{ matrix.php-version == '8.0' }}
if: ${{ matrix.php-version == '8.1' }}
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand All @@ -129,11 +129,11 @@ jobs:
strategy:
matrix:
php-version:
- "8.0"
- "8.1"

steps:
- name: "Checkout"
uses: "actions/checkout@v2"
uses: "actions/checkout@v3"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
Expand All @@ -146,7 +146,7 @@ jobs:
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: "Cache dependencies"
uses: actions/cache@v2
uses: "actions/cache@v3"
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ matrix.dependencies }}-composer-${{ hashFiles('**/composer.json') }}
Expand All @@ -166,11 +166,11 @@ jobs:
strategy:
matrix:
php-version:
- "8.0"
- "8.1"

steps:
- name: "Checkout"
uses: "actions/checkout@v2"
uses: "actions/checkout@v3"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
Expand All @@ -184,7 +184,7 @@ jobs:
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: "Cache dependencies"
uses: actions/cache@v2
uses: "actions/cache@v3"
with:
path: ${{ steps.composercache.outputs.dir }}
key: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ matrix.dependencies }}-composer-${{ hashFiles('**/composer.json') }}
Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PHP_DOCKER_VERSION := thecodingmachine/php:8.0-v4-cli
PHP_DOCKER_VERSION := thecodingmachine/php:8.1-v4-cli
PHP_BIN := docker run -it --rm \
--network=ddeboer_imap_network \
--env IMAP_SERVER_NAME=ddeboer_imap_server \
Expand All @@ -15,6 +15,7 @@ all: csfix static-analysis test

vendor: composer.json
$(PHP_BIN) composer update
$(PHP_BIN) composer bump
touch vendor

.PHONY: csfix
Expand All @@ -23,7 +24,7 @@ csfix: vendor

.PHONY: static-analysis
static-analysis: vendor
$(PHP_BIN) vendor/bin/phpstan analyse
$(PHP_BIN) vendor/bin/phpstan analyse $(PHPSTAN_FLAGS)

wait-for-it:
wget -O wait-for-it "https://raw.githubusercontent.com/vishnubob/wait-for-it/master/wait-for-it.sh"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

A PHP IMAP library to read and process e-mails over IMAP protocol, built with robust Object-Oriented architecture.

This library requires PHP >= 7.4 with [IMAP](https://www.php.net/manual/en/book.imap.php),
This library requires PHP >= 8.1 with [IMAP](https://www.php.net/manual/en/book.imap.php),
[iconv](https://www.php.net/manual/en/book.iconv.php) and
[Multibyte String](https://www.php.net/manual/en/book.mbstring.php) extensions installed.

Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@
}
],
"require": {
"php": "^8.0.1",
"php": "~8.1.0 || ~8.2.0",
"ext-iconv": "*",
"ext-imap": "*",
"ext-mbstring": "*"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.11",
"laminas/laminas-mail": "^2.17",
"phpstan/phpstan": "^1.8.4",
"phpstan/phpstan-phpunit": "^1.1.1",
"phpstan/phpstan-strict-rules": "^1.4.3",
"phpunit/phpunit": "^9.5.24"
"friendsofphp/php-cs-fixer": "^3.13.2",
"laminas/laminas-mail": "^2.21.1",
"phpstan/phpstan": "^1.9.8",
"phpstan/phpstan-phpunit": "^1.3.3",
"phpstan/phpstan-strict-rules": "^1.4.4",
"phpunit/phpunit": "^9.5.27"
},
"autoload": {
"psr-4": {
Expand Down
25 changes: 0 additions & 25 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,30 +1,10 @@
parameters:
ignoreErrors:
-
message: "#^Class IMAP\\\\Connection not found\\.$#"
count: 1
path: src/ImapResource.php

-
message: "#^If condition is always false\\.$#"
count: 1
path: src/ImapResource.php

-
message: "#^Instanceof between resource and IMAP\\\\Connection will always evaluate to false\\.$#"
count: 1
path: src/ImapResource.php

-
message: "#^Parameter \\$resource of method Ddeboer\\\\Imap\\\\ImapResource\\:\\:__construct\\(\\) has invalid type IMAP\\\\Connection\\.$#"
count: 1
path: src/ImapResource.php

-
message: "#^Property Ddeboer\\\\Imap\\\\ImapResource\\:\\:\\$resource \\(resource\\) does not accept IMAP\\\\Connection\\|resource\\.$#"
count: 1
path: src/ImapResource.php

-
message: "#^Parameter \\#2 \\$array of function implode expects array\\<string\\>, array\\<int, Ddeboer\\\\Imap\\\\MessageInterface\\|int\\|string\\> given\\.$#"
count: 1
Expand Down Expand Up @@ -160,11 +140,6 @@ parameters:
count: 2
path: tests/ConnectionTest.php

-
message: "#^Parameter \\#1 \\$resource of class Ddeboer\\\\Imap\\\\ImapResource constructor expects IMAP\\\\Connection\\|resource, string given\\.$#"
count: 1
path: tests/ConnectionTest.php

-
message: "#^Call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertArrayHasKey\\(\\) with 'date' and \\*NEVER\\* will always evaluate to true\\.$#"
count: 1
Expand Down
3 changes: 0 additions & 3 deletions src/ConnectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Ddeboer\Imap\Exception\CreateMailboxException;
use Ddeboer\Imap\Exception\DeleteMailboxException;
use Ddeboer\Imap\Exception\InvalidResourceException;
use Ddeboer\Imap\Exception\MailboxDoesNotExistException;

/**
Expand All @@ -31,8 +30,6 @@ public function close(int $flag = 0): bool;

/**
* Check if the connection is still active.
*
* @throws InvalidResourceException If connection was closed
*/
public function ping(): bool;

Expand Down
9 changes: 0 additions & 9 deletions src/Exception/InvalidResourceException.php

This file was deleted.

23 changes: 4 additions & 19 deletions src/ImapResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Ddeboer\Imap;

use Ddeboer\Imap\Exception\InvalidResourceException;
use Ddeboer\Imap\Exception\ReopenMailboxException;
use IMAP\Connection;

Expand All @@ -13,33 +12,21 @@
*/
final class ImapResource implements ImapResourceInterface
{
/**
* @var resource
*/
private $resource;
private Connection $resource;
private ?MailboxInterface $mailbox = null;
private static ?string $lastMailboxUsedCache = null;

/**
* Constructor.
*
* @param Connection|resource $resource
*/
public function __construct($resource, MailboxInterface $mailbox = null)
public function __construct(Connection $resource, MailboxInterface $mailbox = null)
{
$this->resource = $resource;
$this->mailbox = $mailbox;
}

public function getStream()
public function getStream(): Connection
{
if (
!$this->resource instanceof Connection
&& (false === \is_resource($this->resource) || 'imap' !== \get_resource_type($this->resource))
) {
throw new InvalidResourceException('Supplied resource is not a valid imap resource');
}

$this->initMailbox();

return $this->resource;
Expand Down Expand Up @@ -76,10 +63,8 @@ private function initMailbox(): void

/**
* Check whether the current mailbox is open.
*
* @param resource $resource
*/
private static function isMailboxOpen(MailboxInterface $mailbox, $resource): bool
private static function isMailboxOpen(MailboxInterface $mailbox, Connection $resource): bool
{
$currentMailboxName = $mailbox->getFullEncodedName();
if ($currentMailboxName === self::$lastMailboxUsedCache) {
Expand Down
8 changes: 2 additions & 6 deletions src/ImapResourceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@

namespace Ddeboer\Imap;

use Ddeboer\Imap\Exception\InvalidResourceException;
use IMAP\Connection;

interface ImapResourceInterface
{
/**
* Get IMAP resource stream.
*
* @throws InvalidResourceException
*
* @return resource
*/
public function getStream();
public function getStream(): Connection;

/**
* Clear last mailbox used cache.
Expand Down
3 changes: 1 addition & 2 deletions src/Mailbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Ddeboer\Imap;

use DateTimeInterface;
use Ddeboer\Imap\Exception\ImapNumMsgException;
use Ddeboer\Imap\Exception\ImapStatusException;
use Ddeboer\Imap\Exception\InvalidSearchCriteriaException;
Expand Down Expand Up @@ -196,7 +195,7 @@ public function getIterator(): MessageIteratorInterface
return $this->getMessages();
}

public function addMessage(string $message, string $options = null, DateTimeInterface $internalDate = null): bool
public function addMessage(string $message, string $options = null, \DateTimeInterface $internalDate = null): bool
{
$arguments = [
$this->resource->getStream(),
Expand Down
3 changes: 1 addition & 2 deletions src/MailboxInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Ddeboer\Imap;

use DateTimeInterface;
use Ddeboer\Imap\Message\PartInterface;
use Ddeboer\Imap\Search\ConditionInterface;

Expand Down Expand Up @@ -97,7 +96,7 @@ public function getIterator(): MessageIteratorInterface;
/**
* Add a message to the mailbox.
*/
public function addMessage(string $message, string $options = null, DateTimeInterface $internalDate = null): bool;
public function addMessage(string $message, string $options = null, \DateTimeInterface $internalDate = null): bool;

/**
* Returns a tree of threaded message for the current Mailbox.
Expand Down
8 changes: 3 additions & 5 deletions src/Search/AbstractDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Ddeboer\Imap\Search;

use DateTimeInterface;

/**
* Represents a date condition.
*/
Expand All @@ -19,14 +17,14 @@ abstract class AbstractDate implements ConditionInterface
/**
* The date to be used for the condition.
*/
private DateTimeInterface $date;
private \DateTimeInterface $date;

/**
* Constructor.
*
* @param DateTimeInterface $date optional date for the condition
* @param \DateTimeInterface $date optional date for the condition
*/
public function __construct(DateTimeInterface $date, string $dateFormat = 'j-M-Y')
public function __construct(\DateTimeInterface $date, string $dateFormat = 'j-M-Y')
{
$this->date = $date;
$this->dateFormat = $dateFormat;
Expand Down
Loading

0 comments on commit a238641

Please sign in to comment.