diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b285223..8c38035 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -64,3 +64,24 @@ jobs: - name: Run lint run: composer lint + + phpstan: + runs-on: ubuntu-latest + + name: PHPStan + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.5 + coverage: none + + - name: Install Composer dependencies + uses: ramsey/composer-install@v3 + + - name: Run phpstan + run: composer phpstan diff --git a/composer.json b/composer.json index e42e8af..186e544 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,9 @@ "illuminate/support": "^9.0 || ^10.0 || ^11.0 || ^12.0", "knplabs/gaufrette": "^0.11", "phpunit/phpunit": "^9.5", - "symfony/validator": "^5.4 || ^6.4 || ^7.0" + "symfony/validator": "^5.4 || ^6.4 || ^7.0", + "phpstan/phpstan": "^2.1", + "phpstan/phpstan-phpunit": "^2.0" }, "suggest": { "symfony/validator": "Add validation constraints", @@ -49,6 +51,9 @@ ], "lint": [ "php-cs-fixer fix --ansi" + ], + "phpstan": [ + "phpstan analyse" ] } } diff --git a/phpstan.dist.neon b/phpstan.dist.neon new file mode 100644 index 0000000..30a7c73 --- /dev/null +++ b/phpstan.dist.neon @@ -0,0 +1,10 @@ +includes: + - vendor/phpstan/phpstan-phpunit/extension.neon + - vendor/phpstan/phpstan-phpunit/rules.neon + - vendor/phpstan/phpstan/conf/bleedingEdge.neon + +parameters: + level: 8 + paths: + - src/ + - tests/ diff --git a/src/EmailChecker/Adapter/AgregatorAdapter.php b/src/EmailChecker/Adapter/AgregatorAdapter.php index 67e42be..0b893e8 100644 --- a/src/EmailChecker/Adapter/AgregatorAdapter.php +++ b/src/EmailChecker/Adapter/AgregatorAdapter.php @@ -18,21 +18,18 @@ */ class AgregatorAdapter implements AdapterInterface { + /** + * @var AdapterInterface[] + */ protected $adapters; /** - * Build agregator adapter with a list of adpaters (order matters). + * Build aggregator adapter with a list of adapters (order matters). * - * @param array $adapters List of AdapterInterface objects + * @param AdapterInterface[] $adapters List of AdapterInterface objects */ public function __construct(array $adapters) { - foreach ($adapters as $adapter) { - if (!$adapter instanceof AdapterInterface) { - throw new \InvalidArgumentException('AgregatorAdapter only accept instances of AdapterInterface'); - } - } - $this->adapters = $adapters; } diff --git a/src/EmailChecker/Adapter/ArrayAdapter.php b/src/EmailChecker/Adapter/ArrayAdapter.php index 4de61fd..56f7513 100644 --- a/src/EmailChecker/Adapter/ArrayAdapter.php +++ b/src/EmailChecker/Adapter/ArrayAdapter.php @@ -18,10 +18,13 @@ */ class ArrayAdapter implements AdapterInterface { + /** + * @var string[] + */ protected $domains; /** - * @param array $domains List of throwaway domains + * @param string[] $domains List of throwaway domains */ public function __construct(array $domains) { diff --git a/src/EmailChecker/Adapter/BuiltInAdapter.php b/src/EmailChecker/Adapter/BuiltInAdapter.php index e0a5815..0a598cd 100644 --- a/src/EmailChecker/Adapter/BuiltInAdapter.php +++ b/src/EmailChecker/Adapter/BuiltInAdapter.php @@ -25,13 +25,19 @@ */ class BuiltInAdapter implements AdapterInterface { - protected $domains; + /** + * @var string[]|null + */ + protected $domains = null; public function isThrowawayDomain($domain) { return in_array($domain, $this->getDomains()); } + /** + * @return string[] + */ private function getDomains() { if (null === $this->domains) { diff --git a/src/EmailChecker/Adapter/FileAdapter.php b/src/EmailChecker/Adapter/FileAdapter.php index eae9c0c..f1bbeac 100644 --- a/src/EmailChecker/Adapter/FileAdapter.php +++ b/src/EmailChecker/Adapter/FileAdapter.php @@ -20,6 +20,9 @@ */ class FileAdapter implements AdapterInterface { + /** + * @var string[] + */ protected $domains; /** @@ -27,11 +30,12 @@ class FileAdapter implements AdapterInterface */ public function __construct($filename) { - if (!file_exists($filename)) { + $content = file_get_contents($filename); + if (false === $content) { throw new \InvalidArgumentException(sprintf('File "%s" not found', $filename)); } - $this->domains = Utilities::parseLines(file_get_contents($filename)); + $this->domains = Utilities::parseLines($content); } public function isThrowawayDomain($domain) diff --git a/src/EmailChecker/Adapter/GaufretteAdapter.php b/src/EmailChecker/Adapter/GaufretteAdapter.php index 3625b2d..a7a4d21 100644 --- a/src/EmailChecker/Adapter/GaufretteAdapter.php +++ b/src/EmailChecker/Adapter/GaufretteAdapter.php @@ -21,6 +21,9 @@ */ class GaufretteAdapter implements AdapterInterface { + /** + * @var string[] + */ protected $domains; public function __construct(File $file) diff --git a/src/EmailChecker/Constraints/NotThrowawayEmail.php b/src/EmailChecker/Constraints/NotThrowawayEmail.php index d74c1d1..4a554e6 100644 --- a/src/EmailChecker/Constraints/NotThrowawayEmail.php +++ b/src/EmailChecker/Constraints/NotThrowawayEmail.php @@ -21,6 +21,9 @@ #[\Attribute] class NotThrowawayEmail extends Constraint { + /** + * @var string + */ public $message = 'The domain associated with this email is not valid.'; public function __construct( diff --git a/src/EmailChecker/Constraints/NotThrowawayEmailValidator.php b/src/EmailChecker/Constraints/NotThrowawayEmailValidator.php index a41d741..50a7f2e 100644 --- a/src/EmailChecker/Constraints/NotThrowawayEmailValidator.php +++ b/src/EmailChecker/Constraints/NotThrowawayEmailValidator.php @@ -21,6 +21,9 @@ */ class NotThrowawayEmailValidator extends ConstraintValidator { + /** + * @var EmailChecker + */ protected $emailChecker; public function __construct(?EmailChecker $emailChecker = null) @@ -28,8 +31,17 @@ public function __construct(?EmailChecker $emailChecker = null) $this->emailChecker = $emailChecker ?: new EmailChecker(); } + /** + * @param mixed $value + * + * @return void + */ public function validate($value, Constraint $constraint) { + if (!$constraint instanceof NotThrowawayEmail) { + throw new UnexpectedTypeException($constraint, NotThrowawayEmail::class); + } + if (null === $value || '' === $value) { return; } @@ -38,7 +50,7 @@ public function validate($value, Constraint $constraint) throw new UnexpectedTypeException($value, 'string'); } - if (!$this->emailChecker->isValid($value)) { + if (!$this->emailChecker->isValid((string) $value)) { $this->context->addViolation($constraint->message); } } diff --git a/src/EmailChecker/EmailChecker.php b/src/EmailChecker/EmailChecker.php index 510a86e..3acc4df 100644 --- a/src/EmailChecker/EmailChecker.php +++ b/src/EmailChecker/EmailChecker.php @@ -22,6 +22,9 @@ */ class EmailChecker { + /** + * @var AdapterInterface + */ protected $adapter; /** @@ -29,7 +32,7 @@ class EmailChecker */ public function __construct(?AdapterInterface $adapter = null) { - $this->adapter = $adapter ?: new BuiltInAdapter(); + $this->adapter = $adapter ?? new BuiltInAdapter(); } /** diff --git a/src/EmailChecker/Laravel/EmailCheckerServiceProvider.php b/src/EmailChecker/Laravel/EmailCheckerServiceProvider.php index c0732be..c22bf73 100644 --- a/src/EmailChecker/Laravel/EmailCheckerServiceProvider.php +++ b/src/EmailChecker/Laravel/EmailCheckerServiceProvider.php @@ -22,10 +22,10 @@ */ class EmailCheckerServiceProvider extends ServiceProvider { - protected $app; - /** * Register the factory in the application container. + * + * @return void */ public function register() { @@ -44,6 +44,8 @@ public function register() /** * Bootstrap any application services. + * + * @return void */ public function boot(EmailChecker $checker) { @@ -62,7 +64,7 @@ public function boot(EmailChecker $checker) /** * Get the services provided by the provider. * - * @return array + * @return array */ public function provides() { diff --git a/src/EmailChecker/ThrowawayDomains.php b/src/EmailChecker/ThrowawayDomains.php index b5e84e0..b7e341a 100644 --- a/src/EmailChecker/ThrowawayDomains.php +++ b/src/EmailChecker/ThrowawayDomains.php @@ -15,18 +15,29 @@ * List of built-in throwaway domains read from the resources folder. * * @author Matthieu Moquet + * + * @implements \IteratorAggregate */ class ThrowawayDomains implements \IteratorAggregate, \Countable { + /** + * @var string[] + */ protected $domains; public function __construct() { - $this->domains = Utilities::parseLines(file_get_contents( - __DIR__.'/../../res/throwaway_domains.txt' - )); + $content = file_get_contents(__DIR__.'/../../res/throwaway_domains.txt'); + if (false === $content) { + throw new \LogicException('File "throwaway_domains.txt" not found'); + } + + $this->domains = Utilities::parseLines($content); } + /** + * @return string[] + */ public function toArray() { return $this->domains; diff --git a/src/EmailChecker/Utilities.php b/src/EmailChecker/Utilities.php index e73c52d..60d65a4 100644 --- a/src/EmailChecker/Utilities.php +++ b/src/EmailChecker/Utilities.php @@ -28,14 +28,10 @@ class Utilities * * @param string $email The email address to parse * - * @return array The parts of the email. First the local part, then the domain + * @return array{string, string} The parts of the email. First the local part, then the domain */ public static function parseEmailAddress($email) { - if (!is_string($email)) { - throw new InvalidEmailException(sprintf('Expected a string, received %s', gettype($email))); - } - $pattern = sprintf('/^(?%s)@(?%s)$/iD', self::EMAIL_REGEX_LOCAL, self::EMAIL_REGEX_DOMAIN); if (!preg_match($pattern, $email, $parts)) { @@ -50,7 +46,7 @@ public static function parseEmailAddress($email) * * @param string $content The content to parse * - * @return array Array of cleaned string + * @return array Array of cleaned string */ public static function parseLines($content) { @@ -62,10 +58,9 @@ public static function parseLines($content) $lines = array_map('strtolower', $lines); // Remove empty lines and comments - $lines = array_filter($lines, function ($line) { - return (0 === strlen($line) || '#' === $line[0]) ? false : $line; - }); - - return $lines; + return array_filter( + $lines, + static fn (string $line): bool => 0 !== strlen($line) && '#' !== $line[0], + ); } } diff --git a/tests/EmailChecker/Tests/Adpater/AgregatorAdapterTest.php b/tests/EmailChecker/Tests/Adpater/AgregatorAdapterTest.php index 166c758..60bdda1 100644 --- a/tests/EmailChecker/Tests/Adpater/AgregatorAdapterTest.php +++ b/tests/EmailChecker/Tests/Adpater/AgregatorAdapterTest.php @@ -15,46 +15,36 @@ use EmailChecker\Adapter\AgregatorAdapter; use EmailChecker\Tests\TestCase; -class AgregatorAdapterTest extends TestCase +final class AgregatorAdapterTest extends TestCase { - public function testAllValid() + public function testAllValid(): void { $adapter1 = $this->getAdapterMock(false, 'once'); $adapter2 = $this->getAdapterMock(false, 'once'); - $this->adapter = new AgregatorAdapter([$adapter1, $adapter2]); + $adapter = new AgregatorAdapter([$adapter1, $adapter2]); - $this->assertFalse($this->adapter->isThrowawayDomain('example.org')); + $this->assertFalse($adapter->isThrowawayDomain('example.org')); } - public function testFirstInvalid() + public function testFirstInvalid(): void { $adapter1 = $this->getAdapterMock(true, 'once'); $adapter2 = $this->getAdapterMock(false, 'never'); - $this->adapter = new AgregatorAdapter([$adapter1, $adapter2]); + $adapter = new AgregatorAdapter([$adapter1, $adapter2]); - $this->assertTrue($this->adapter->isThrowawayDomain('example.org')); + $this->assertTrue($adapter->isThrowawayDomain('example.org')); } - public function testSecondInvalid() + public function testSecondInvalid(): void { $adapter1 = $this->getAdapterMock(false, 'once'); $adapter2 = $this->getAdapterMock(true, 'once'); - $this->adapter = new AgregatorAdapter([$adapter1, $adapter2]); + $adapter = new AgregatorAdapter([$adapter1, $adapter2]); - $this->assertTrue($this->adapter->isThrowawayDomain('example.org')); - } - - public function testCheckArrayValuesInstanceOf() - { - $this->expectException(\InvalidArgumentException::class); - - new AgregatorAdapter([ - new \stdClass(), - new \stdClass(), - ]); + $this->assertTrue($adapter->isThrowawayDomain('example.org')); } /** @@ -64,7 +54,7 @@ public function testCheckArrayValuesInstanceOf() * * @return AdapterInterface The mock adapter */ - protected function getAdapterMock($isThrowawayDomain, $call = 'any') + protected function getAdapterMock(bool $isThrowawayDomain, string $call = 'any'): AdapterInterface { $adapter = $this->createMock(AdapterInterface::class); $adapter->expects($this->$call()) diff --git a/tests/EmailChecker/Tests/Adpater/ArrayAdapterTest.php b/tests/EmailChecker/Tests/Adpater/ArrayAdapterTest.php index 08fe90d..52908a3 100644 --- a/tests/EmailChecker/Tests/Adpater/ArrayAdapterTest.php +++ b/tests/EmailChecker/Tests/Adpater/ArrayAdapterTest.php @@ -14,26 +14,26 @@ use EmailChecker\Adapter\ArrayAdapter; use EmailChecker\Tests\TestCase; -class ArrayAdapterTest extends TestCase +final class ArrayAdapterTest extends TestCase { - protected static $throawayDomains = [ + private const DOMAINS = [ 'jetable.org', 'mailjet.org', ]; - protected $adapter; + private ArrayAdapter $adapter; protected function setUp(): void { parent::setUp(); - $this->adapter = new ArrayAdapter(self::$throawayDomains); + $this->adapter = new ArrayAdapter(self::DOMAINS); } /** * @dataProvider throwawayDomains */ - public function testThrowawayDomains($domain) + public function testThrowawayDomains(string $domain): void { $this->assertTrue($this->adapter->isThrowawayDomain($domain)); } @@ -41,12 +41,12 @@ public function testThrowawayDomains($domain) /** * @dataProvider notThrowawayDomains */ - public function testNotThrowawayDomains($domain) + public function testNotThrowawayDomains(string $domain): void { $this->assertFalse($this->adapter->isThrowawayDomain($domain)); } - public static function throwawayDomains() + public static function throwawayDomains(): iterable { return [ ['jetable.org'], @@ -54,7 +54,7 @@ public static function throwawayDomains() ]; } - public static function notThrowawayDomains() + public static function notThrowawayDomains(): iterable { return [ ['gmail.com'], diff --git a/tests/EmailChecker/Tests/Adpater/BuiltInAdapterTest.php b/tests/EmailChecker/Tests/Adpater/BuiltInAdapterTest.php index 407f9a0..6b9152c 100644 --- a/tests/EmailChecker/Tests/Adpater/BuiltInAdapterTest.php +++ b/tests/EmailChecker/Tests/Adpater/BuiltInAdapterTest.php @@ -14,9 +14,9 @@ use EmailChecker\Adapter\BuiltInAdapter; use EmailChecker\Tests\TestCase; -class BuiltInAdapterTest extends TestCase +final class BuiltInAdapterTest extends TestCase { - protected $adapter; + private BuiltInAdapter $adapter; protected function setUp(): void { @@ -28,12 +28,12 @@ protected function setUp(): void /** * @dataProvider throwawayDomains */ - public function testThrowawayDomains($domain) + public function testThrowawayDomains(string $domain): void { $this->assertTrue($this->adapter->isThrowawayDomain($domain)); } - public static function throwawayDomains() + public static function throwawayDomains(): iterable { // List of some of the built-in throwaway domains return [ diff --git a/tests/EmailChecker/Tests/Adpater/FileAdapterTest.php b/tests/EmailChecker/Tests/Adpater/FileAdapterTest.php index ab086b4..fa683b3 100644 --- a/tests/EmailChecker/Tests/Adpater/FileAdapterTest.php +++ b/tests/EmailChecker/Tests/Adpater/FileAdapterTest.php @@ -14,9 +14,9 @@ use EmailChecker\Adapter\FileAdapter; use EmailChecker\Tests\TestCase; -class FileAdapterTest extends TestCase +final class FileAdapterTest extends TestCase { - protected $adapter; + private FileAdapter $adapter; protected function setUp(): void { @@ -28,7 +28,7 @@ protected function setUp(): void /** * @dataProvider throwawayDomains */ - public function testThrowawayDomains($domain) + public function testThrowawayDomains(string $domain): void { $this->assertTrue($this->adapter->isThrowawayDomain($domain)); } @@ -36,12 +36,12 @@ public function testThrowawayDomains($domain) /** * @dataProvider notThrowawayDomains */ - public function testNotThrowawayDomains($domain) + public function testNotThrowawayDomains(string $domain): void { $this->assertFalse($this->adapter->isThrowawayDomain($domain)); } - public static function throwawayDomains() + public static function throwawayDomains(): iterable { return [ ['jetable.org'], @@ -51,7 +51,7 @@ public static function throwawayDomains() ]; } - public static function notThrowawayDomains() + public static function notThrowawayDomains(): iterable { return [ ['gmail.com'], diff --git a/tests/EmailChecker/Tests/Adpater/GaufretteAdapterTest.php b/tests/EmailChecker/Tests/Adpater/GaufretteAdapterTest.php index b3d71a8..13b30eb 100644 --- a/tests/EmailChecker/Tests/Adpater/GaufretteAdapterTest.php +++ b/tests/EmailChecker/Tests/Adpater/GaufretteAdapterTest.php @@ -17,9 +17,9 @@ use Gaufrette\File; use Gaufrette\Filesystem; -class GaufretteAdapterTest extends TestCase +final class GaufretteAdapterTest extends TestCase { - protected $adapter; + private GaufretteAdapter $adapter; protected function setUp(): void { @@ -34,7 +34,7 @@ protected function setUp(): void /** * @dataProvider throwawayDomains */ - public function testThrowawayDomains($domain) + public function testThrowawayDomains(string $domain): void { $this->assertTrue($this->adapter->isThrowawayDomain($domain)); } @@ -42,12 +42,12 @@ public function testThrowawayDomains($domain) /** * @dataProvider notThrowawayDomains */ - public function testNotThrowawayDomains($domain) + public function testNotThrowawayDomains(string $domain): void { $this->assertFalse($this->adapter->isThrowawayDomain($domain)); } - public static function throwawayDomains() + public static function throwawayDomains(): iterable { return [ ['jetable.org'], @@ -57,7 +57,7 @@ public static function throwawayDomains() ]; } - public static function notThrowawayDomains() + public static function notThrowawayDomains(): iterable { return [ ['gmail.com'], diff --git a/tests/EmailChecker/Tests/Constraint/NotThrowawayEmailValidatorTest.php b/tests/EmailChecker/Tests/Constraint/NotThrowawayEmailValidatorTest.php index ae8ba36..7c33250 100644 --- a/tests/EmailChecker/Tests/Constraint/NotThrowawayEmailValidatorTest.php +++ b/tests/EmailChecker/Tests/Constraint/NotThrowawayEmailValidatorTest.php @@ -13,14 +13,16 @@ use EmailChecker\Constraints\NotThrowawayEmail; use EmailChecker\Constraints\NotThrowawayEmailValidator; +use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Symfony\Component\Validator\Context\ExecutionContextInterface; use Symfony\Component\Validator\Exception\UnexpectedTypeException; -class NotThrowawayEmailValidatorTest extends TestCase +final class NotThrowawayEmailValidatorTest extends TestCase { - protected $context; - protected $validator; + /** @var ExecutionContextInterface&MockObject */ + private MockObject $context; + private NotThrowawayEmailValidator $validator; protected function setUp(): void { @@ -31,15 +33,7 @@ protected function setUp(): void $this->validator->initialize($this->context); } - protected function tearDown(): void - { - parent::tearDown(); - - $this->context = null; - $this->validator = null; - } - - public function testNullIsValid() + public function testNullIsValid(): void { $this->context->expects($this->never()) ->method('addViolation'); @@ -47,7 +41,7 @@ public function testNullIsValid() $this->validator->validate(null, new NotThrowawayEmail()); } - public function testEmptyStringIsValid() + public function testEmptyStringIsValid(): void { $this->context->expects($this->never()) ->method('addViolation'); @@ -55,7 +49,7 @@ public function testEmptyStringIsValid() $this->validator->validate('', new NotThrowawayEmail()); } - public function testExpectsStringCompatibleType() + public function testExpectsStringCompatibleType(): void { $this->expectException(UnexpectedTypeException::class); @@ -65,7 +59,7 @@ public function testExpectsStringCompatibleType() /** * @dataProvider getValidEmails */ - public function testValidEmails($email) + public function testValidEmails(string $email): void { $this->context->expects($this->never()) ->method('addViolation'); @@ -73,7 +67,7 @@ public function testValidEmails($email) $this->validator->validate($email, new NotThrowawayEmail()); } - public function getValidEmails() + public function getValidEmails(): iterable { return [ ['matthieu@moquet.com'], @@ -84,7 +78,7 @@ public function getValidEmails() /** * @dataProvider getInvalidEmails */ - public function testInvalidEmails($email) + public function testInvalidEmails(string $email): void { $constraint = new NotThrowawayEmail([ 'message' => 'myMessage', @@ -97,7 +91,7 @@ public function testInvalidEmails($email) $this->validator->validate($email, $constraint); } - public function getInvalidEmails() + public function getInvalidEmails(): iterable { return [ // Invalid emails diff --git a/tests/EmailChecker/Tests/EmailCheckerTest.php b/tests/EmailChecker/Tests/EmailCheckerTest.php index 1d1d057..f9b3ab1 100644 --- a/tests/EmailChecker/Tests/EmailCheckerTest.php +++ b/tests/EmailChecker/Tests/EmailCheckerTest.php @@ -14,33 +14,33 @@ use EmailChecker\Adapter\AdapterInterface; use EmailChecker\EmailChecker; -class EmailCheckerTest extends TestCase +final class EmailCheckerTest extends TestCase { - public function testEmailIsValid() + public function testEmailIsValid(): void { $adapter = $this->createMock(AdapterInterface::class); - $adapter->expects($this->any()) + $adapter ->method('isThrowawayDomain') - ->will($this->returnValue(false)); + ->willReturn(false); $checker = new EmailChecker($adapter); $this->assertTrue($checker->isValid('foo@bar.org')); } - public function testEmailIsNotValid() + public function testEmailIsNotValid(): void { $adapter = $this->createMock(AdapterInterface::class); - $adapter->expects($this->any()) + $adapter ->method('isThrowawayDomain') - ->will($this->returnValue(true)); + ->willReturn(true); $checker = new EmailChecker($adapter); $this->assertFalse($checker->isValid('foo@bar.org')); } - public function testMalformattedEmail() + public function testMalformattedEmail(): void { $adapter = $this->createMock(AdapterInterface::class); $checker = new EmailChecker($adapter); diff --git a/tests/EmailChecker/Tests/TestCase.php b/tests/EmailChecker/Tests/TestCase.php index c99275a..3fe6064 100644 --- a/tests/EmailChecker/Tests/TestCase.php +++ b/tests/EmailChecker/Tests/TestCase.php @@ -11,10 +11,17 @@ namespace EmailChecker\Tests; -class TestCase extends \PHPUnit\Framework\TestCase +use PHPUnit\Framework\TestCase as PHPUnitTestCase; + +abstract class TestCase extends PHPUnitTestCase { - protected function getFixtures($file) + protected function getFixtures(string $file): string { - return file_get_contents(__DIR__.'/../../fixtures/'.$file); + $content = file_get_contents(__DIR__.'/../../fixtures/'.$file); + if (false === $content) { + throw new \InvalidArgumentException(sprintf('File "%s" not found', $file)); + } + + return $content; } } diff --git a/tests/EmailChecker/Tests/ThrowawayDomainsTest.php b/tests/EmailChecker/Tests/ThrowawayDomainsTest.php index 95f14da..12ee8cc 100644 --- a/tests/EmailChecker/Tests/ThrowawayDomainsTest.php +++ b/tests/EmailChecker/Tests/ThrowawayDomainsTest.php @@ -13,13 +13,12 @@ use EmailChecker\ThrowawayDomains; -class ThrowawayDomainsTest extends TestCase +final class ThrowawayDomainsTest extends TestCase { - public function testIsInstanciable() + public function testIsInstanciable(): void { $domains = new ThrowawayDomains(); - $this->assertTrue(is_array($domains->toArray())); $this->assertGreaterThan(0, count($domains)); } } diff --git a/tests/EmailChecker/Tests/UtilitiesTest.php b/tests/EmailChecker/Tests/UtilitiesTest.php index 397a90d..331d5be 100644 --- a/tests/EmailChecker/Tests/UtilitiesTest.php +++ b/tests/EmailChecker/Tests/UtilitiesTest.php @@ -14,12 +14,12 @@ use EmailChecker\Exception\InvalidEmailException; use EmailChecker\Utilities; -class UtilitiesTest extends TestCase +final class UtilitiesTest extends TestCase { /** * @dataProvider validEmails */ - public function testParseValidEmail($email, $exceptedLocal, $exceptedDomain) + public function testParseValidEmail(string $email, string $exceptedLocal, string $exceptedDomain): void { list($local, $domain) = Utilities::parseEmailAddress($email); @@ -29,7 +29,7 @@ public function testParseValidEmail($email, $exceptedLocal, $exceptedDomain) /** * @dataProvider invalidEmails */ - public function testParseInvalidEmail($email) + public function testParseInvalidEmail(string $email): void { try { Utilities::parseEmailAddress($email); @@ -39,7 +39,7 @@ public function testParseInvalidEmail($email) } } - public function testParseLines() + public function testParseLines(): void { $content = <<<'TEXT' # This is a comment and should be parsed @@ -68,7 +68,7 @@ public function testParseLines() $this->assertEmpty($diffs, sprintf($message, print_r($expectedLines, true), print_r($parsedContent, true))); } - public static function validEmails() + public static function validEmails(): iterable { return [ ['foo@bar.org', 'foo', 'bar.org'], @@ -76,7 +76,7 @@ public static function validEmails() ]; } - public static function invalidEmails() + public static function invalidEmails(): iterable { return [ ['foo[at]bar.org'],