Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
name: phpstan
name: Upgrade, Compile and PHPStan
on: [ pull_request ]

jobs:
build:
strategy:
matrix:
include:
- PHP_VERSION: php74-fpm
MAGENTO_VERSION: 2.4.0
- PHP_VERSION: php81-fpm
MAGENTO_VERSION: 2.4.6-p4
- PHP_VERSION: php83-fpm
MAGENTO_VERSION: 2.4.7

- PHP_VERSION: php84-fpm
MAGENTO_VERSION: 2.4.8
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
Expand All @@ -29,4 +34,4 @@ jobs:
run: docker exec magento-project-community-edition ./retry "php bin/magento module:enable Magmodules_MessageBird && php bin/magento setup:upgrade && php bin/magento setup:di:compile"

- name: Run PHPStan
run: docker exec magento-project-community-edition /bin/bash -c "./vendor/bin/phpstan analyse --no-progress -c /data/extensions/*/phpstan.neon /data/extensions"
run: docker exec magento-project-community-edition /bin/bash -c "./vendor/bin/phpstan analyse --no-progress -c /data/extensions/*/phpstan.neon /data/extensions"
15 changes: 10 additions & 5 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
name: Lint PHP files
on: [ push, pull_request ]
on: [push, pull_request]

jobs:
php-74:
runs-on: ubuntu-latest
steps:
- uses: prestashop/github-action-php-lint/7.4@v2.2
- uses: prestashop/github-action-php-lint/7.4@v2.3.1

php-81:
runs-on: ubuntu-latest
steps:
- uses: prestashop/github-action-php-lint/8.1@v2.2
- uses: prestashop/github-action-php-lint/8.1@v2.3.1

php-82:
runs-on: ubuntu-latest
steps:
- uses: prestashop/github-action-php-lint/8.2@v2.2
- uses: prestashop/github-action-php-lint/8.2@v2.3.1

php-83:
runs-on: ubuntu-latest
steps:
- uses: prestashop/github-action-php-lint/8.3@v2.2
- uses: prestashop/github-action-php-lint/8.3@v2.3.1

php-84:
runs-on: ubuntu-latest
steps:
- uses: prestashop/github-action-php-lint/8.4@v2.3.1
34 changes: 0 additions & 34 deletions .github/workflows/setup-di-compile.yml

This file was deleted.

4 changes: 2 additions & 2 deletions Api/Config/RepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,11 @@ public function getRestrictionShipment(int $storeId): array;
* @param int $storeId
* @return bool
*/
public function isDebugEnabled(int $storeId = null): bool;
public function isDebugEnabled(?int $storeId = null): bool;

/**
* @param int $storeId
* @return bool
*/
public function isMollieEnabled(int $storeId = null): bool;
public function isMollieEnabled(?int $storeId = null): bool;
}
44 changes: 14 additions & 30 deletions Logger/DebugLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,35 @@

namespace Magmodules\MessageBird\Logger;

use Monolog\Logger;
use Magento\Framework\Serialize\Serializer\Json;
use Monolog\Logger as MonologLogger;

/**
* DebugLogger logger class
* Wrapper around Monolog\Logger to log debug-level messages for module.
* Automatically serializes array or object input using Magento's JSON serializer.
*
* Example usage:
* $logger->addLog('API Debug', ['message' => 'response', 'code' => 200]);
*/
class DebugLogger extends Logger
class DebugLogger
{
private MonologLogger $logger;
private Json $json;

/**
* @var Json
*/
private $json;

/**
* DebugLogger constructor.
*
* @param Json $json
* @param string $name
* @param array $handlers
* @param array $processors
*/
public function __construct(
Json $json,
string $name,
array $handlers = [],
array $processors = []
MonologLogger $logger,
Json $json
) {
$this->logger = $logger;
$this->json = $json;
parent::__construct($name, $handlers, $processors);
}

/**
* Add debug data to messagebird Log
*
* @param string $type
* @param mixed $data
*
*/
public function addLog(string $type, $data): void
{
if (is_array($data) || is_object($data)) {
$this->addRecord(static::INFO, $type . ': ' . $this->json->serialize($data));
$this->logger->info( $type . ': ' . $this->json->serialize($data));
} else {
$this->addRecord(static::INFO, $type . ': ' . $data);
$this->logger->info( $type . ': ' . $data);
}
}
}
46 changes: 15 additions & 31 deletions Logger/ErrorLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,51 +7,35 @@

namespace Magmodules\MessageBird\Logger;

use Monolog\Logger;
use Magento\Framework\Serialize\Serializer\Json;
use Monolog\Logger as MonologLogger;

