diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 770b5d94..748b8c4f 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -6,7 +6,7 @@ use Symfony\Component\Config\Definition\ConfigurationInterface; /** - * TinymceBundle configuration structure. + * Configuration. */ class Configuration implements ConfigurationInterface { @@ -15,14 +15,14 @@ class Configuration implements ConfigurationInterface * * @return TreeBuilder */ - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $defaults = $this->getTinymceDefaults(); - $treeBuilder = new TreeBuilder('stfalcon_tinymce'); + $treeBuilder = new TreeBuilder(); return $treeBuilder - ->getRootNode() + ->root('stfalcon_tinymce', 'array') ->children() // Include jQuery (true) library or not (false) ->booleanNode('include_jquery')->defaultFalse()->end() @@ -79,23 +79,23 @@ public function getConfigTreeBuilder() * * @return array */ - private function getTinymceDefaults() + private function getTinymceDefaults(): array { - return array( - 'advanced' => array( - "theme" => "modern", - "plugins" => array( - "advlist autolink lists link image charmap print preview hr anchor pagebreak", - "searchreplace wordcount visualblocks visualchars code fullscreen", - "insertdatetime media nonbreaking save table contextmenu directionality", - "emoticons template paste textcolor", - ), - "toolbar1" => "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify - | bullist numlist outdent indent | link image", - "toolbar2" => "print preview media | forecolor backcolor emoticons", - "image_advtab" => true, - ), - 'simple' => array(), - ); + return [ + 'advanced' => [ + 'theme' => 'modern', + 'plugins' => [ + 'advlist autolink lists link image charmap print preview hr anchor pagebreak', + 'searchreplace wordcount visualblocks visualchars code fullscreen', + 'insertdatetime media nonbreaking save table contextmenu directionality', + 'emoticons template paste textcolor', + ], + 'toolbar1' => 'undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify + | bullist numlist outdent indent | link image', + 'toolbar2' => 'print preview media | forecolor backcolor emoticons', + 'image_advtab' => true, + ], + 'simple' => [], + ]; } } diff --git a/DependencyInjection/StfalconTinymceExtension.php b/DependencyInjection/StfalconTinymceExtension.php index ce97459b..026faa94 100644 --- a/DependencyInjection/StfalconTinymceExtension.php +++ b/DependencyInjection/StfalconTinymceExtension.php @@ -8,29 +8,29 @@ use Symfony\Component\HttpKernel\DependencyInjection\Extension; /** - * StfalconTinymceExtension + * StfalconTinymceExtension. */ class StfalconTinymceExtension extends Extension { /** - * Loads the StfalconTinymce configuration. + * Loads the StfalconTinymceBundle configuration. * * @param array $configs An array of configuration values * @param ContainerBuilder $container A ContainerBuilder instance */ - public function load(array $configs, ContainerBuilder $container) + public function load(array $configs, ContainerBuilder $container): void { // Get default configuration of the bundle $config = $this->processConfiguration(new Configuration(), $configs); if (empty($config['theme'])) { - $config['theme'] = array( - 'simple' => array(), - ); + $config['theme'] = [ + 'simple' => [], + ]; } else { foreach ($config['theme'] as &$bundleTheme) { // Quick fix for the removed obsolete themes - if (isset($bundleTheme['theme']) && in_array($bundleTheme['theme'], array('advanced', 'simple'))) { + if (isset($bundleTheme['theme']) && \in_array($bundleTheme['theme'], ['advanced', 'simple'], true)) { $bundleTheme['theme'] = 'modern'; } unset($bundleTheme); @@ -51,7 +51,7 @@ public function load(array $configs, ContainerBuilder $container) * * @return string The alias */ - public function getAlias() + public function getAlias(): string { return 'stfalcon_tinymce'; } diff --git a/Helper/LocaleHelper.php b/Helper/LocaleHelper.php index 2c75f10b..e2720ef2 100644 --- a/Helper/LocaleHelper.php +++ b/Helper/LocaleHelper.php @@ -3,13 +3,11 @@ namespace Stfalcon\Bundle\TinymceBundle\Helper; /** - * Class LocaleHelper - * - * @package Stfalcon\Bundle\TinymceBundle\Helper + * LocaleHelper. */ class LocaleHelper { - static private $locales = array( + private static $locales = [ 'bn' => 'bn_BD', 'bg' => 'bg_BG', 'cn' => 'zh_CN', @@ -21,17 +19,15 @@ class LocaleHelper 'tr' => 'tr_TR', 'tw' => 'zh_TW', 'uk' => 'uk_UA', - ); + ]; /** * @param string $locale * * @return string */ - public static function getLanguage($locale) + public static function getLanguage($locale): string { - return isset(self::$locales[$locale]) - ? self::$locales[$locale] - : $locale; + return self::$locales[$locale] ?? $locale; } } diff --git a/Twig/Extension/StfalconTinymceExtension.php b/Twig/Extension/StfalconTinymceExtension.php index 17d28ab7..6e18c64f 100644 --- a/Twig/Extension/StfalconTinymceExtension.php +++ b/Twig/Extension/StfalconTinymceExtension.php @@ -32,9 +32,8 @@ class StfalconTinymceExtension extends \Twig_Extension private $packages; /** - * Initialize tinymce helper - * * @param ContainerInterface $container + * @param Packages $packages */ public function __construct(ContainerInterface $container, Packages $packages) { @@ -43,8 +42,6 @@ public function __construct(ContainerInterface $container, Packages $packages) } /** - * Gets a service. - * * @param string $id The service identifier * * @return object The associated service @@ -73,13 +70,13 @@ public function getParameter($name) */ public function getFunctions() { - return array( + return [ 'tinymce_init' => new \Twig_SimpleFunction( 'tinymce_init', - array($this, 'tinymceInit'), - array('is_safe' => array('html')) + [$this, 'tinymceInit'], + ['is_safe' => ['html']] ), - ); + ]; } /** @@ -89,7 +86,7 @@ public function getFunctions() * * @return string */ - public function tinymceInit($options = array()) + public function tinymceInit($options = []): string { $config = $this->getParameter('stfalcon_tinymce.config'); $config = array_merge_recursive($config, $options); @@ -159,7 +156,7 @@ public function tinymceInit($options = array()) if (isset($themeOptions['content_css'])) { // As there may be multiple CSS Files specified we need to parse each of them individually $cssFiles = $themeOptions['content_css']; - if (!is_array($themeOptions['content_css'])) { + if (!\is_array($themeOptions['content_css'])) { $cssFiles = explode(',', $themeOptions['content_css']); } @@ -173,27 +170,30 @@ public function tinymceInit($options = array()) } } - $tinymceConfiguration = preg_replace( - array( + $tinymceConfiguration = \preg_replace( + [ '/"file_browser_callback":"([^"]+)"\s*/', '/"file_picker_callback":"([^"]+)"\s*/', '/"paste_preprocess":"([^"]+)"\s*/', - ), - array( + ], + [ 'file_browser_callback:$1', 'file_picker_callback:$1', '"paste_preprocess":$1', - ), - json_encode($config) + ], + \json_encode($config) ); - return $this->getService('twig')->render('@StfalconTinymce/Script/init.html.twig', array( - 'tinymce_config' => $tinymceConfiguration, - 'include_jquery' => $config['include_jquery'], - 'tinymce_jquery' => $config['tinymce_jquery'], - 'asset_package_name' => $assetPackageName, - 'base_url' => $this->baseUrl, - )); + return $this->getService('twig')->render( + '@StfalconTinymce/Script/init.html.twig', + [ + 'tinymce_config' => $tinymceConfiguration, + 'include_jquery' => $config['include_jquery'], + 'tinymce_jquery' => $config['tinymce_jquery'], + 'asset_package_name' => $assetPackageName, + 'base_url' => $this->baseUrl, + ] + ); } /** @@ -201,7 +201,7 @@ public function tinymceInit($options = array()) * * @return string The extension name */ - public function getName() + public function getName(): string { return 'stfalcon_tinymce'; } @@ -213,7 +213,7 @@ public function getName() * * @return string */ - protected function getAssetsUrl($inputUrl) + protected function getAssetsUrl(string $inputUrl): string { $assets = $this->packages; diff --git a/composer.json b/composer.json index 79253240..60cad226 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,7 @@ }, "require": { "php": "^7.1.3", - "symfony/framework-bundle": "^3.4||^4.0||^5.0" + "symfony/framework-bundle": "^3.4 || ^4.0" }, "autoload": { "psr-0": {