diff --git a/.gitignore b/.gitignore index 13d3253..9a8eb86 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ index .composer.lock .phpunit.cache composer.lock +PHP_CodeSniffer diff --git a/.php_cs b/.php_cs deleted file mode 100644 index 4e6698c..0000000 --- a/.php_cs +++ /dev/null @@ -1,62 +0,0 @@ -level(CS\FixerInterface::PSR2_LEVEL) - ->fixers([ - 'array_element_no_space_before_comma', - 'array_element_white_space_after_comma', - 'duplicate_semicolon', - 'extra_empty_lines', - 'function_typehint_space', - 'include', - 'join_function', - 'list_commas', - 'method_argument_default_value', - 'multiline_array_trailing_comma', - 'namespace_no_leading_whitespace', - 'new_with_braces', - 'no_blank_lines_after_class_opening', - 'object_operator', - 'operators_spaces', - 'phpdoc_indent', - 'phpdoc_inline_tag', - 'phpdoc_no_access', - 'phpdoc_no_empty_return', - 'phpdoc_no_package', - 'phpdoc_scalar', - 'phpdoc_separation', - 'phpdoc_short_description', - 'phpdoc_type_to_var', - 'phpdoc_types', - 'phpdoc_var_without_name', - 'print_to_echo', - 'remove_leading_slash_use', - 'remove_lines_between_uses', - 'return', - 'short_bool_cast', - 'single_array_no_trailing_comma', - 'single_blank_line_before_namespace', - 'single_quote', - 'spaces_cast', - 'standardize_not_equal', - 'ternary_spaces', - 'trim_array_spaces', - 'unalign_double_arrow', - 'unalign_equals', - 'unary_operators_spaces', - 'unneeded_control_parentheses', - 'unused_use', - 'whitespacy_lines', - 'concat_with_spaces', - 'newline_after_open_tag', - 'ordered_use', - 'phpdoc_order', - 'short_array_syntax', - 'strict_param', - ]) - ->finder( - CS\Finder\DefaultFinder::create() - ->in([__DIR__ . '/src', __DIR__ . '/tests']) - ); diff --git a/.scrutinizer.yml b/.scrutinizer.yml deleted file mode 100644 index b1d8692..0000000 --- a/.scrutinizer.yml +++ /dev/null @@ -1,37 +0,0 @@ - -filter: - excluded_paths: [tests/*, data/*, vendor/*] - paths: [src/*] - -checks: - php: - code_rating: true - remove_extra_empty_lines: true - remove_php_closing_tag: true - remove_trailing_whitespace: true - fix_use_statements: - remove_unused: true - preserve_multiple: false - preserve_blanklines: true - order_alphabetically: true - fix_php_opening_tag: true - fix_linefeed: true - fix_line_ending: true - fix_identation_4spaces: true - fix_doc_comments: true -tools: - external_code_coverage: - timeout: 600 - php_analyzer: true - php_code_coverage: false - php_code_sniffer: - config: - standard: PSR2 - filter: - paths: ['src'] - php_loc: - enabled: true - excluded_dirs: [vendor, tests] - php_cpd: - enabled: true - excluded_dirs: [vendor, tests, data] diff --git a/README.md b/README.md index 14cd2b7..3b33d98 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,10 @@ # Mailer -[![Build Status](https://img.shields.io/travis/2amigos/mailer-library/master.svg?style=flat-square)](https://travis-ci.org/2amigos/mailer-library) -[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/2amigos/mailer-library/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/2amigos/mailer-library/?branch=master) -[![Code Coverage](https://scrutinizer-ci.com/g/2amigos/mailer-library/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/2amigos/mailer-library/?branch=master) +[![tests](https://github.com/2amigos/mailer-library/actions/workflows/ci.yml/badge.svg)](https://github.com/2amigos/mailer-library/actions/workflows/ci.yml) +[![Codacy Badge](https://app.codacy.com/project/badge/Grade/d0e8d6e968944592a95a0911d8f178ff)](https://app.codacy.com/gh/2amigos/mailer-library/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_grade) +[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/d0e8d6e968944592a95a0911d8f178ff)](https://app.codacy.com/gh/2amigos/mailer-library/dashboard?utm_source=gh&utm_medium=referral&utm_content=&utm_campaign=Badge_coverage) +[![Latest Stable Version](http://poser.pugx.org/2amigos/mailer/v)](https://packagist.org/packages/2amigos/mailer) +[![Total Downloads](http://poser.pugx.org/2amigos/mailer/downloads)](https://packagist.org/packages/2amigos/mailer) +[![PHP Version Require](http://poser.pugx.org/2amigos/mailer/require/php)](https://packagist.org/packages/2amigos/mailer) Many times we face a requirement to implement queue mail functionality in our projects. There are queue and mailing libraries, but there seemed to be none that could actually suit our needs and moreover, we always had to sync their diff --git a/src/Builder/Buildable.php b/src/Builder/Buildable.php index ad25745..7c83e38 100644 --- a/src/Builder/Buildable.php +++ b/src/Builder/Buildable.php @@ -20,5 +20,5 @@ protected static function getConfig() * @param $config * @return void */ - public abstract static function make($config = null); + abstract public static function make($config = null); } diff --git a/src/Builder/MailJobBuilder.php b/src/Builder/MailJobBuilder.php index 13a0c14..43a9a91 100644 --- a/src/Builder/MailJobBuilder.php +++ b/src/Builder/MailJobBuilder.php @@ -24,7 +24,7 @@ public static function make($jobAttributes = null, ?string $broker = null): Mail $config = self::getConfig(); $messageBroker = $broker ?? $config['config']['message_broker']; - switch($messageBroker) { + switch ($messageBroker) { case MessageBrokerEnum::BROKER_REDIS: return new RedisMailJob($jobAttributes); case MessageBrokerEnum::BROKER_SQS: @@ -35,7 +35,8 @@ public static function make($jobAttributes = null, ?string $broker = null): Mail return new PdoMailJob($jobAttributes); case MessageBrokerEnum::BROKER_RABBITMQ: return new RabbitMqJob($jobAttributes); - default: throw new UndefinedMessageBrokerException(); + default: + throw new UndefinedMessageBrokerException(); } } } diff --git a/src/Builder/QueueBuilder.php b/src/Builder/QueueBuilder.php index 57f4154..40d1aa5 100644 --- a/src/Builder/QueueBuilder.php +++ b/src/Builder/QueueBuilder.php @@ -45,7 +45,7 @@ protected static function getBrokerAdapter($messageBroker) $config = self::getConfig(); $connectionValues = $config['brokers'][$messageBroker] ?? []; - switch($messageBroker) { + switch ($messageBroker) { case MessageBrokerEnum::BROKER_REDIS: return new RedisQueueStoreAdapter( new RedisQueueStoreConnection($connectionValues) @@ -66,7 +66,8 @@ protected static function getBrokerAdapter($messageBroker) return new RabbitMqQueueStoreAdapter( new RabbitMqQueueConnection($connectionValues) ); - default: throw new UndefinedMessageBrokerException(); + default: + throw new UndefinedMessageBrokerException(); } } } diff --git a/src/Event/Event.php b/src/Event/Event.php index a643179..907a507 100644 --- a/src/Event/Event.php +++ b/src/Event/Event.php @@ -1,4 +1,5 @@ data = func_get_args(); - return call_user_func($this->handler, $this); } diff --git a/src/Event/EventHandlerTrait.php b/src/Event/EventHandlerTrait.php index 1147219..be37bec 100644 --- a/src/Event/EventHandlerTrait.php +++ b/src/Event/EventHandlerTrait.php @@ -1,4 +1,5 @@ getTransportInstance()->send($message); } @@ -121,9 +120,7 @@ public static function fromMailMessage(MailMessage $mailMessage) 'port' => $mailMessage->port, 'options' => $mailMessage->transportOptions, ]; - $factory = TransportFactory::create($options, $mailMessage->transportType); - return new Mailer($factory->create()); } } diff --git a/src/Model/AbstractMailObject.php b/src/Model/AbstractMailObject.php index 5f5fb7a..86770d7 100644 --- a/src/Model/AbstractMailObject.php +++ b/src/Model/AbstractMailObject.php @@ -1,4 +1,5 @@ json_encode($this)]); - QueueBuilder::make()->enqueue($job); } @@ -131,7 +130,6 @@ public function addAttachment(string $path, ?string $name = null): void { if (is_null($this->attachments)) { $this->attachments = [File::make($path, $name)]; - return; } diff --git a/src/Queue/Backend/AbstractQueueStoreConnection.php b/src/Queue/Backend/AbstractQueueStoreConnection.php index e5267b6..74999b7 100644 --- a/src/Queue/Backend/AbstractQueueStoreConnection.php +++ b/src/Queue/Backend/AbstractQueueStoreConnection.php @@ -1,4 +1,5 @@ connection = $connection; $this->queueName = $queueName; $this->timeToRun = $timeToRun; @@ -58,7 +54,6 @@ public function __construct( public function init() { $this->getConnection()->connect(); - return $this; } @@ -80,7 +75,6 @@ public function enqueue(MailJobInterface $mailJob) $timestamp = $mailJob->getTimeToSend(); $payload = $this->createPayload($mailJob); $delay = (int) max(Pheanstalk::DEFAULT_DELAY, $timestamp - time()); - return $this->getConnection() ->getInstance() ->useTube($this->queueName) @@ -96,15 +90,12 @@ public function dequeue() $job = $this->getConnection()->getInstance()->watch($this->queueName)->reserveWithTimeout($this->reserveTimeout); if ($job instanceof PheanstalkJob) { $data = json_decode($job->getData(), true); - - return new BeanstalkdMailJob( - [ + return new BeanstalkdMailJob([ 'id' => $data['id'], 'attempt' => $data['attempt'], 'message' => $data['message'], 'pheanstalkJob' => $job, - ] - ); + ]); } return null; @@ -123,17 +114,14 @@ public function ack(MailJobInterface $mailJob) $pheanstalk = $this->getConnection()->getInstance()->useTube($this->queueName); if ($mailJob->isCompleted()) { $pheanstalk->delete($mailJob->getPheanstalkJob()); - return null; } $timestamp = $mailJob->getTimeToSend(); $delay = max(0, $timestamp - time()); - - // add back to the queue as it wasn't completed maybe due to some transitory error +// add back to the queue as it wasn't completed maybe due to some transitory error // could also be failed. $pheanstalk->release($mailJob->getPheanstalkJob(), Pheanstalk::DEFAULT_PRIORITY, $delay); - return null; } @@ -144,7 +132,6 @@ public function ack(MailJobInterface $mailJob) public function isEmpty() { $stats = $this->getConnection()->getInstance()->statsTube($this->queueName); - return (int) $stats->current_jobs_delayed === 0 && (int) $stats->current_jobs_urgent === 0 && (int) $stats->current_jobs_ready === 0; @@ -157,12 +144,10 @@ public function isEmpty() */ protected function createPayload(MailJobInterface $mailJob) { - return json_encode( - [ + return json_encode([ 'id' => $mailJob->isNewRecord() ? sha1(Random::string(32)) : $mailJob->getId(), 'attempt' => $mailJob->getAttempt(), 'message' => $mailJob->getMessage(), - ] - ); + ]); } } diff --git a/src/Queue/Backend/Beanstalkd/BeanstalkdQueueStoreConnection.php b/src/Queue/Backend/Beanstalkd/BeanstalkdQueueStoreConnection.php index d8659c3..fdb7582 100644 --- a/src/Queue/Backend/Beanstalkd/BeanstalkdQueueStoreConnection.php +++ b/src/Queue/Backend/Beanstalkd/BeanstalkdQueueStoreConnection.php @@ -1,4 +1,5 @@ getConfigurationValue('port', Pheanstalk::DEFAULT_PORT); $connectionTimeout = $this->getConfigurationValue('connectionTimeout'); $connectPersistent = $this->getConfigurationValue('connectPersistent', false); - $connection = new Connection(new SocketFactory($host, $port ?: Pheanstalk::DEFAULT_PORT, $connectionTimeout ?? 0, $connectPersistent ?? SocketFactory::AUTODETECT)); $this->instance = new Pheanstalk($connection); - return $this; } diff --git a/src/Queue/Backend/MailJobInterface.php b/src/Queue/Backend/MailJobInterface.php index 3740915..514d821 100644 --- a/src/Queue/Backend/MailJobInterface.php +++ b/src/Queue/Backend/MailJobInterface.php @@ -1,4 +1,5 @@ state = self::STATE_COMPLETED; - parent::markAsCompleted(); } diff --git a/src/Queue/Backend/Pdo/PdoQueueStoreAdapter.php b/src/Queue/Backend/Pdo/PdoQueueStoreAdapter.php index d7b3038..59abfbe 100644 --- a/src/Queue/Backend/Pdo/PdoQueueStoreAdapter.php +++ b/src/Queue/Backend/Pdo/PdoQueueStoreAdapter.php @@ -1,4 +1,5 @@ getConnection()->connect(); - return $this; } @@ -57,14 +56,10 @@ public function getConnection() */ public function enqueue(MailJobInterface $mailJob) { - $sql = sprintf( - 'INSERT INTO `%s` (`message`, `timeToSend`) VALUES (:message, :timeToSend)', - $this->tableName - ); + $sql = sprintf('INSERT INTO `%s` (`message`, `timeToSend`) VALUES (:message, :timeToSend)', $this->tableName); $query = $this->getConnection()->getInstance()->prepare($sql); $query->bindValue(':message', $mailJob->getMessage()); $query->bindValue(':timeToSend', $mailJob->getTimeToSend()); - return $query->execute(); } @@ -76,33 +71,28 @@ public function enqueue(MailJobInterface $mailJob) public function dequeue() { $this->getConnection()->getInstance()->beginTransaction(); - $mailJob = null; $sqlText = 'SELECT `id`, `message`, `attempt` FROM `%s` WHERE `timeToSend` <= :timeToSend AND `state`=:state ORDER BY id ASC LIMIT 1 FOR UPDATE'; $sql = sprintf($sqlText, $this->tableName); $query = $this->getConnection()->getInstance()->prepare($sql); - $query->bindValue(':state', PdoMailJob::STATE_NEW); $query->bindValue(':timeToSend', date('Y-m-d H:i:s'), time()); $query->execute(); $queryResult = $query->fetch(PDO::FETCH_ASSOC); - if ($queryResult) { - // + // $sqlText = 'UPDATE `%s` SET `state`=:state WHERE `id`=:id'; $sql = sprintf($sqlText, $this->tableName); $query = $this->getConnection()->getInstance()->prepare($sql); $query->bindValue(':state', PdoMailJob::STATE_ACTIVE); $query->bindValue(':id', $queryResult['id'], PDO::PARAM_INT); $query->execute(); - $mailJob = new PdoMailJob($queryResult); } $this->getConnection()->getInstance()->commit(); - return $mailJob; } @@ -128,13 +118,11 @@ public function ack(MailJobInterface $mailJob) $sql = sprintf($sqlText, $this->tableName); $sentTime = $mailJob->isCompleted() ? date('Y-m-d H:i:s', time()) : null; $query = $this->getConnection()->getInstance()->prepare($sql); - $query->bindValue(':id', $mailJob->getId(), PDO::PARAM_INT); $query->bindValue(':attempt', $mailJob->getAttempt(), PDO::PARAM_INT); $query->bindValue(':state', $mailJob->getState()); $query->bindValue(':timeToSend', $mailJob->getTimeToSend()); $query->bindValue(':sentTime', $sentTime); - return $query->execute(); } @@ -143,16 +131,11 @@ public function ack(MailJobInterface $mailJob) */ public function isEmpty() { - $sql = sprintf( - 'SELECT COUNT(`id`) FROM `%s` WHERE `timeToSend` <= :timeToSend AND `state`=:state ORDER BY id ASC LIMIT 1', - $this->tableName - ); + $sql = sprintf('SELECT COUNT(`id`) FROM `%s` WHERE `timeToSend` <= :timeToSend AND `state`=:state ORDER BY id ASC LIMIT 1', $this->tableName); $query = $this->getConnection()->getInstance()->prepare($sql); - $query->bindValue(':state', PdoMailJob::STATE_NEW); $query->bindValue(':timeToSend', date('Y-m-d H:i:s'), time()); $query->execute(); - return intval($query->fetchColumn(0)) === 0; } } diff --git a/src/Queue/Backend/Pdo/PdoQueueStoreConnection.php b/src/Queue/Backend/Pdo/PdoQueueStoreConnection.php index 05acd59..9bc5906 100644 --- a/src/Queue/Backend/Pdo/PdoQueueStoreConnection.php +++ b/src/Queue/Backend/Pdo/PdoQueueStoreConnection.php @@ -1,4 +1,5 @@ configuration['dsn'])) { - $this->configuration['dsn'] = sprintf( - "mysql:host=%s;dbname=%s;port=%s", - $this->configuration['host'] ?? '', - $this->configuration['db'] ?? '', - $this->configuration['port'] ?? 3306 - ); + $this->configuration['dsn'] = sprintf("mysql:host=%s;dbname=%s;port=%s", $this->configuration['host'] ?? '', $this->configuration['db'] ?? '', $this->configuration['port'] ?? 3306); } } @@ -35,14 +31,11 @@ protected function defineConnectionString() public function connect() { $this->disconnect(); - $username = $this->getConfigurationValue('username'); $password = $this->getConfigurationValue('password'); $options = $this->getConfigurationValue('options'); - $this->instance = new PDO($this->getConfigurationValue('dsn'), $username, $password, $options); $this->instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - return $this; } diff --git a/src/Queue/Backend/QueueStoreAdapterInterface.php b/src/Queue/Backend/QueueStoreAdapterInterface.php index f183dc5..d081c34 100644 --- a/src/Queue/Backend/QueueStoreAdapterInterface.php +++ b/src/Queue/Backend/QueueStoreAdapterInterface.php @@ -1,4 +1,5 @@ configuration['port'], $this->configuration['user'], $this->configuration['password'] - ); $this->instance = $this->connection->channel(); diff --git a/src/Queue/Backend/Redis/RedisMailJob.php b/src/Queue/Backend/Redis/RedisMailJob.php index c1ee438..2c1e470 100644 --- a/src/Queue/Backend/Redis/RedisMailJob.php +++ b/src/Queue/Backend/Redis/RedisMailJob.php @@ -1,4 +1,5 @@ getConnection() ->connect(); - return $this; } @@ -64,7 +63,6 @@ public function enqueue(MailJobInterface $mailJob) { $timestamp = $mailJob->getTimeToSend(); $payload = $this->createPayload($mailJob); - return $timestamp !== null && $timestamp > time() ? $this->getConnection()->getInstance()->zadd($this->queueName . ':delayed', $timestamp, $payload) : $this->getConnection()->getInstance()->rpush($this->queueName, $payload); @@ -76,23 +74,17 @@ public function enqueue(MailJobInterface $mailJob) public function dequeue() { $this->migrateExpiredJobs(); - $job = $this->getConnection()->getInstance()->lpop($this->queueName); - if ($job !== null) { $this->getConnection() ->getInstance() ->zadd($this->queueName . ':reserved', time() + $this->expireTime, $job); - $data = json_decode($job, true); - - return new RedisMailJob( - [ + return new RedisMailJob([ 'id' => $data['id'], 'attempt' => $data['attempt'], 'message' => $data['message'], - ] - ); + ]); } return null; @@ -108,7 +100,6 @@ public function ack(MailJobInterface $mailJob) } $this->removeReserved($mailJob); - if (!$mailJob->isCompleted()) { if ($mailJob->getTimeToSend() === null || $mailJob->getTimeToSend() < time()) { $mailJob->setTimeToSend(time() + $this->expireTime); @@ -141,13 +132,11 @@ public function isEmpty() */ protected function createPayload(MailJobInterface $mailJob) { - return json_encode( - [ + return json_encode([ 'id' => $mailJob->isNewRecord() ? sha1(Random::string(32)) : $mailJob->getId(), 'attempt' => $mailJob->getAttempt(), 'message' => $mailJob->getMessage(), - ] - ); + ]); } /** @@ -168,24 +157,21 @@ protected function migrateExpiredJobs() protected function migrateJobs($from, $to) { $options = ['cas' => true, 'watch' => $from, 'retry' => 10]; + $this->getConnection()->getInstance()->transaction($options, function ($transaction) use ($from, $to) { - $this->getConnection()->getInstance()->transaction( - $options, - function ($transaction) use ($from, $to) { $time = time(); - // First we need to get all of jobs that have expired based on the current time + // First we need to get all of jobs that have expired based on the current time // so that we can push them onto the main queue. After we get them we simply // remove them from this "delay" queues. All of this within a transaction. $jobs = $this->getExpiredJobs($transaction, $from, $time); - // If we actually found any jobs, we will remove them from the old queue and we + // If we actually found any jobs, we will remove them from the old queue and we // will insert them onto the new (ready) "queue". This means they will stand // ready to be processed by the queue worker whenever their turn comes up. - if (count($jobs) > 0) { - $this->removeExpiredJobs($transaction, $from, $time); - $this->pushExpiredJobsOntoNewQueue($transaction, $to, $jobs); - } + if (count($jobs) > 0) { + $this->removeExpiredJobs($transaction, $from, $time); + $this->pushExpiredJobsOntoNewQueue($transaction, $to, $jobs); } - ); + }); } /** diff --git a/src/Queue/Backend/Redis/RedisQueueStoreConnection.php b/src/Queue/Backend/Redis/RedisQueueStoreConnection.php index 96e76b4..7905e98 100644 --- a/src/Queue/Backend/Redis/RedisQueueStoreConnection.php +++ b/src/Queue/Backend/Redis/RedisQueueStoreConnection.php @@ -1,4 +1,5 @@ disconnect(); $this->instance = new Client($this->configuration); - return $this; } diff --git a/src/Queue/Backend/Sqs/SqsMailJob.php b/src/Queue/Backend/Sqs/SqsMailJob.php index cb2812e..3756523 100644 --- a/src/Queue/Backend/Sqs/SqsMailJob.php +++ b/src/Queue/Backend/Sqs/SqsMailJob.php @@ -1,4 +1,5 @@ getConnection()->connect(); - - // create new queue or get existing one +// create new queue or get existing one $queue = $this->getConnection()->getInstance()->createQueue([ 'QueueName' => $this->queueName, ]); $this->queueUrl = $queue['QueueUrl']; - return $this; } @@ -71,7 +69,6 @@ public function enqueue(MailJobInterface $mailJob) 'Attempt' => $mailJob->getAttempt(), ]); $messageId = $result['MessageId']; - return $messageId !== null && is_string($messageId); } @@ -85,13 +82,11 @@ public function dequeue() $result = $this->getConnection()->getInstance()->receiveMessage([ 'QueueUrl' => $this->queueUrl, ]); - if (empty($result['Messages'])) { return null; } $result = array_shift($result['Messages']); - return new SqsMailJob([ 'id' => $result['MessageId'], 'receiptHandle' => $result['ReceiptHandle'], @@ -116,7 +111,6 @@ public function ack(MailJobInterface $mailJob) 'QueueUrl' => $this->queueUrl, 'ReceiptHandle' => $mailJob->getReceiptHandle(), ]); - return true; } elseif ($mailJob->getVisibilityTimeout() !== null) { $this->getConnection()->getInstance()->changeMessageVisibility([ @@ -124,7 +118,6 @@ public function ack(MailJobInterface $mailJob) 'ReceiptHandle' => $mailJob->getReceiptHandle(), 'VisibilityTimeout' => $mailJob->getVisibilityTimeout(), ]); - return true; } @@ -140,7 +133,6 @@ public function isEmpty(): bool 'QueueUrl' => $this->queueUrl, 'AttributeNames' => ['ApproximateNumberOfMessages'], ]); - return $response['Attributes']['ApproximateNumberOfMessages'] === 0; } } diff --git a/src/Queue/Backend/Sqs/SqsQueueStoreConnection.php b/src/Queue/Backend/Sqs/SqsQueueStoreConnection.php index d224d95..eb67911 100644 --- a/src/Queue/Backend/Sqs/SqsQueueStoreConnection.php +++ b/src/Queue/Backend/Sqs/SqsQueueStoreConnection.php @@ -1,4 +1,5 @@ getConfigurationValue('key'); $secret = $this->getConfigurationValue('secret'); $region = $this->getConfigurationValue('region'); - $this->instance = new SqsClient([ 'key' => $key, 'secret' => $secret, 'region' => $region, ]); - return $this; } diff --git a/src/Queue/Cli/MailMessageWorker.php b/src/Queue/Cli/MailMessageWorker.php index a2c375a..7560815 100644 --- a/src/Queue/Cli/MailMessageWorker.php +++ b/src/Queue/Cli/MailMessageWorker.php @@ -1,4 +1,5 @@ mailer->send($this->mailMessage); if (is_null($sentMessage)) { diff --git a/src/Security/Cypher.php b/src/Security/Cypher.php index b6fb659..cc8ce28 100644 --- a/src/Security/Cypher.php +++ b/src/Security/Cypher.php @@ -1,4 +1,5 @@ key = $key; $this->iv = $iv; - // initialize cypher with strongest mode and with AES. Is an anti-pattern and should be passed through the +// initialize cypher with strongest mode and with AES. Is an anti-pattern and should be passed through the // constructor as an argument, but this way we ensure the library does have the strongest strategy by default. $this->strategy = new AES('cbc'); - $this->strategy->setKeyLength(256); } @@ -39,7 +38,6 @@ public function encodeMailMessage(MailMessage $mailMessage) $jsonEncodedMailMessage = json_encode($mailMessage, JSON_NUMERIC_CHECK); $this->strategy->setKey($this->key); $this->strategy->setIV($this->iv); - return base64_encode($this->strategy->encrypt($jsonEncodedMailMessage)); } @@ -51,7 +49,6 @@ public function decodeMailMessage($encodedMailMessage) $this->strategy->setKey($this->key); $decryptedMailMessage = $this->strategy->decrypt(base64_decode($encodedMailMessage, true)); $jsonDecodedMailMessageAttributes = json_decode($decryptedMailMessage, true); - return new MailMessage($jsonDecodedMailMessageAttributes); } } diff --git a/src/Security/CypherInterface.php b/src/Security/CypherInterface.php index 1a13b97..7df8837 100644 --- a/src/Security/CypherInterface.php +++ b/src/Security/CypherInterface.php @@ -1,4 +1,5 @@ dsn = $dsn; diff --git a/src/Transport/MailTransportFactory.php b/src/Transport/MailTransportFactory.php index 97960b0..7ee5e5a 100644 --- a/src/Transport/MailTransportFactory.php +++ b/src/Transport/MailTransportFactory.php @@ -1,4 +1,5 @@ dsn = $dsn; @@ -29,7 +28,6 @@ public function getInstance(): \Symfony\Component\Mailer\Transport\SendmailTrans { if ($this->instance === null) { $sendMailFactory = new \Symfony\Component\Mailer\Transport\SendmailTransportFactory(); - $this->instance = $sendMailFactory->create(Dsn::fromString($this->dsn)); } diff --git a/src/Transport/SendMailTransportFactory.php b/src/Transport/SendMailTransportFactory.php index aa1d147..8784c7d 100644 --- a/src/Transport/SendMailTransportFactory.php +++ b/src/Transport/SendMailTransportFactory.php @@ -1,4 +1,5 @@ instance === null) { $user = $this->options['username'] ?? null; $password = $this->options['password'] ?? null; - - $this->instance = (new EsmtpTransportFactory())->create( - new Dsn('smtp', $this->host, $user, $password, $this->port, $this->options) - ); + $this->instance = (new EsmtpTransportFactory())->create(new Dsn('smtp', $this->host, $user, $password, $this->port, $this->options)); } return $this->instance; diff --git a/src/Transport/SmtpTransportFactory.php b/src/Transport/SmtpTransportFactory.php index 1569a95..7fd0ddb 100644 --- a/src/Transport/SmtpTransportFactory.php +++ b/src/Transport/SmtpTransportFactory.php @@ -1,4 +1,5 @@ options, 'host'); $port = ArrayHelper::remove($this->options, 'port'); $options = ArrayHelper::getValue($this->options, 'options', []); - return new SmtpTransport($host, $port, $options); } } diff --git a/src/Transport/TransportFactory.php b/src/Transport/TransportFactory.php index e602f83..ec5b776 100644 --- a/src/Transport/TransportFactory.php +++ b/src/Transport/TransportFactory.php @@ -1,8 +1,10 @@