/**
* ErrorLogger logger class
* Wrapper around Monolog\Logger to log error-level messages for module.
* Automatically serializes array or object input using Magento's JSON serializer.
*
* Example usage:
* $logger->addLog('API Error', ['message' => 'Invalid response', 'code' => 500]);
*/
class ErrorLogger extends Logger
class ErrorLogger
{
private MonologLogger $logger;
private Json $json;

/**
* @var Json
*/
private $json;

/**
* ErrorLogger constructor.
*
* @param Json $json
* @param string $name
* @param array $handlers
* @param array $processors
*/
public function __construct(
Json $json,
string $name,
array $handlers = [],
array $processors = []
MonologLogger $logger,
Json $json
) {
$this->logger = $logger;
$this->json = $json;
parent::__construct($name, $handlers, $processors);
}

/**
* Add error data to messagebird Log
*
* @param string $type
* @param mixed $data
*
*/
public function addLog($type, $data): void
public function addLog(string $type, $data): void
{
if (is_array($data) || is_object($data)) {
$this->addRecord(static::ERROR, $type . ': ' . $this->json->serialize($data));
$this->logger->error( $type . ': ' . $this->json->serialize($data));
} else {
$this->addRecord(static::ERROR, $type . ': ' . $data);
$this->logger->error( $type . ': ' . $data);
}
}
}
23 changes: 9 additions & 14 deletions Logger/Handler/Debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,16 @@
namespace Magmodules\MessageBird\Logger\Handler;

use Monolog\Logger;
use Magento\Framework\Logger\Handler\Base;
use Monolog\Handler\StreamHandler;

/**
* Debug logger handler class
*/
class Debug extends Base
class Debug extends StreamHandler
{
public const FILENAME = 'messagebird-debug.log';
public const LEVEL = Logger::DEBUG;

/**
* @var int
*/
protected $loggerType = Logger::DEBUG;

/**
* @var string
*/
protected $fileName = '/var/log/messagebird-debug.log';
public function __construct()
{
/** @phpstan-ignore constant.notFound */
parent::__construct(BP . '/var/log/' . self::FILENAME, self::LEVEL);
}
}
23 changes: 9 additions & 14 deletions Logger/Handler/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,16 @@
namespace Magmodules\MessageBird\Logger\Handler;

use Monolog\Logger;
use Magento\Framework\Logger\Handler\Base;
use Monolog\Handler\StreamHandler;

/**
* Error logger handler class
*/
class Error extends Base
class Error extends StreamHandler
{
public const FILENAME = 'messagebird-error.log';
public const LEVEL = Logger::ERROR;

/**
* @var int
*/
protected $loggerType = Logger::ERROR;

/**
* @var string
*/
protected $fileName = '/var/log/messagebird-error.log';
public function __construct()
{
/** @phpstan-ignore constant.notFound */
parent::__construct(BP . '/var/log/' . self::FILENAME, self::LEVEL);
}
}
2 changes: 1 addition & 1 deletion Model/CommunicationLog/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function __construct(
ResourceModel $resourceModel,
SearchResultsInterfaceFactory $searchResultsFactory,
DataInterfaceFactory $dataFactory,
CollectionProcessorInterface $collectionProcessor = null
?CollectionProcessorInterface $collectionProcessor = null
) {
$this->collectionFactory = $collectionFactory;
$this->resourceModel = $resourceModel;
Expand Down
10 changes: 5 additions & 5 deletions Model/Config/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public function getRestrictionShipment(int $storeId): array
*
* @return bool
*/
private function isSetFlag(string $path, int $storeId = null, string $scope = null): bool
private function isSetFlag(string $path, ?int $storeId = null, ?string $scope = null): bool
{
if (empty($scope)) {
$scope = ScopeInterface::SCOPE_STORE;
Expand All @@ -341,8 +341,8 @@ private function isSetFlag(string $path, int $storeId = null, string $scope = nu
*/
private function getStoreValue(
string $path,
int $storeId = null,
string $scope = null
?int $storeId = null,
?string $scope = null
): string {
if (!$storeId) {
$storeId = (int)$this->getStore()->getId();
Expand All @@ -354,15 +354,15 @@ private function getStoreValue(
/**
* @inheritDoc
*/
public function isDebugEnabled(int $storeId = null): bool
public function isDebugEnabled(?int $storeId = null): bool
{
return $this->isSetFlag(self::DEBUG, $storeId);
}

/**
* @inheritDoc
*/
public function isMollieEnabled(int $storeId = null): bool
public function isMollieEnabled(?int $storeId = null): bool
{
return $this->isSetFlag(self::MOLLIE_STATUS, $storeId);
}
Expand Down
4 changes: 2 additions & 2 deletions Model/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public function __construct(
Adapter $adapter,
PrepareProductAlertData $prepareProductAlertData,
CommunicationLogRepository $communicationLogRepository,
AbstractResource $resource = null,
AbstractDb $resourceCollection = null,
?AbstractResource $resource = null,
?AbstractDb $resourceCollection = null,
array $data = []
) {
$this->adapter = $adapter;
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "magmodules/magento2-messagebird",
"description": "MessageBird integration for Magento 2",
"type": "magento2-module",
"version": "1.1.1",
"version": "1.2.0",
"require": {
"magento/framework": ">=100.1.0",
"messagebird/php-rest-api": ">=1.20",
Expand All @@ -20,4 +20,4 @@
"Magmodules\\MessageBird\\": ""
}
}
}
}
2 changes: 1 addition & 1 deletion etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<default>
<magmodules_messagebird>
<general>
<version>v1.1.1</version>
<version>v1.2.0</version>
</general>
<communication>
<order_message>We successfully received your order with ID #{{order_id}} and awaiting your payment.</order_message>
Expand Down
Loading