Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge branch 'cs/zendframework/zendframework#6967-zend-view-cs-fixes'…
Browse files Browse the repository at this point in the history
  • Loading branch information
Ocramius committed Dec 7, 2014
3 parents 67522f1 + 2ce8a53 + 08c9d8a commit 51c13e1
Show file tree
Hide file tree
Showing 14 changed files with 148 additions and 73 deletions.
8 changes: 5 additions & 3 deletions src/Helper/Escaper/AbstractHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ abstract class AbstractHelper extends Helper\AbstractHelper
* Invoke this helper: escape a value
*
* @param mixed $value
* @param int $recurse Expects one of the recursion constants; used to decide whether or not to recurse the given value when escaping
* @param int $recurse Expects one of the recursion constants;
* used to decide whether or not to recurse the given value when escaping
* @throws Exception\InvalidArgumentException
* @return mixed Given a scalar, a scalar value is returned. Given an object, with the $recurse flag not allowing object recursion, returns a string. Otherwise, returns an array.
* @return mixed Given a scalar, a scalar value is returned. Given an object, with the $recurse flag not
* allowing object recursion, returns a string. Otherwise, returns an array.
*/
public function __invoke($value, $recurse = self::RECURSE_NONE)
{
Expand Down Expand Up @@ -100,7 +102,7 @@ public function setEncoding($encoding)
if (null !== $this->escaper) {
throw new Exception\InvalidArgumentException(
'Character encoding settings cannot be changed once the Helper has been used or '
. ' if a Zend\Escaper\Escaper object (with preset encoding option) is set.'
. ' if a Zend\Escaper\Escaper object (with preset encoding option) is set.'
);
}

Expand Down
50 changes: 32 additions & 18 deletions src/Helper/FlashMessenger.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,18 @@ public function renderCurrent($namespace = PluginFlashMessenger::NAMESPACE_DEFAU
/**
* Render Messages
*
* @param array $messages
* @param array $classes
* @param string $namespace
* @param array $messages
* @param array $classes
* @param bool|null $autoEscape
* @return string
*/
protected function renderMessages($namespace = PluginFlashMessenger::NAMESPACE_DEFAULT, array $messages = array(), array $classes = array(), $autoEscape = null)
{
protected function renderMessages(
$namespace = PluginFlashMessenger::NAMESPACE_DEFAULT,
array $messages = array(),
array $classes = array(),
$autoEscape = null
) {
// Prepare classes for opening tag
if (empty($classes)) {
if (isset($this->classMessages[$namespace])) {
Expand All @@ -155,27 +161,35 @@ protected function renderMessages($namespace = PluginFlashMessenger::NAMESPACE_D
$messagesToPrint = array();
$translator = $this->getTranslator();
$translatorTextDomain = $this->getTranslatorTextDomain();
array_walk_recursive($messages, function ($item) use (&$messagesToPrint, $escapeHtml, $autoEscape, $translator, $translatorTextDomain) {
if ($translator !== null) {
$item = $translator->translate(
$item,
$translatorTextDomain
);
}

if ($autoEscape) {
$messagesToPrint[] = $escapeHtml($item);
return;
array_walk_recursive(
$messages,
function ($item) use (& $messagesToPrint, $escapeHtml, $autoEscape, $translator, $translatorTextDomain) {
if ($translator !== null) {
$item = $translator->translate(
$item,
$translatorTextDomain
);
}

if ($autoEscape) {
$messagesToPrint[] = $escapeHtml($item);
return;
}

$messagesToPrint[] = $item;
}
);

$messagesToPrint[] = $item;
});
if (empty($messagesToPrint)) {
return '';
}

// Generate markup
$markup = sprintf($this->getMessageOpenFormat(), ' class="' . implode(' ', $classes) . '"');
$markup .= implode(sprintf($this->getMessageSeparatorString(), ' class="' . implode(' ', $classes) . '"'), $messagesToPrint);
$markup .= implode(
sprintf($this->getMessageSeparatorString(), ' class="' . implode(' ', $classes) . '"'),
$messagesToPrint
);
$markup .= $this->getMessageCloseString();
return $markup;
}
Expand Down
11 changes: 9 additions & 2 deletions src/Helper/HeadLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,11 @@ public function itemToString(stdClass $item)
$link .= sprintf(' %s="%s"', $key, ($this->autoEscape) ? $this->escape($value) : $value);
}
} else {
$link .= sprintf(' %s="%s"', $itemKey, ($this->autoEscape) ? $this->escape($attributes[$itemKey]) : $attributes[$itemKey]);
$link .= sprintf(
' %s="%s"',
$itemKey,
($this->autoEscape) ? $this->escape($attributes[$itemKey]) : $attributes[$itemKey]
);
}
}
}
Expand All @@ -310,7 +314,10 @@ public function itemToString(stdClass $item)
return '';
}

if (isset($attributes['conditionalStylesheet']) && !empty($attributes['conditionalStylesheet']) && is_string($attributes['conditionalStylesheet'])) {
if (isset($attributes['conditionalStylesheet'])
&& !empty($attributes['conditionalStylesheet'])
&& is_string($attributes['conditionalStylesheet'])
) {
// inner wrap with comment end and start if !IE
if (str_replace(' ', '', $attributes['conditionalStylesheet']) === '!IE') {
$link = '<!-->' . $link . '<!--';
Expand Down
14 changes: 11 additions & 3 deletions src/Helper/HeadMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,13 @@ public function __construct()
* @param string $placement
* @return HeadMeta
*/
public function __invoke($content = null, $keyValue = null, $keyType = 'name', $modifiers = array(), $placement = Placeholder\Container\AbstractContainer::APPEND)
{
public function __invoke(
$content = null,
$keyValue = null,
$keyType = 'name',
$modifiers = array(),
$placement = Placeholder\Container\AbstractContainer::APPEND
) {
if ((null !== $content) && (null !== $keyValue)) {
$item = $this->createData($keyType, $keyValue, $content, $modifiers);
$action = strtolower($placement);
Expand Down Expand Up @@ -261,7 +266,10 @@ public function itemToString(stdClass $item)
$modifiersString
);

if (isset($item->modifiers['conditional']) && !empty($item->modifiers['conditional']) && is_string($item->modifiers['conditional'])) {
if (isset($item->modifiers['conditional'])
&& !empty($item->modifiers['conditional'])
&& is_string($item->modifiers['conditional'])
) {
// inner wrap with comment end and start if !IE
if (str_replace(' ', '', $item->modifiers['conditional']) === '!IE') {
$meta = '<!-->' . $meta . '<!--';
Expand Down
46 changes: 34 additions & 12 deletions src/Helper/HeadScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,13 @@ public function __construct()
* @param string $type Script type and/or array of script attributes
* @return HeadScript
*/
public function __invoke($mode = self::FILE, $spec = null, $placement = 'APPEND', array $attrs = array(), $type = 'text/javascript')
{
public function __invoke(
$mode = self::FILE,
$spec = null,
$placement = 'APPEND',
array $attrs = array(),
$type = 'text/javascript'
) {
if ((null !== $spec) && is_string($spec)) {
$action = ucfirst(strtolower($mode));
$placement = strtolower($placement);
Expand Down Expand Up @@ -260,8 +265,11 @@ public function toString($indent = null)
* @throws Exception\RuntimeException
* @return void
*/
public function captureStart($captureType = Placeholder\Container\AbstractContainer::APPEND, $type = 'text/javascript', $attrs = array())
{
public function captureStart(
$captureType = Placeholder\Container\AbstractContainer::APPEND,
$type = 'text/javascript',
$attrs = array()
) {
if ($this->captureLock) {
throw new Exception\RuntimeException('Cannot nest headScript captures');
}
Expand Down Expand Up @@ -328,7 +336,10 @@ public function createData($type, array $attributes, $content = null)
protected function isDuplicate($file)
{
foreach ($this->getContainer() as $item) {
if (($item->source === null) && array_key_exists('src', $item->attributes) && ($file == $item->attributes['src'])) {
if (($item->source === null)
&& array_key_exists('src', $item->attributes)
&& ($file == $item->attributes['src'])
) {
return true;
}
}
Expand All @@ -344,7 +355,11 @@ protected function isDuplicate($file)
*/
protected function isValid($value)
{
if ((!$value instanceof stdClass) || !isset($value->type) || (!isset($value->source) && !isset($value->attributes))) {
if ((!$value instanceof stdClass)
|| !isset($value->type)
|| (!isset($value->source)
&& !isset($value->attributes))
) {
return false;
}

Expand Down Expand Up @@ -376,10 +391,11 @@ public function itemToString($item, $indent, $escapeStart, $escapeEnd)
}
}

$addScriptEscape = !(isset($item->attributes['noescape']) && filter_var($item->attributes['noescape'], FILTER_VALIDATE_BOOLEAN));
$addScriptEscape = !(isset($item->attributes['noescape'])
&& filter_var($item->attributes['noescape'], FILTER_VALIDATE_BOOLEAN));

$type = ($this->autoEscape) ? $this->escape($item->type) : $item->type;
$html = '<script type="' . $type . '"' . $attrString . '>';
$html = '<script type="' . $type . '"' . $attrString . '>';
if (!empty($item->source)) {
$html .= PHP_EOL;

Expand All @@ -397,7 +413,10 @@ public function itemToString($item, $indent, $escapeStart, $escapeEnd)
}
$html .= '</script>';

if (isset($item->attributes['conditional']) && !empty($item->attributes['conditional']) && is_string($item->attributes['conditional'])) {
if (isset($item->attributes['conditional'])
&& !empty($item->attributes['conditional'])
&& is_string($item->attributes['conditional'])
) {
// inner wrap with comment end and start if !IE
if (str_replace(' ', '', $item->attributes['conditional']) === '!IE') {
$html = '<!-->' . $html . '<!--';
Expand All @@ -421,7 +440,8 @@ public function append($value)
{
if (!$this->isValid($value)) {
throw new Exception\InvalidArgumentException(
'Invalid argument passed to append(); please use one of the helper methods, appendScript() or appendFile()'
'Invalid argument passed to append(); '
. 'please use one of the helper methods, appendScript() or appendFile()'
);
}

Expand All @@ -439,7 +459,8 @@ public function prepend($value)
{
if (!$this->isValid($value)) {
throw new Exception\InvalidArgumentException(
'Invalid argument passed to prepend(); please use one of the helper methods, prependScript() or prependFile()'
'Invalid argument passed to prepend(); '
. 'please use one of the helper methods, prependScript() or prependFile()'
);
}

Expand Down Expand Up @@ -476,7 +497,8 @@ public function offsetSet($index, $value)
{
if (!$this->isValid($value)) {
throw new Exception\InvalidArgumentException(
'Invalid argument passed to offsetSet(); please use one of the helper methods, offsetSetScript() or offsetSetFile()'
'Invalid argument passed to offsetSet(); '
. 'please use one of the helper methods, offsetSetScript() or offsetSetFile()'
);
}

Expand Down
14 changes: 11 additions & 3 deletions src/Helper/HtmlObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,18 @@ class HtmlObject extends AbstractHtmlElement
* @throws InvalidArgumentException
* @return string
*/
public function __invoke($data = null, $type = null, array $attribs = array(), array $params = array(), $content = null)
{
public function __invoke(
$data = null,
$type = null,
array $attribs = array(),
array $params = array(),
$content = null
) {
if ($data == null || $type == null) {
throw new InvalidArgumentException('HTMLObject: missing argument. $data and $type are required in htmlObject($data, $type, array $attribs = array(), array $params = array(), $content = null)');
throw new InvalidArgumentException(
'HTMLObject: missing argument. $data and $type are required in '
. 'htmlObject($data, $type, array $attribs = array(), array $params = array(), $content = null)'
);
}

// Merge data and type
Expand Down
9 changes: 7 additions & 2 deletions src/Helper/InlineScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ class InlineScript extends HeadScript
* @param string $type Script type and/or array of script attributes
* @return InlineScript
*/
public function __invoke($mode = self::FILE, $spec = null, $placement = 'APPEND', array $attrs = array(), $type = 'text/javascript')
{
public function __invoke(
$mode = self::FILE,
$spec = null,
$placement = 'APPEND',
array $attrs = array(),
$type = 'text/javascript'
) {
return parent::__invoke($mode, $spec, $placement, $attrs, $type);
}
}
9 changes: 5 additions & 4 deletions src/Helper/Navigation/AbstractHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ public function __call($method, array $arguments = array())
{
return call_user_func_array(
array($this->getContainer(), $method),
$arguments);
$arguments
);
}

/**
Expand Down Expand Up @@ -283,8 +284,8 @@ protected function parseContainer(&$container = null)

if (!$container instanceof Navigation\AbstractContainer) {
throw new Exception\InvalidArgumentException(
'Container must be a string alias or an instance of ' .
'Zend\Navigation\AbstractContainer'
'Container must be a string alias or an instance of '
. 'Zend\Navigation\AbstractContainer'
);
}
}
Expand Down Expand Up @@ -706,7 +707,7 @@ public function setRole($role = null)
} else {
throw new Exception\InvalidArgumentException(sprintf(
'$role must be a string, null, or an instance of '
. 'Zend\Permissions\Role\RoleInterface; %s given',
. 'Zend\Permissions\Role\RoleInterface; %s given',
(is_object($role) ? get_class($role) : gettype($role))
));
}
Expand Down
12 changes: 5 additions & 7 deletions src/Helper/Navigation/Links.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ public function __call($method, array $arguments = array())
$result = preg_match('/find(Rel|Rev)(.+)/', $method, $match);
ErrorHandler::stop();
if ($result) {
return $this->findRelation($arguments[0],
strtolower($match[1]),
strtolower($match[2]));
return $this->findRelation($arguments[0], strtolower($match[1]), strtolower($match[2]));
}

return parent::__call($method, $arguments);
Expand Down Expand Up @@ -409,8 +407,7 @@ public function searchRelNext(AbstractPage $page)
{
$found = null;
$break = false;
$iterator = new RecursiveIteratorIterator($this->findRoot($page),
RecursiveIteratorIterator::SELF_FIRST);
$iterator = new RecursiveIteratorIterator($this->findRoot($page), RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $intermediate) {
if ($intermediate === $page) {
// current page; break at next accepted page
Expand Down Expand Up @@ -443,8 +440,9 @@ public function searchRelPrev(AbstractPage $page)
$found = null;
$prev = null;
$iterator = new RecursiveIteratorIterator(
$this->findRoot($page),
RecursiveIteratorIterator::SELF_FIRST);
$this->findRoot($page),
RecursiveIteratorIterator::SELF_FIRST
);
foreach ($iterator as $intermediate) {
if (!$this->accept($intermediate)) {
continue;
Expand Down
Loading

0 comments on commit 51c13e1

Please # to comment.