From ad075be66846d1275d2f79c3a09fbb39e7d77b06 Mon Sep 17 00:00:00 2001 From: Awilum Date: Fri, 14 Aug 2020 21:37:30 +0300 Subject: [PATCH] feat(core): Flextype Solid Core - next round #458 --- src/flextype/app/Support/Collection.php | 2 +- .../app/Support/Helpers/CollectionHelper.php | 12 ++++----- .../app/Support/Helpers/FinderHelper.php | 26 +++++++++---------- .../app/Support/Parsers/Shortcode.php | 5 ++-- .../Parsers/Shortcodes/EntriesShortcode.php | 5 ++-- .../Parsers/Shortcodes/RawShortcode.php | 5 ++-- .../Parsers/Shortcodes/RegistryShortcode.php | 3 +-- .../Parsers/Shortcodes/UrlShortcode.php | 3 +-- .../app/Support/Serializers/Frontmatter.php | 5 ++-- src/flextype/app/Support/Serializers/Yaml.php | 3 ++- 10 files changed, 33 insertions(+), 36 deletions(-) diff --git a/src/flextype/app/Support/Collection.php b/src/flextype/app/Support/Collection.php index 3322b212..1c2154dc 100644 --- a/src/flextype/app/Support/Collection.php +++ b/src/flextype/app/Support/Collection.php @@ -221,7 +221,7 @@ class Collection * * @param int|null $firstResult The value to set. * - * @return + * @return * * @access public */ diff --git a/src/flextype/app/Support/Helpers/CollectionHelper.php b/src/flextype/app/Support/Helpers/CollectionHelper.php index e6c9acb5..a8b320e6 100644 --- a/src/flextype/app/Support/Helpers/CollectionHelper.php +++ b/src/flextype/app/Support/Helpers/CollectionHelper.php @@ -35,7 +35,7 @@ if (! function_exists('collect_filter')) { $collection = new Collection($items); // Bind: return - $bind_return = isset($filter['return']) ? $filter['return'] : 'all'; + $bind_return = $filter['return'] ?? 'all'; // Bind: where $bind_where = []; @@ -113,20 +113,20 @@ if (! function_exists('collect_filter')) { break; case 'random': $bind_random_value = isset($filter['random_value']) ? (int) $filter['random_value'] : null; - $items = $collection->random($bind_random_value); + $items = $collection->random($bind_random_value); break; case 'limit': $bind_set_max_result_value = isset($filter['limit_value']) ? (int) $filter['limit_value'] : 0; - $items = $collection->limit($bind_set_max_result_value); + $items = $collection->limit($bind_set_max_result_value); break; case 'set_first_result': $bind_set_first_result_value = isset($filter['set_first_result_value']) ? (int) $filter['set_first_result_value'] : 0; - $items = $collection->setFirstResult($bind_set_first_result_value); + $items = $collection->setFirstResult($bind_set_first_result_value); break; case 'slice': $bind_slice_offset_value = isset($filter['slice_offset_value']) ? (int) $filter['slice_offset_value'] : 0; - $bind_slice_limit_value = isset($filter['slice_limit_value']) ? (int) $filter['slice_limit_value'] : 0; - $items = $collection->slice($bind_slice_offset_value, $bind_slice_limit_value); + $bind_slice_limit_value = isset($filter['slice_limit_value']) ? (int) $filter['slice_limit_value'] : 0; + $items = $collection->slice($bind_slice_offset_value, $bind_slice_limit_value); break; case 'exists': $items = $collection->exists(); diff --git a/src/flextype/app/Support/Helpers/FinderHelper.php b/src/flextype/app/Support/Helpers/FinderHelper.php index fccef1cf..3953fbbe 100644 --- a/src/flextype/app/Support/Helpers/FinderHelper.php +++ b/src/flextype/app/Support/Helpers/FinderHelper.php @@ -27,19 +27,19 @@ if (! function_exists('find_filter')) { { $find = find()->in($path); - isset($filter['depth']) and $find->depth($filter['depth']) or $find->depth(1); - isset($filter['date']) and $find->date($filter['date']); - isset($filter['size']) and $find->size($filter['size']); - isset($filter['exclude']) and $find->exclude($filter['exclude']); - isset($filter['contains']) and $find->contains($filter['contains']); - isset($filter['not_contains']) and $find->notContains($filter['not_contains']); - isset($filter['filter']) and $find->filter($filter['filter']); - isset($filter['sort']) and $find->sort($filter['sort']); - isset($filter['path']) and $find->path($filter['path']); - isset($filter['sort_by']) && $filter['sort_by'] == 'atime' and $find->sortByAccessedTime(); - isset($filter['sort_by']) && $filter['sort_by'] == 'mtime' and $find->sortByModifiedTime(); - isset($filter['sort_by']) && $filter['sort_by'] == 'ctime' and $find->sortByChangedTime(); + isset($filter['depth']) and $find->depth($filter['depth']) or $find->depth(1); + isset($filter['date']) and $find->date($filter['date']); + isset($filter['size']) and $find->size($filter['size']); + isset($filter['exclude']) and $find->exclude($filter['exclude']); + isset($filter['contains']) and $find->contains($filter['contains']); + isset($filter['not_contains']) and $find->notContains($filter['not_contains']); + isset($filter['filter']) and $find->filter($filter['filter']); + isset($filter['sort']) and $find->sort($filter['sort']); + isset($filter['path']) and $find->path($filter['path']); + isset($filter['sort_by']) && $filter['sort_by'] === 'atime' and $find->sortByAccessedTime(); + isset($filter['sort_by']) && $filter['sort_by'] === 'mtime' and $find->sortByModifiedTime(); + isset($filter['sort_by']) && $filter['sort_by'] === 'ctime' and $find->sortByChangedTime(); - return ($search_in == 'files') ? $find->files() : $find->directories(); + return $search_in === 'files' ? $find->files() : $find->directories(); } } diff --git a/src/flextype/app/Support/Parsers/Shortcode.php b/src/flextype/app/Support/Parsers/Shortcode.php index d392de81..000b40ad 100644 --- a/src/flextype/app/Support/Parsers/Shortcode.php +++ b/src/flextype/app/Support/Parsers/Shortcode.php @@ -52,7 +52,7 @@ class Shortcode * * @access public */ - public function addHandler(string $name, $handler) + public function addHandler(string $name, callable $handler) { return $this->shortcode->addHandler($name, $handler); } @@ -65,7 +65,8 @@ class Shortcode * * @access public */ - public function addEventHandler($name, $handler) { + public function addEventHandler(string $name, callable $handler) + { return $this->shortcode->addEventHandler($name, $handler); } diff --git a/src/flextype/app/Support/Parsers/Shortcodes/EntriesShortcode.php b/src/flextype/app/Support/Parsers/Shortcodes/EntriesShortcode.php index 390978a3..3d64dc5e 100644 --- a/src/flextype/app/Support/Parsers/Shortcodes/EntriesShortcode.php +++ b/src/flextype/app/Support/Parsers/Shortcodes/EntriesShortcode.php @@ -7,13 +7,12 @@ declare(strict_types=1); * Founded by Sergey Romanenko and maintained by Flextype Community. */ -use Thunder\Shortcode\Shortcode\ShortcodeInterface; use Flextype\Component\Arrays\Arrays; +use Thunder\Shortcode\Shortcode\ShortcodeInterface; if ($flextype->container('registry')->get('flextype.settings.shortcode.shortcodes.entries.enabled')) { - // Shortcode: [entries_fetch id="entry-id" field="field-name" default="default-value"] - $flextype->container('shortcode')->addHandler('entries_fetch', function (ShortcodeInterface $s) use ($flextype) { + $flextype->container('shortcode')->addHandler('entries_fetch', static function (ShortcodeInterface $s) use ($flextype) { return Arrays::get($flextype['entries']->fetch($s->getParameter('id')), $s->getParameter('field'), $s->getParameter('default')); }); } diff --git a/src/flextype/app/Support/Parsers/Shortcodes/RawShortcode.php b/src/flextype/app/Support/Parsers/Shortcodes/RawShortcode.php index 14d44309..f583d3c9 100644 --- a/src/flextype/app/Support/Parsers/Shortcodes/RawShortcode.php +++ b/src/flextype/app/Support/Parsers/Shortcodes/RawShortcode.php @@ -7,14 +7,13 @@ declare(strict_types=1); * Founded by Sergey Romanenko and maintained by Flextype Community. */ -use Thunder\Shortcode\Shortcode\ShortcodeInterface; use Thunder\Shortcode\EventHandler\FilterRawEventHandler; use Thunder\Shortcode\Events; +use Thunder\Shortcode\Shortcode\ShortcodeInterface; if ($flextype->container('registry')->get('flextype.settings.shortcode.shortcodes.raw.enabled')) { - // Shortcode: [raw] - $flextype->container('shortcode')->addHandler('raw', function (ShortcodeInterface $s) use ($flextype) { + $flextype->container('shortcode')->addHandler('raw', static function (ShortcodeInterface $s) { return $s->getContent(); }); diff --git a/src/flextype/app/Support/Parsers/Shortcodes/RegistryShortcode.php b/src/flextype/app/Support/Parsers/Shortcodes/RegistryShortcode.php index 85e9ae40..d7e9548f 100644 --- a/src/flextype/app/Support/Parsers/Shortcodes/RegistryShortcode.php +++ b/src/flextype/app/Support/Parsers/Shortcodes/RegistryShortcode.php @@ -10,9 +10,8 @@ declare(strict_types=1); use Thunder\Shortcode\Shortcode\ShortcodeInterface; if ($flextype->container('registry')->get('flextype.settings.shortcode.shortcodes.registry.enabled')) { - // Shortcode: [registry_get name="item-name" default="default-value"] - $flextype->container('shortcode')->addHandler('registry_get', function (ShortcodeInterface $s) use ($flextype) { + $flextype->container('shortcode')->addHandler('registry_get', static function (ShortcodeInterface $s) use ($flextype) { return $flextype->container('registry')->get($s->getParameter('name'), $s->getParameter('default')); }); } diff --git a/src/flextype/app/Support/Parsers/Shortcodes/UrlShortcode.php b/src/flextype/app/Support/Parsers/Shortcodes/UrlShortcode.php index b268f992..ca49d79e 100644 --- a/src/flextype/app/Support/Parsers/Shortcodes/UrlShortcode.php +++ b/src/flextype/app/Support/Parsers/Shortcodes/UrlShortcode.php @@ -11,9 +11,8 @@ use Slim\Http\Environment; use Slim\Http\Uri; if ($flextype->container('registry')->get('flextype.settings.shortcode.shortcodes.url.enabled')) { - // Shortcode: [url] - $flextype->container('shortcode')->addHandler('url', function () use ($flextype) { + $flextype->container('shortcode')->addHandler('url', static function () use ($flextype) { if ($flextype->container('registry')->has('flextype.settings.url') && $flextype->container('registry')->get('flextype.settings.url') !== '') { return $flextype->container('registry')->get('flextype.settings.url'); } diff --git a/src/flextype/app/Support/Serializers/Frontmatter.php b/src/flextype/app/Support/Serializers/Frontmatter.php index 67208949..502c18e5 100644 --- a/src/flextype/app/Support/Serializers/Frontmatter.php +++ b/src/flextype/app/Support/Serializers/Frontmatter.php @@ -15,6 +15,7 @@ use function count; use function implode; use function ltrim; use function md5; +use function preg_replace; use function preg_split; use function trim; use const PHP_EOL; @@ -88,12 +89,10 @@ class Frontmatter $matter = $this->flextype->container('yaml')->encode($input); } - $encoded = '---' . "\n" . + return '---' . "\n" . $matter . '---' . "\n" . $content; - - return $encoded; } /** diff --git a/src/flextype/app/Support/Serializers/Yaml.php b/src/flextype/app/Support/Serializers/Yaml.php index 285d6d42..0adfeeb6 100644 --- a/src/flextype/app/Support/Serializers/Yaml.php +++ b/src/flextype/app/Support/Serializers/Yaml.php @@ -13,6 +13,7 @@ use RuntimeException; use Symfony\Component\Yaml\Exception\DumpException as SymfonyYamlDumpException; use Symfony\Component\Yaml\Exception\ParseException as SymfonyYamlParseException; use Symfony\Component\Yaml\Yaml as SymfonyYaml; +use function error_reporting; use function function_exists; use function ini_get; use function ini_set; @@ -44,7 +45,7 @@ class Yaml */ public function __construct($flextype) { - $this->flextype = $flextype; + $this->flextype = $flextype; } /**