Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: qa tooling #23

Merged
merged 5 commits into from
May 26, 2024
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
37 changes: 37 additions & 0 deletions .github/workflows/code-analysis.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Code Analysis

on:
pull_request:
workflow_dispatch:
permissions:
contents: read
jobs:
code_analysis:
strategy:
fail-fast: false
matrix:
actions:
- name: 'PHPStan'
run: composer phpstan
- name: 'Coding Standards'
run: composer check-cs
name: ${{ matrix.actions.name }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Cache Composer dependencies
uses: actions/cache@v4
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
- name: Setup PHP
id: setup-php
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
extensions: 'ctype,curl,dom,iconv,imagick,intl,json,mbstring,openssl,pcre,pdo,reflection,spl,zip'
ini-values: post_max_size=256M, max_execution_time=180, memory_limit=512M
tools: composer:v2
- name: Install Composer dependencies
run: composer install --no-interaction --no-ansi --no-progress
- run: ${{ matrix.actions.run }}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## 2.0.1 - 2024-05-26
### Fixed
- Fixed issues with saving settings

## 2.0.0
### Added
- Initial Craft CMS 4 release
Expand Down
20 changes: 19 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "superbig/craft-mjml",
"description": "Render Twig emails with MJML, the only framework that makes responsive email easy.",
"type": "craft-plugin",
"version": "2.0.0",
"version": "2.0.1",
"keywords": [
"craft",
"cms",
Expand All @@ -25,11 +25,29 @@
"craftcms/cms": "^4.0.0-beta.1",
"mikehaertl/php-shellcommand": "^1.4"
},
"require-dev": {
"craftcms/ecs": "dev-main",
"craftcms/phpstan": "dev-main",
"craftcms/rector": "dev-main"
},
"autoload": {
"psr-4": {
"superbig\\mjml\\": "src/"
}
},
"scripts": {
"phpstan": "phpstan --ansi --memory-limit=1G",
"check-cs": "ecs check --ansi",
"fix-cs": "ecs check --fix --ansi"
},
"config": {
"allow-plugins": {
"craftcms/plugin-installer": true,
"yiisoft/yii2-composer": true
},
"optimize-autoloader": true,
"sort-packages": true
},
"extra": {
"name": "MJML",
"handle": "mjml",
Expand Down
14 changes: 14 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

use craft\ecs\SetList;
use Symplify\EasyCodingStandard\Config\ECSConfig;

return static function(ECSConfig $ecsConfig): void {
$ecsConfig->paths([
__DIR__ . '/src',
__FILE__,
]);

$ecsConfig->parallel();
$ecsConfig->sets([SetList::CRAFT_CMS_4]);
};
6 changes: 6 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
includes:
- %currentWorkingDirectory%/vendor/craftcms/phpstan/phpstan.neon
parameters:
level: 5
paths:
- src
39 changes: 17 additions & 22 deletions src/MJML.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@

namespace superbig\mjml;

use superbig\mjml\services\MJMLService;
use superbig\mjml\variables\MJMLVariable;
use superbig\mjml\twigextensions\MJMLTwigExtension;
use superbig\mjml\models\Settings;

use Craft;
use craft\base\Plugin;
use craft\services\Plugins;
use craft\events\PluginEvent;
use craft\web\UrlManager;
use craft\web\twig\variables\CraftVariable;
use craft\events\RegisterUrlRulesEvent;
use craft\web\twig\variables\CraftVariable;

use craft\web\UrlManager;
use superbig\mjml\models\Settings;
use superbig\mjml\services\MJMLService;
use superbig\mjml\twigextensions\MJMLTwigExtension;
use superbig\mjml\variables\MJMLVariable;

use Twig\Error\LoaderError;
use Twig\Error\RuntimeError;
use Twig\Error\SyntaxError;
use yii\base\Event;
use yii\base\Exception;

/**
* Class MJML
Expand All @@ -37,14 +39,7 @@
*/
class MJML extends Plugin
{
/**
* @var MJML
*/
public static $plugin;

/**
* @var string
*/
public static MJML $plugin;
public string $schemaVersion = '1.0.0';

/**
Expand Down Expand Up @@ -89,18 +84,18 @@ function(Event $event) {
);
}

/**
* @inheritdoc
*/
protected function createSettingsModel(): ?\craft\base\Model
{
return new Settings();
}

/**
* @inheritdoc
* @throws SyntaxError
* @throws Exception
* @throws RuntimeError
* @throws LoaderError
*/
protected function settingsHtml(): ?string
protected function settingsHtml(): string
{
return Craft::$app->view->renderTemplate(
'mjml/settings',
Expand Down
8 changes: 4 additions & 4 deletions src/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@

return [
// The path to where the your version of Node is located, i.e. `/usr/local/bin/node`
'nodePath' => '',
'nodePath' => '',

// The path to where the MJML cli installed with npm is located, i.e. `/usr/local/bin/mjml`
'mjmlCliPath' => '',
'mjmlCliPath' => '',

// cli config args, e.g. `--config.minify true`',
'mjmlCliConfigArgs' => '',
'mjmlCliConfigArgs' => '',

// The app id received by email
'appId' => '',
'appId' => '',

// Enter the secret key received by email
'secretKey' => '',
Expand Down
33 changes: 12 additions & 21 deletions src/models/MJMLModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

namespace superbig\mjml\models;

use craft\helpers\Template;
use craft\base\Model;
use craft\helpers\Template;

/**
* @author Superbig
Expand All @@ -20,36 +20,27 @@
*/
class MJMLModel extends Model
{
// Public Properties
// =========================================================================
public string $html;
public string $mjml;

/**
* @var string
*/
public $html;

/**
* @var string
*/
public $mjml;
public function output(): \Twig\Markup
{
return Template::raw($this->html);
}

/**
* @var string
* @param array{html: string, mjml: string} $results
* @return MJMLModel
*/
public $mjmlVersion;

// Public Methods
// =========================================================================

public function output()
public static function create(array $results): MJMLModel
{
return Template::raw($this->html);
return new self($results);
}

/**
* @inheritdoc
*/
public function rules(): array
public function defineRules(): array
{
return [
[['html', 'mjml'], 'string'],
Expand Down
78 changes: 39 additions & 39 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

namespace superbig\mjml\models;

use superbig\mjml\MJML;

use Craft;

use craft\base\Model;
use craft\behaviors\EnvAttributeParserBehavior;

/**
* @author Superbig
Expand All @@ -22,38 +22,12 @@
*/
class Settings extends Model
{
// Public Properties
// =========================================================================

/**
* @var string
*/
public $nodePath = '';

/**
* @var string
*/
public $mjmlCliPath = '';

/**
* @var string
*/
public $mjmlCliConfigArgs = '';

/**
* @var string
*/
public $mjmlCliIncludesPath = '';

/**
* @var string
*/
public $appId = '';

/**
* @var string
*/
public $secretKey = '';
public string $nodePath = '';
public string $mjmlCliPath = '';
public string $mjmlCliConfigArgs = '';
public string $mjmlCliIncludesPath = '';
public string $appId = '';
public string $secretKey = '';

public function init(): void
{
Expand All @@ -62,14 +36,40 @@ public function init(): void
parent::init();
}

/**
* @inheritdoc
*/
public function rules(): array
public function defineBehaviors(): array
{
return [
'parser' => [
'class' => EnvAttributeParserBehavior::class,
'attributes' => [
'nodePath',
'mjmlCliPath',
'mjmlCliConfigArgs',
'mjmlCliIncludesPath',
'appId',
'secretKey',
],
],
];
}

public function defineRules(): array
{
return [
[['appId', 'secretKey', 'mjmlCliPath', 'nodePath', 'mjmlCliConfigArgs'], 'string'],
[['appId', 'secretKey'], 'required'],
[['appId', 'secretKey'], 'required', 'when' => fn(Settings $model) => !empty($model->appId) || !empty($model->secretKey)],
[['mjmlCliPath', 'nodePath'], 'required', 'when' => fn(Settings $model) => !empty($model->mjmlCliPath) || !empty($model->nodePath)],
];
}

public function attributeLabels()
{
return [
'appId' => Craft::t('mjml', 'API App ID'),
'secretKey' => Craft::t('mjml', 'API Secret Key'),
'mjmlCliPath' => Craft::t('mjml', 'MJML Cli Path'),
'nodePath' => Craft::t('mjml', 'Node.js Path'),
'mjmlCliConfigArgs' => Craft::t('mjml', 'MJML Cli Config Arguments'),
];
}
}
Loading