diff --git a/.github/workflows/phpstan.yml b/.github/workflows/compile-and-phpstan.yml similarity index 82% rename from .github/workflows/phpstan.yml rename to .github/workflows/compile-and-phpstan.yml index 28aea8c..2d25250 100755 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/compile-and-phpstan.yml @@ -1,4 +1,4 @@ -name: phpstan +name: Upgrade, Compile and PHPStan on: [ pull_request ] jobs: @@ -6,9 +6,14 @@ jobs: 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 @@ -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" \ No newline at end of file + run: docker exec magento-project-community-edition /bin/bash -c "./vendor/bin/phpstan analyse --no-progress -c /data/extensions/*/phpstan.neon /data/extensions" diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml index 5195f3d..ddf8638 100755 --- a/.github/workflows/linting.yml +++ b/.github/workflows/linting.yml @@ -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 \ No newline at end of file + - 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 diff --git a/.github/workflows/setup-di-compile.yml b/.github/workflows/setup-di-compile.yml deleted file mode 100755 index 59e0e02..0000000 --- a/.github/workflows/setup-di-compile.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Run setup:upgrade and setup:di:compile -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.4 - - PHP_VERSION: php82-fpm - MAGENTO_VERSION: 2.4.6 - - PHP_VERSION: php83-fpm - MAGENTO_VERSION: 2.4.7 - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - - name: Start Docker - run: docker run --detach --name magento-project-community-edition michielgerritsen/magento-project-community-edition:${{ matrix.PHP_VERSION }}-magento${{ matrix.MAGENTO_VERSION }} - - - name: Create branch for Composer and remove version from composer.json - run: git checkout -b continuous-integration-test-branch && sed -i '/version/d' ./composer.json - - - name: Upload the code into the docker container - run: docker cp $(pwd) magento-project-community-edition:/data/extensions/ - - - name: Install the extension in Magento - run: docker exec magento-project-community-edition composer require magmodules/magento2-messagebird:@dev --no-plugins - - - name: Run setup:di:compile - run: docker exec magento-project-community-edition ./retry "php bin/magento setup:di:compile" \ No newline at end of file diff --git a/Api/Config/RepositoryInterface.php b/Api/Config/RepositoryInterface.php index 0fa5175..b17cd09 100755 --- a/Api/Config/RepositoryInterface.php +++ b/Api/Config/RepositoryInterface.php @@ -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; } diff --git a/Logger/DebugLogger.php b/Logger/DebugLogger.php index 38c00c2..3809827 100755 --- a/Logger/DebugLogger.php +++ b/Logger/DebugLogger.php @@ -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); } } } diff --git a/Logger/ErrorLogger.php b/Logger/ErrorLogger.php index 770fbbe..24f46c3 100755 --- a/Logger/ErrorLogger.php +++ b/Logger/ErrorLogger.php @@ -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); } } } diff --git a/Logger/Handler/Debug.php b/Logger/Handler/Debug.php index 3036557..d39e751 100755 --- a/Logger/Handler/Debug.php +++ b/Logger/Handler/Debug.php @@ -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); + } } diff --git a/Logger/Handler/Error.php b/Logger/Handler/Error.php index bce4e52..2da4ed3 100755 --- a/Logger/Handler/Error.php +++ b/Logger/Handler/Error.php @@ -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); + } } diff --git a/Model/CommunicationLog/Repository.php b/Model/CommunicationLog/Repository.php index 4813811..c2c1ea7 100755 --- a/Model/CommunicationLog/Repository.php +++ b/Model/CommunicationLog/Repository.php @@ -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; diff --git a/Model/Config/Repository.php b/Model/Config/Repository.php index 7b62a0f..7811c85 100755 --- a/Model/Config/Repository.php +++ b/Model/Config/Repository.php @@ -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; @@ -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(); @@ -354,7 +354,7 @@ private function getStoreValue( /** * @inheritDoc */ - public function isDebugEnabled(int $storeId = null): bool + public function isDebugEnabled(?int $storeId = null): bool { return $this->isSetFlag(self::DEBUG, $storeId); } @@ -362,7 +362,7 @@ public function isDebugEnabled(int $storeId = null): bool /** * @inheritDoc */ - public function isMollieEnabled(int $storeId = null): bool + public function isMollieEnabled(?int $storeId = null): bool { return $this->isSetFlag(self::MOLLIE_STATUS, $storeId); } diff --git a/Model/Email.php b/Model/Email.php index 27127bc..252a10f 100755 --- a/Model/Email.php +++ b/Model/Email.php @@ -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; diff --git a/composer.json b/composer.json index 32db6f5..245eab6 100755 --- a/composer.json +++ b/composer.json @@ -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", @@ -20,4 +20,4 @@ "Magmodules\\MessageBird\\": "" } } -} \ No newline at end of file +} diff --git a/etc/config.xml b/etc/config.xml index 197e59e..27f31a2 100755 --- a/etc/config.xml +++ b/etc/config.xml @@ -8,7 +8,7 @@ - v1.1.1 + v1.2.0 We successfully received your order with ID #{{order_id}} and awaiting your payment. diff --git a/etc/di.xml b/etc/di.xml index b9d43c0..bdb387d 100755 --- a/etc/di.xml +++ b/etc/di.xml @@ -6,25 +6,30 @@ - + - Magento\Framework\Filesystem\Driver\File + MessageBirdDebug + + Magmodules\MessageBird\Logger\Handler\Debug + - - + + MessageBirdError - Magmodules\MessageBird\Logger\Handler\Error + Magmodules\MessageBird\Logger\Handler\Error - + - MessageBirdDebug - - Magmodules\MessageBird\Logger\Handler\Error - + MessageBirdDebugMonolog + + + + + MessageBirdErrorMonolog diff --git a/phpstan.neon b/phpstan.neon index fe57a7d..7fdc53f 100755 --- a/phpstan.neon +++ b/phpstan.neon @@ -7,5 +7,5 @@ parameters: fileExtensions: - php - phtml - excludes_analyse: + excludePaths: - Test/*