Skip to content

Commit

Permalink
chore: fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Fred Carlsen <[email protected]>
  • Loading branch information
sjelfull committed May 15, 2024
1 parent 5c303d9 commit 1d65794
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 120 deletions.
25 changes: 11 additions & 14 deletions src/MJML.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
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 @@ -35,15 +39,8 @@
*/
class MJML extends Plugin
{
/**
* @var MJML
*/
public static $plugin;

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

Check failure on line 43 in src/MJML.php

View workflow job for this annotation

GitHub Actions / PHPStan

Property superbig\mjml\MJML::$schemaVersion (string) overriding property craft\base\Plugin::$schemaVersion should not have a native type.

/**
* @inheritdoc
Expand Down Expand Up @@ -87,16 +84,16 @@ function(Event $event) {
);
}

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

/**
* @inheritdoc
* @throws SyntaxError
* @throws Exception
* @throws RuntimeError
* @throws LoaderError
*/
protected function settingsHtml(): string
{
Expand Down
27 changes: 5 additions & 22 deletions src/models/MJMLModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,19 @@
*/
class MJMLModel extends Model
{
// Public Properties
// =========================================================================
public string $html;
public string $mjml;
public string $mjmlVersion;

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

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

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

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

public function output()
public function output(): \Twig\Markup
{
return Template::raw($this->html);
}

/**
* @inheritdoc
*/
public function rules()
public function rules(): array
{
return [
[['html', 'mjml'], 'string'],
Expand Down
52 changes: 14 additions & 38 deletions src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,50 +22,26 @@
*/
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 function init()
public string $nodePath = '';
public string $mjmlCliPath = '';
public string $mjmlCliConfigArgs = '';
public string $mjmlCliIncludesPath = '';
public string $appId = '';
public string $secretKey = '';

public function init(): void
{
$this->mjmlCliIncludesPath = Craft::$app->getView()->getTemplatesPath();

parent::init();
}

/**
* @inheritdoc
*/
public function rules()
public function behaviors()

Check failure on line 39 in src/models/Settings.php

View workflow job for this annotation

GitHub Actions / PHPStan

Method superbig\mjml\models\Settings::behaviors() should return array but return statement is missing.
{

}

public function rules(): array
{
return [
[['appId', 'secretKey', 'mjmlCliPath', 'nodePath', 'mjmlCliConfigArgs'], 'string'],
Expand Down
41 changes: 10 additions & 31 deletions src/twigextensions/MJMLTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,51 +11,36 @@
namespace superbig\mjml\twigextensions;

use superbig\mjml\MJML;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;

/**
* @author Superbig
* @package MJML
* @since 1.0.0
*/
class MJMLTwigExtension extends \Twig_Extension
class MJMLTwigExtension extends AbstractExtension
{
// Public Methods
// =========================================================================

/**
* @inheritdoc
*/
public function getName()
public function getName(): string
{
return 'MJML';
}

/**
* @inheritdoc
*/
public function getFilters()
public function getFilters(): array
{
return [
new \Twig_SimpleFilter('mjml', [$this, 'mjml']),
new \Twig_SimpleFilter('mjmlCli', [$this, 'mjmlCli']),
new TwigFilter('mjml', [$this, 'mjml']),
new TwigFilter('mjmlCli', [$this, 'mjmlCli']),
];
}

/**
* @inheritdoc
*/
public function getFunctions()
public function getFunctions(): array
{
return [
];
}

/**
* @param null $html
*
* @return string
*/
public function mjml($html = null)
public function mjml($html = null): ?string
{
$result = MJML::$plugin->mjmlService->parse($html);

Expand All @@ -66,13 +51,7 @@ public function mjml($html = null)
return $result->output();
}

/**
* @param null $html
*
* @return string
* @throws \yii\base\ErrorException
*/
public function mjmlCli($html = null)
public function mjmlCli($html = null): ?string
{
$result = MJML::$plugin->mjmlService->parseCli($html);

Expand Down
17 changes: 2 additions & 15 deletions src/variables/MJMLVariable.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,12 @@
*/
class MJMLVariable
{
// Public Methods
// =========================================================================

/**
* @param null|string $html
*
* @return MJMLModel|null
*/
public function parse($html = null)
public function parse(string $html = null): ?MJMLModel
{
return MJML::$plugin->mjmlService->parse($html);
}

/**
* @param string $template
*
* @return MJMLModel|null
*/
public function include(string $template = '', $variables = null, $renderMethod = 'cli')
public function include(string $template = '', $variables = null, $renderMethod = 'cli'): \Twig\Markup
{
return Template::raw(MJML::$plugin->mjmlService->include($template, $variables, $renderMethod));
}
Expand Down

0 comments on commit 1d65794

Please sign in to comment.