Skip to content

Commit

Permalink
Fix PHPCS issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Babker committed Sep 18, 2016
1 parent 8766af4 commit 746171c
Show file tree
Hide file tree
Showing 15 changed files with 157 additions and 122 deletions.
8 changes: 4 additions & 4 deletions components/com_tags/views/tag/view.html.php
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion libraries/cms/application/cms.php
Expand Up @@ -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);
}
}
Expand Down
27 changes: 16 additions & 11 deletions libraries/cms/captcha/captcha.php
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand Down
114 changes: 61 additions & 53 deletions libraries/cms/plugin/plugin.php
Expand Up @@ -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;
});
);
}

/**
Expand All @@ -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]);
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/joomla/application/web.php
Expand Up @@ -971,7 +971,7 @@ public function setSession(SessionInterface $session)
$this->session = $session;

return $this;
}
}

/**
* Method to load the system URI strings for the application.
Expand Down
2 changes: 1 addition & 1 deletion libraries/joomla/database/interface.php
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions libraries/legacy/controller/legacy.php
Expand Up @@ -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);
Expand Down
13 changes: 8 additions & 5 deletions libraries/legacy/model/admin.php
Expand Up @@ -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
{
Expand Down
17 changes: 13 additions & 4 deletions libraries/legacy/view/category.php
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions libraries/src/Cms/Application/EventAware.php
Expand Up @@ -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;
}
Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions plugins/editors-xtd/readmore/readmore.php
Expand Up @@ -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);
Expand Down
21 changes: 10 additions & 11 deletions plugins/editors/codemirror/codemirror.php
Expand Up @@ -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'];

Expand All @@ -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'];
Expand Down

0 comments on commit 746171c

Please sign in to comment.