diff --git a/build/phpcs/Joomla/Sniffs/Commenting/FileCommentSniff.php b/build/phpcs/Joomla/Sniffs/Commenting/FileCommentSniff.php index 9fbd98c550e88..cdd2454e7b1c7 100644 --- a/build/phpcs/Joomla/Sniffs/Commenting/FileCommentSniff.php +++ b/build/phpcs/Joomla/Sniffs/Commenting/FileCommentSniff.php @@ -362,6 +362,16 @@ protected function processTags($commentStart, $commentEnd) // Required tag missing. if ($info['required'] === true && in_array($tag, $foundTags) === false) { + // We don't use package tags in namespaced code or the bootstrap file + if ($tag == 'package') { + // this should return 0 if there is no namespaced tokens + $namespaced = $this->currentFile->findNext(T_NAMESPACE, 0); + + if ($namespaced !== 0 || strpos($this->currentFile->getFilename(), '/libraries/bootstrap.php')) { + continue; + } + } + $error = 'Missing @%s tag in %s comment'; $data = array( $tag, diff --git a/components/com_tags/views/tag/view.html.php b/components/com_tags/views/tag/view.html.php index 9ef27488c0861..83e6ea4fcd9a9 100644 --- a/components/com_tags/views/tag/view.html.php +++ b/components/com_tags/views/tag/view.html.php @@ -94,15 +94,15 @@ public function display($tpl = null) !empty($itemElement->core_body)? $itemElement->text = $itemElement->core_body : $itemElement->text = null; JPluginHelper::importPlugin('content'); - JFactory::getApplication()->triggerEvent('onContentPrepare', array ('com_tags.tag', &$itemElement, &$itemElement->core_params, 0)); + JFactory::getApplication()->triggerEvent('onContentPrepare', ['com_tags.tag', &$itemElement, &$itemElement->core_params, 0]); - $results = JFactory::getApplication()->triggerEvent('onContentAfterTitle', array('com_tags.tag', &$itemElement, &$itemElement->core_params, 0)); + $results = JFactory::getApplication()->triggerEvent('onContentAfterTitle', ['com_tags.tag', &$itemElement, &$itemElement->core_params, 0]); $itemElement->event->afterDisplayTitle = trim(implode("\n", $results)); - $results = JFactory::getApplication()->triggerEvent('onContentBeforeDisplay', array('com_tags.tag', &$itemElement, &$itemElement->core_params, 0)); + $results = JFactory::getApplication()->triggerEvent('onContentBeforeDisplay', ['com_tags.tag', &$itemElement, &$itemElement->core_params, 0]); $itemElement->event->beforeDisplayContent = trim(implode("\n", $results)); - $results = JFactory::getApplication()->triggerEvent('onContentAfterDisplay', array('com_tags.tag', &$itemElement, &$itemElement->core_params, 0)); + $results = JFactory::getApplication()->triggerEvent('onContentAfterDisplay', ['com_tags.tag', &$itemElement, &$itemElement->core_params, 0]); $itemElement->event->afterDisplayContent = trim(implode("\n", $results)); // Write the results back into the body diff --git a/libraries/cms/application/cms.php b/libraries/cms/application/cms.php index ea87c55306765..04cf16820ab44 100644 --- a/libraries/cms/application/cms.php +++ b/libraries/cms/application/cms.php @@ -459,7 +459,7 @@ public static function getInstance($name = null, $prefix = 'JApplication', Conta } else { - // TODO - This creates an implicit hard requirement on the JApplicationCms constructor... If we ever get around to "true" DI, this'll go away anyway + // TODO - This creates an implicit hard requirement on the JApplicationCms constructor static::$instances[$name] = new $classname(null, null, null, $container); } } diff --git a/libraries/cms/captcha/captcha.php b/libraries/cms/captcha/captcha.php index c7bfa2c7974f8..741e2c266bdbd 100644 --- a/libraries/cms/captcha/captcha.php +++ b/libraries/cms/captcha/captcha.php @@ -110,9 +110,10 @@ public static function getInstance($captcha, array $options = array()) */ public function initialise($id) { - $event = new Event('onInit', [ - 'id' => $id - ]); + $event = new Event( + 'onInit', + ['id' => $id] + ); try { @@ -153,11 +154,14 @@ public function display($name, $id, $class = '') return ''; } - $event = new Event('onDisplay', [ - 'name' => $name, - 'id' => $id ? $id : $name, - 'class' => $class ? 'class="' . $class . '"' : '', - ]); + $event = new Event( + 'onDisplay', + [ + 'name' => $name, + 'id' => $id ? $id : $name, + 'class' => $class ? 'class="' . $class . '"' : '', + ] + ); $result = $this->getDispatcher()->dispatch('onInit', $event); @@ -182,9 +186,10 @@ public function checkAnswer($code) return false; } - $event = new Event('onCheckAnswer', [ - 'code' => $code - ]); + $event = new Event( + 'onCheckAnswer', + ['code' => $code] + ); $result = $this->getDispatcher()->dispatch('onCheckAnswer', $event); diff --git a/libraries/cms/plugin/plugin.php b/libraries/cms/plugin/plugin.php index ccd4d944bde82..75a68e0a1cad4 100644 --- a/libraries/cms/plugin/plugin.php +++ b/libraries/cms/plugin/plugin.php @@ -245,64 +245,70 @@ protected function registerListeners() * * @param string $methodName The method name to register * + * @return void + * * @since 4.0 */ protected final function registerLegacyListener($methodName) { - $this->getDispatcher()->addListener($methodName, function(AbstractEvent $event) use ($methodName) { - // Get the event arguments - $arguments = $event->getArguments(); - - // Map the associative argument array to a numeric indexed array for efficiency (see the switch statement below). - $arguments = array_values($arguments); - - // Extract any old results; they must not be part of the method call. - $allResults = []; - - if (isset($arguments['result'])) - { - $allResults = $arguments['result']; - - unset($arguments['result']); - } - - /** - * Calling the method directly is faster than using call_user_func_array, hence this argument - * unpacking switch statement. Please do not wrap it back to a single line, it will hurt performance. - * - * If we raise minimum requirements to PHP 5.6 we can use array unpacking and remove the switch for - * even better results, i.e. replace the switch with: - * $result = $this->{$methodName}(...$arguments); - */ - switch (count($arguments)) + $this->getDispatcher()->addListener( + $methodName, + function (AbstractEvent $event) use ($methodName) { - case 0: - $result = $this->{$methodName}(); - break; - case 1: - $result = $this->{$methodName}($arguments[0]); - break; - case 2: - $result = $this->{$methodName}($arguments[0], $arguments[1]); - break; - case 3: - $result = $this->{$methodName}($arguments[0], $arguments[1], $arguments[2]); - break; - case 4: - $result = $this->{$methodName}($arguments[0], $arguments[1], $arguments[2], $arguments[3]); - break; - case 5: - $result = $this->{$methodName}($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4]); - break; - default: - $result = call_user_func_array(array($this, $methodName), $arguments); - break; + // Get the event arguments + $arguments = $event->getArguments(); + + // Map the associative argument array to a numeric indexed array for efficiency (see the switch statement below). + $arguments = array_values($arguments); + + // Extract any old results; they must not be part of the method call. + $allResults = []; + + if (isset($arguments['result'])) + { + $allResults = $arguments['result']; + + unset($arguments['result']); + } + + /** + * Calling the method directly is faster than using call_user_func_array, hence this argument + * unpacking switch statement. Please do not wrap it back to a single line, it will hurt performance. + * + * If we raise minimum requirements to PHP 5.6 we can use array unpacking and remove the switch for + * even better results, i.e. replace the switch with: + * $result = $this->{$methodName}(...$arguments); + */ + switch (count($arguments)) + { + case 0: + $result = $this->{$methodName}(); + break; + case 1: + $result = $this->{$methodName}($arguments[0]); + break; + case 2: + $result = $this->{$methodName}($arguments[0], $arguments[1]); + break; + case 3: + $result = $this->{$methodName}($arguments[0], $arguments[1], $arguments[2]); + break; + case 4: + $result = $this->{$methodName}($arguments[0], $arguments[1], $arguments[2], $arguments[3]); + break; + case 5: + $result = $this->{$methodName}($arguments[0], $arguments[1], $arguments[2], $arguments[3], $arguments[4]); + break; + default: + $result = call_user_func_array(array($this, $methodName), $arguments); + break; + } + + // Restore the old results and add the new result from our method call + array_push($allResults, $result); + $event['result'] = $allResults; } - - // Restore the old results and add the new result from our method call - array_push($allResults, $result); - $event['result'] = $allResults; - }); + ); } /** @@ -311,9 +317,11 @@ protected final function registerLegacyListener($methodName) * * @param string $methodName The method name to register * + * @return void + * * @since 4.0 */ - protected final function registerListener($methodName) + final protected function registerListener($methodName) { $this->getDispatcher()->addListener($methodName, [$this, $methodName]); } diff --git a/libraries/joomla/application/daemon.php b/libraries/joomla/application/daemon.php index b3df19996cc08..a3b58cc35b0c1 100644 --- a/libraries/joomla/application/daemon.php +++ b/libraries/joomla/application/daemon.php @@ -21,7 +21,7 @@ * @see https://secure.php.net/manual/en/features.commandline.php * @since 11.1 */ -class JApplicationDaemon extends JApplicationCli +abstract class JApplicationDaemon extends JApplicationCli { /** * @var array The available POSIX signals to be caught by default. @@ -127,7 +127,7 @@ public function __construct(JInputCli $input = null, Registry $config = null, Di // @codeCoverageIgnoreEnd // Call the parent constructor. - parent::__construct($input, $config, $dispatcher); + parent::__construct($input, $config, null, null, $dispatcher); // Set some system limits. @set_time_limit($this->config->get('max_execution_time', 0)); diff --git a/libraries/joomla/database/interface.php b/libraries/joomla/database/interface.php index 58ab0187ef62a..b385f3191f72b 100644 --- a/libraries/joomla/database/interface.php +++ b/libraries/joomla/database/interface.php @@ -14,7 +14,7 @@ /** * Joomla Platform Database Interface * - * @since 11.2 + * @since 11.2 * @deprecated 5.0 Implement Joomla\Database\DatabaseInterface instead */ interface JDatabaseInterface extends DatabaseInterface diff --git a/libraries/legacy/controller/legacy.php b/libraries/legacy/controller/legacy.php index 3c0de90f0864f..3d947544a4876 100644 --- a/libraries/legacy/controller/legacy.php +++ b/libraries/legacy/controller/legacy.php @@ -300,10 +300,10 @@ public static function getInstance($prefix, $config = array()) { self::$instance = JFactory::getContainer()->get($class); } - else - { + else + { self::$instance = new $class($config); - } + } // Instantiate the class, store it to the static container, and return it return self::$instance = new $class($config); diff --git a/libraries/legacy/model/admin.php b/libraries/legacy/model/admin.php index 86083ca9c5377..50e4b5c6faea2 100644 --- a/libraries/legacy/model/admin.php +++ b/libraries/legacy/model/admin.php @@ -594,11 +594,14 @@ protected function batchTag($value, $pks, $contexts) $table->load($pk); $tags = array($value); - $setTagsEvent = Joomla\Cms\Event\AbstractEvent::create('TableSetNewTags', array( - 'subject' => $this, - 'newTags' => $tags, - 'replaceTags' => false - )); + $setTagsEvent = Joomla\Cms\Event\AbstractEvent::create( + 'TableSetNewTags', + array( + 'subject' => $this, + 'newTags' => $tags, + 'replaceTags' => false, + ) + ); try { diff --git a/libraries/legacy/view/category.php b/libraries/legacy/view/category.php index aa4666fe40b11..88c9d6a90eca1 100644 --- a/libraries/legacy/view/category.php +++ b/libraries/legacy/view/category.php @@ -166,15 +166,24 @@ public function commonCategoryDisplay() JPluginHelper::importPlugin('content'); - JFactory::getApplication()->triggerEvent('onContentPrepare', array($this->extension . '.category', &$itemElement, &$itemElement->params, 0)); + JFactory::getApplication()->triggerEvent('onContentPrepare', [$this->extension . '.category', &$itemElement, &$itemElement->params, 0]); - $results = JFactory::getApplication()->triggerEvent('onContentAfterTitle', array($this->extension . '.category', &$itemElement, &$itemElement->core_params, 0)); + $results = JFactory::getApplication()->triggerEvent( + 'onContentAfterTitle', + [$this->extension . '.category', &$itemElement, &$itemElement->core_params, 0] + ); $itemElement->event->afterDisplayTitle = trim(implode("\n", $results)); - $results = JFactory::getApplication()->triggerEvent('onContentBeforeDisplay', array($this->extension . '.category', &$itemElement, &$itemElement->core_params, 0)); + $results = JFactory::getApplication()->triggerEvent( + 'onContentBeforeDisplay', + [$this->extension . '.category', &$itemElement, &$itemElement->core_params, 0] + ); $itemElement->event->beforeDisplayContent = trim(implode("\n", $results)); - $results = JFactory::getApplication()->triggerEvent('onContentAfterDisplay', array($this->extension . '.category', &$itemElement, &$itemElement->core_params, 0)); + $results = JFactory::getApplication()->triggerEvent( + 'onContentAfterDisplay', + [$this->extension . '.category', &$itemElement, &$itemElement->core_params, 0] + ); $itemElement->event->afterDisplayContent = trim(implode("\n", $results)); if ($itemElement->text) diff --git a/libraries/src/Cms/Application/Autoconfigurable.php b/libraries/src/Cms/Application/Autoconfigurable.php index e92ca14bb77cb..ddc33bf8665c9 100644 --- a/libraries/src/Cms/Application/Autoconfigurable.php +++ b/libraries/src/Cms/Application/Autoconfigurable.php @@ -8,8 +8,6 @@ namespace Joomla\Cms\Application; -use Joomla\Registry\Registry; - /** * Trait for application classes which can automatically retrieve the global configuration * @@ -17,14 +15,6 @@ */ trait Autoconfigurable { - /** - * The application configuration object. - * - * @var Registry - * @since 4.0 - */ - protected $config; - /** * Method to load a PHP configuration class file based on convention and return the instantiated data object. * diff --git a/libraries/src/Cms/Application/EventAware.php b/libraries/src/Cms/Application/EventAware.php index 801ff712ae890..66203f1cbc97f 100644 --- a/libraries/src/Cms/Application/EventAware.php +++ b/libraries/src/Cms/Application/EventAware.php @@ -55,9 +55,9 @@ public function registerEvent($event, callable $handler) $this->getDispatcher()->addListener($event, $handler); } catch (\UnexpectedValueException $e) - { + { // No dispatcher is registered, don't throw an error (mimics old behavior) - } + } return $this; } @@ -71,10 +71,10 @@ public function registerEvent($event, callable $handler) * * This method will only return the 'result' argument of the event * - * @param string $eventName The event name. - * @param array|Event $args An array of arguments or an Event object (optional). + * @param string $eventName The event name. + * @param array|Event $args An array of arguments or an Event object (optional). * - * @return array An array of results from each function call, or null if no dispatcher is defined. + * @return array An array of results from each function call. Note this will be an empty array if no dispatcher is set. * * @since 4.0 * @throws \InvalidArgumentException diff --git a/plugins/editors-xtd/readmore/readmore.php b/plugins/editors-xtd/readmore/readmore.php index 63ed12ea727d7..10eca686efe42 100644 --- a/plugins/editors-xtd/readmore/readmore.php +++ b/plugins/editors-xtd/readmore/readmore.php @@ -39,9 +39,10 @@ public function onDisplay($name) // Button is not active in specific content components - $event = new Event('getContent', [ - 'name' => $name - ]); + $event = new Event( + 'getContent', + ['name' => $name] + ); $getContentResult = $this->getDispatcher()->dispatch('getContent', $event); $getContent = $getContentResult['result'][0]; $present = JText::_('PLG_READMORE_ALREADY_EXISTS', true); diff --git a/plugins/editors/codemirror/codemirror.php b/plugins/editors/codemirror/codemirror.php index 45e7c478f14a8..f782d7e1f7a90 100644 --- a/plugins/editors/codemirror/codemirror.php +++ b/plugins/editors/codemirror/codemirror.php @@ -298,15 +298,11 @@ protected function displayButtons($name, $buttons, $asset, $author) { $return = ''; - $args = array( - 'name' => $name, - 'event' => 'onGetInsertMethod' + $onGetInsertMethodEvent = new Event( + 'onGetInsertMethod', + ['name' => $name] ); - $onGetInsertMethodEvent = new Event('onGetInsertMethod', [ - 'name' => $name, - ]); - $rawResults = $this->getDispatcher()->dispatch('onGetInsertMethod', $onGetInsertMethodEvent); $results = $rawResults['result']; @@ -323,10 +319,13 @@ protected function displayButtons($name, $buttons, $asset, $author) if (is_array($buttons) || (is_bool($buttons) && $buttons)) { - $buttonsEvent = new Event('getButtons', [ - 'name' => $this->_name, - 'buttons' => $buttons, - ]); + $buttonsEvent = new Event( + 'getButtons', + [ + 'name' => $this->_name, + 'buttons' => $buttons, + ] + ); $buttonsResult = $this->getDispatcher()->dispatch('getButtons', $buttonsEvent); $buttons = $buttonsResult['result']; diff --git a/plugins/editors/none/none.php b/plugins/editors/none/none.php index 7f84838b66e51..44619214ffcdb 100644 --- a/plugins/editors/none/none.php +++ b/plugins/editors/none/none.php @@ -139,9 +139,10 @@ public function _displayButtons($name, $buttons, $asset, $author) { $return = ''; - $onGetInsertMethodEvent = new Event('onGetInsertMethod', [ - 'name' => $name, - ]); + $onGetInsertMethodEvent = new Event( + 'onGetInsertMethod', + ['name' => $name] + ); $rawResults = $this->getDispatcher()->dispatch('onGetInsertMethod', $onGetInsertMethodEvent); $results = $rawResults['result']; @@ -159,10 +160,13 @@ public function _displayButtons($name, $buttons, $asset, $author) if (is_array($buttons) || (is_bool($buttons) && $buttons)) { - $buttonsEvent = new \Joomla\Event\Event('getButtons', [ - 'name' => $this->_name, - 'buttons' => $buttons, - ]); + $buttonsEvent = new Event( + 'getButtons', + [ + 'name' => $this->_name, + 'buttons' => $buttons, + ] + ); $buttonsResult = $this->getDispatcher()->dispatch('getButtons', $buttonsEvent); $buttons = $buttonsResult['result']; diff --git a/plugins/editors/tinymce/tinymce.php b/plugins/editors/tinymce/tinymce.php index 40f19c24d64c0..fcbbd5759a19b 100644 --- a/plugins/editors/tinymce/tinymce.php +++ b/plugins/editors/tinymce/tinymce.php @@ -275,7 +275,7 @@ public function onDisplay($name, $content, $width, $height, $col, $row, $buttons // Paragraph $forcenewline = "force_br_newlines : false, force_p_newlines : true, forced_root_block : 'p',"; } - + $ignore_filter = false; // Text filtering @@ -283,7 +283,7 @@ public function onDisplay($name, $content, $width, $height, $col, $row, $buttons { // Use filters from com_config $filter = static::getGlobalFilters(); - + $ignore_filter = $filter === false; $tagBlacklist = !empty($filter->tagBlacklist) ? $filter->tagBlacklist : array(); @@ -1000,10 +1000,13 @@ private function _toogleButton($name) private function tinyButtons($name, $excluded) { // Get the available buttons - $buttonsEvent = new Event('getButtons', [ - 'name' => $this->_name, - 'buttons' => $excluded, - ]); + $buttonsEvent = new Event( + 'getButtons', + [ + 'name' => $this->_name, + 'buttons' => $excluded, + ] + ); $buttonsResult = $this->getDispatcher()->dispatch('getButtons', $buttonsEvent); $buttons = $buttonsResult['result']; diff --git a/plugins/user/profile/profile.php b/plugins/user/profile/profile.php index 5a793b9006840..06812c1e68dc4 100644 --- a/plugins/user/profile/profile.php +++ b/plugins/user/profile/profile.php @@ -75,13 +75,16 @@ public function onContentPrepareData($context, $data) // Load the profile data from the database. $db = JFactory::getDbo(); $query = $db->getQuery(true) - ->select(array( - $db->qn('profile_key'), - $db->qn('profile_value'), - ))->from('#__user_profiles') - ->where($db->qn('user_id') . ' = ' . $db->q((int) $userId)) - ->where($db->qn('profile_key') . ' LIKE ' . $db->qn('profile.%')) - ->order($db->qn('ordering')); + ->select( + array( + $db->qn('profile_key'), + $db->qn('profile_value'), + ) + ) + ->from('#__user_profiles') + ->where($db->qn('user_id') . ' = ' . $db->q((int) $userId)) + ->where($db->qn('profile_key') . ' LIKE ' . $db->qn('profile.%')) + ->order($db->qn('ordering')); $db->setQuery($query); $results = $db->loadRowList(); diff --git a/tests/unit/core/mock/dispatcher.php b/tests/unit/core/mock/dispatcher.php index ee54875127a06..a327c756765cf 100644 --- a/tests/unit/core/mock/dispatcher.php +++ b/tests/unit/core/mock/dispatcher.php @@ -126,6 +126,8 @@ public static function mockRegister($event, $handler, $return = null) self::$handlers[$event] = []; } - self::$handlers[$event][print_r($handler, true)] = $return; + $identifier = is_array($handler) ? md5(serialize($handler)) : spl_object_hash($handler); + + self::$handlers[$event][$identifier] = $return; } } diff --git a/tests/unit/suites/libraries/joomla/application/stubs/JApplicationDaemonInspector.php b/tests/unit/suites/libraries/joomla/application/stubs/JApplicationDaemonInspector.php index 3dff30580ba25..1aeee92129724 100644 --- a/tests/unit/suites/libraries/joomla/application/stubs/JApplicationDaemonInspector.php +++ b/tests/unit/suites/libraries/joomla/application/stubs/JApplicationDaemonInspector.php @@ -276,4 +276,17 @@ public function pcntlWait(&$status, $options = 0) { return self::$pcntlWait; } + + /** + * Method to run the application routines. Most likely you will want to instantiate a controller + * and execute it, or perform some sort of task directly. + * + * @return void + * + * @since 4.0 + */ + protected function doExecute() + { + return; + } }