From 034e10614a4fcab6c94da4b10db4af53c19da603 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bar=C3=A1=C5=A1ek?= Date: Wed, 28 Oct 2020 15:51:47 +0100 Subject: [PATCH] PHP 7.4 support --- README.md | 2 +- composer.json | 5 +++-- src/MjmlServer.php | 38 +++----------------------------------- 3 files changed, 7 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 81eab18..a95c90d 100644 --- a/README.md +++ b/README.md @@ -62,4 +62,4 @@ Minimal template configuration: -``` \ No newline at end of file +``` diff --git a/composer.json b/composer.json index e4d27a6..3747b90 100644 --- a/composer.json +++ b/composer.json @@ -9,12 +9,13 @@ } ], "require": { - "php": ">=7.1.0" + "php": ">=7.4.0" }, "require-dev": { "phpstan/phpstan": "^0.12.18", "tracy/tracy": "^2.7", - "phpstan/phpstan-nette": "^0.12.6" + "phpstan/phpstan-nette": "^0.12.6", + "symplify/easy-coding-standard": "^7.2" }, "autoload": { "classmap": [ diff --git a/src/MjmlServer.php b/src/MjmlServer.php index fcc6ffd..9262baf 100644 --- a/src/MjmlServer.php +++ b/src/MjmlServer.php @@ -7,9 +7,7 @@ final class MjmlServer { - - /** @var string */ - private $cacheDir; + private string $cacheDir; public function __construct(?string $cacheDir = null) @@ -39,10 +37,6 @@ public function run(): void } - /** - * @param string $template - * @return string - */ public function process(string $template): string { $templateContentHash = md5($template); @@ -65,14 +59,9 @@ public function process(string $template): string } - /** - * @param string $file - * @return string - */ private function processReturn(string $file): string { $return = str_replace(["\r\n", "\r"], "\n", $this->read($file)); - if (preg_match('/Error: ([^\n]+)/', $return, $parser)) { throw new \RuntimeException($parser[1]); } @@ -81,10 +70,6 @@ private function processReturn(string $file): string } - /** - * @param string $dir - * @param int $mode - */ private function createDir(string $dir, int $mode = 0777): void { if (!is_dir($dir) && !@mkdir($dir, $mode, true) && !is_dir($dir)) { // @ - dir may already exist @@ -93,10 +78,6 @@ private function createDir(string $dir, int $mode = 0777): void } - /** - * @param string $file - * @return string - */ private function read(string $file): string { $content = @file_get_contents($file); // @ is escalated to exception @@ -108,11 +89,6 @@ private function read(string $file): string } - /** - * @param string $file - * @param string $content - * @param int|null $mode - */ private function write(string $file, string $content, ?int $mode = 0666): void { $this->createDir(dirname($file)); @@ -125,26 +101,18 @@ private function write(string $file, string $content, ?int $mode = 0666): void } - /** - * @return string - */ private function getLastError(): string { return preg_replace('#^\w+\(.*?\): #', '', error_get_last()['message']); } - /** - * @param string $functionName - * @return bool - */ private function functionIsAvailable(string $functionName): bool { static $disabled; - if (\function_exists($functionName)) { if ($disabled === null && \is_string($disableFunctions = ini_get('disable_functions'))) { - $disabled = explode(',', $disableFunctions) ?: []; + $disabled = explode(',', $disableFunctions); } return \in_array($functionName, $disabled, true) === false; @@ -152,4 +120,4 @@ private function functionIsAvailable(string $functionName): bool return false; } -} \ No newline at end of file +}