From 483654e134a1d3a8e8a14d2348cdae9e64dbd592 Mon Sep 17 00:00:00 2001 From: Awilum Date: Sat, 14 Aug 2021 17:50:06 +0300 Subject: [PATCH] feat(serializers): code styles and format updates --- src/flextype/core/Serializers/Frontmatter.php | 5 +++-- src/flextype/core/Serializers/Json.php | 2 +- src/flextype/core/Serializers/PhpArray.php | 1 + src/flextype/core/Serializers/PhpCode.php | 16 ++++++++++------ src/flextype/core/Serializers/Serializers.php | 8 +------- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/flextype/core/Serializers/Frontmatter.php b/src/flextype/core/Serializers/Frontmatter.php index 04d78f22..90c895cb 100644 --- a/src/flextype/core/Serializers/Frontmatter.php +++ b/src/flextype/core/Serializers/Frontmatter.php @@ -14,6 +14,7 @@ use function arrays; use function cache; use function count; use function implode; +use function in_array; use function ltrim; use function preg_replace; use function preg_split; @@ -41,7 +42,7 @@ class Frontmatter $headerSerializer = 'yaml'; } - if (! in_array($headerSerializer, $allowed)) { + if (! in_array($headerSerializer, $allowed)) { $headerSerializer = 'yaml'; } @@ -74,7 +75,7 @@ class Frontmatter $headerSerializer = 'yaml'; } - if (! in_array($headerSerializer, $allowed)) { + if (! in_array($headerSerializer, $allowed)) { $headerSerializer = 'yaml'; } diff --git a/src/flextype/core/Serializers/Json.php b/src/flextype/core/Serializers/Json.php index 1005b311..fc8eff85 100644 --- a/src/flextype/core/Serializers/Json.php +++ b/src/flextype/core/Serializers/Json.php @@ -61,7 +61,7 @@ class Json * Takes a JSON encoded string and converts it into a PHP variable. * * @param string $input A string containing JSON - * + * * @return mixed The JSON converted to a PHP value * * @throws RuntimeException If the JSON is not valid diff --git a/src/flextype/core/Serializers/PhpArray.php b/src/flextype/core/Serializers/PhpArray.php index 0be68d83..c5d3e0d1 100644 --- a/src/flextype/core/Serializers/PhpArray.php +++ b/src/flextype/core/Serializers/PhpArray.php @@ -14,6 +14,7 @@ use RuntimeException; use function cache; use function registry; use function strings; +use function var_export; class PhpArray { diff --git a/src/flextype/core/Serializers/PhpCode.php b/src/flextype/core/Serializers/PhpCode.php index a1ce5019..371f22ff 100644 --- a/src/flextype/core/Serializers/PhpCode.php +++ b/src/flextype/core/Serializers/PhpCode.php @@ -12,8 +12,13 @@ namespace Flextype\Serializers; use RuntimeException; use function cache; +use function error_get_last; +use function error_reporting; use function registry; use function strings; +use function var_export; + +use const E_ALL; class PhpCode { @@ -47,22 +52,21 @@ class PhpCode $cache = registry()->get('flextype.settings.serializers.phpcode.decode.cache'); $decode = static function (string $input) { - $currentErrorLevel = error_reporting(); error_reporting(E_ALL); $return = null; - $eval = @eval('$return=' . $input . ';'); - $error = error_get_last(); + $eval = @eval('$return=' . $input . ';'); + $error = error_get_last(); error_reporting($currentErrorLevel); if ($eval === false || $error) { $msg = 'Decoding PhpCode failed'; - + if ($eval === false) { $lastError = error_get_last(); - $msg .= ': ' . $lastError['message']; + $msg .= ': ' . $lastError['message']; } - + throw new RuntimeException($msg, 0, $error); } diff --git a/src/flextype/core/Serializers/Serializers.php b/src/flextype/core/Serializers/Serializers.php index ee433a7c..81777f70 100644 --- a/src/flextype/core/Serializers/Serializers.php +++ b/src/flextype/core/Serializers/Serializers.php @@ -10,12 +10,6 @@ declare(strict_types=1); namespace Flextype\Serializers; use Atomastic\Macroable\Macroable; -use Flextype\Serializers\Json; -use Flextype\Serializers\Yaml; -use Flextype\Serializers\Frontmatter; -use Flextype\Serializers\Neon; -use Flextype\Serializers\PhpArray; -use Flextype\Serializers\PhpCode; class Serializers { @@ -44,7 +38,7 @@ class Serializers { return new Frontmatter(); } - + /** * Create a Neon instance. */