diff --git a/lib/addon/sfPager.class.php b/lib/addon/sfPager.class.php index 594b1417a..f78ba4a64 100644 --- a/lib/addon/sfPager.class.php +++ b/lib/addon/sfPager.class.php @@ -529,7 +529,7 @@ protected function resetIterator() * * @see Iterator */ - public function current() + public function current(): mixed { if (!$this->isIteratorInitialized()) { @@ -544,7 +544,7 @@ public function current() * * @see Iterator */ - public function key() + public function key(): mixed { if (!$this->isIteratorInitialized()) { @@ -559,7 +559,7 @@ public function key() * * @see Iterator */ - public function next() + public function next(): void { if (!$this->isIteratorInitialized()) { @@ -568,7 +568,7 @@ public function next() --$this->resultsCounter; - return next($this->results); + next($this->results); } /** @@ -576,7 +576,7 @@ public function next() * * @see Iterator */ - public function rewind() + public function rewind(): void { if (!$this->isIteratorInitialized()) { @@ -585,7 +585,7 @@ public function rewind() $this->resultsCounter = count($this->results); - return reset($this->results); + reset($this->results); } /** @@ -593,7 +593,7 @@ public function rewind() * * @see Iterator */ - public function valid() + public function valid(): bool { if (!$this->isIteratorInitialized()) { @@ -608,7 +608,7 @@ public function valid() * * @see Countable */ - public function count() + public function count(): int { return $this->getNbResults(); } diff --git a/lib/escaper/sfOutputEscaperArrayDecorator.class.php b/lib/escaper/sfOutputEscaperArrayDecorator.class.php index 0e6b0b0ae..e4984f938 100644 --- a/lib/escaper/sfOutputEscaperArrayDecorator.class.php +++ b/lib/escaper/sfOutputEscaperArrayDecorator.class.php @@ -42,7 +42,7 @@ public function __construct($escapingMethod, $value) /** * Reset the array to the beginning (as required for the Iterator interface). */ - public function rewind() + public function rewind(): void { reset($this->value); @@ -54,7 +54,7 @@ public function rewind() * * @return string The key */ - public function key() + public function key(): mixed { return key($this->value); } @@ -67,7 +67,7 @@ public function key() * * @return mixed The escaped value */ - public function current() + public function current(): mixed { return sfOutputEscaper::escape($this->escapingMethod, current($this->value)); } @@ -75,7 +75,7 @@ public function current() /** * Moves to the next element (as required by the Iterator interface). */ - public function next() + public function next(): void { next($this->value); @@ -91,7 +91,7 @@ public function next() * * @return bool The validity of the current element; true if it is valid */ - public function valid() + public function valid(): bool { return $this->count > 0; } @@ -103,7 +103,7 @@ public function valid() * * @return bool true if the offset isset; false otherwise */ - public function offsetExists($offset) + public function offsetExists(mixed $offset): bool { return isset($this->value[$offset]); } @@ -115,7 +115,7 @@ public function offsetExists($offset) * * @return mixed The escaped value */ - public function offsetGet($offset) + public function offsetGet(mixed $offset): mixed { return sfOutputEscaper::escape($this->escapingMethod, $this->value[$offset]); } @@ -132,7 +132,7 @@ public function offsetGet($offset) * * @throws sfException */ - public function offsetSet($offset, $value) + public function offsetSet(mixed $offset, mixed $value): void { throw new sfException('Cannot set values.'); } @@ -148,7 +148,7 @@ public function offsetSet($offset, $value) * * @throws sfException */ - public function offsetUnset($offset) + public function offsetUnset(mixed $offset): void { throw new sfException('Cannot unset values.'); } @@ -158,7 +158,7 @@ public function offsetUnset($offset) * * @return int The size of the array */ - public function count() + public function count(): int { return count($this->value); } diff --git a/lib/escaper/sfOutputEscaperIteratorDecorator.class.php b/lib/escaper/sfOutputEscaperIteratorDecorator.class.php index 7d9eca063..248f1a367 100644 --- a/lib/escaper/sfOutputEscaperIteratorDecorator.class.php +++ b/lib/escaper/sfOutputEscaperIteratorDecorator.class.php @@ -56,9 +56,9 @@ public function __construct($escapingMethod, Traversable $value) * * @return void */ - public function rewind() + public function rewind(): void { - return $this->iterator->rewind(); + $this->iterator->rewind(); } /** @@ -66,7 +66,7 @@ public function rewind() * * @return mixed The escaped value */ - public function current() + public function current(): mixed { return sfOutputEscaper::escape($this->escapingMethod, $this->iterator->current()); } @@ -76,7 +76,7 @@ public function current() * * @return string Iterator key */ - public function key() + public function key(): mixed { return $this->iterator->key(); } @@ -86,9 +86,9 @@ public function key() * * @return void */ - public function next() + public function next(): void { - return $this->iterator->next(); + $this->iterator->next(); } /** @@ -97,7 +97,7 @@ public function next() * * @return bool true if the current element is valid; false otherwise */ - public function valid() + public function valid(): bool { return $this->iterator->valid(); } @@ -109,7 +109,7 @@ public function valid() * * @return bool true if the offset isset; false otherwise */ - public function offsetExists($offset) + public function offsetExists(mixed $offset): bool { return isset($this->value[$offset]); } @@ -121,7 +121,7 @@ public function offsetExists($offset) * * @return mixed The escaped value */ - public function offsetGet($offset) + public function offsetGet(mixed $offset): mixed { return sfOutputEscaper::escape($this->escapingMethod, $this->value[$offset]); } @@ -138,7 +138,7 @@ public function offsetGet($offset) * * @throws sfException */ - public function offsetSet($offset, $value) + public function offsetSet(mixed $offset, mixed $value): void { throw new sfException('Cannot set values.'); } @@ -154,7 +154,7 @@ public function offsetSet($offset, $value) * * @throws sfException */ - public function offsetUnset($offset) + public function offsetUnset(mixed $offset): void { throw new sfException('Cannot unset values.'); } diff --git a/lib/escaper/sfOutputEscaperObjectDecorator.class.php b/lib/escaper/sfOutputEscaperObjectDecorator.class.php index 89e70edcd..be5ae6b00 100644 --- a/lib/escaper/sfOutputEscaperObjectDecorator.class.php +++ b/lib/escaper/sfOutputEscaperObjectDecorator.class.php @@ -115,7 +115,7 @@ public function __isset($key) * * @return int The size of the object */ - public function count() + public function count(): int { return count($this->value); } diff --git a/lib/event/sfEvent.class.php b/lib/event/sfEvent.class.php index 0ffd44281..a1716d49c 100644 --- a/lib/event/sfEvent.class.php +++ b/lib/event/sfEvent.class.php @@ -117,9 +117,9 @@ public function getParameters() * * @return Boolean true if the parameter exists, false otherwise */ - public function offsetExists($name) + public function offsetExists(mixed $offset): bool { - return array_key_exists($name, $this->parameters); + return array_key_exists($offset, $this->parameters); } /** @@ -129,7 +129,7 @@ public function offsetExists($name) * * @return mixed The parameter value */ - public function offsetGet($name) + public function offsetGet(mixed $name): mixed { if (!array_key_exists($name, $this->parameters)) { @@ -145,7 +145,7 @@ public function offsetGet($name) * @param string $name The parameter name * @param mixed $value The parameter value */ - public function offsetSet($name, $value) + public function offsetSet(mixed $name, mixed $value): void { $this->parameters[$name] = $value; } @@ -155,7 +155,7 @@ public function offsetSet($name, $value) * * @param string $name The parameter name */ - public function offsetUnset($name) + public function offsetUnset(mixed $name): void { unset($this->parameters[$name]); } diff --git a/lib/form/sfForm.class.php b/lib/form/sfForm.class.php index db46c4d82..ce5b23425 100644 --- a/lib/form/sfForm.class.php +++ b/lib/form/sfForm.class.php @@ -1064,9 +1064,9 @@ public function resetFormFields() * * @return Boolean true if the widget exists, false otherwise */ - public function offsetExists($name) + public function offsetExists(mixed $offset): bool { - return isset($this->widgetSchema[$name]); + return isset($this->widgetSchema[$offset]); } /** @@ -1076,7 +1076,7 @@ public function offsetExists($name) * * @return sfFormField|sfFormFieldSchema A form field instance */ - public function offsetGet($name) + public function offsetGet(mixed $name): mixed { if (!isset($this->formFields[$name])) { @@ -1114,7 +1114,7 @@ public function offsetGet($name) * * @throws LogicException */ - public function offsetSet($offset, $value) + public function offsetSet(mixed $offset, mixed $value): void { throw new LogicException('Cannot update form fields.'); } @@ -1126,7 +1126,7 @@ public function offsetSet($offset, $value) * * @param string $offset The field name */ - public function offsetUnset($offset) + public function offsetUnset(mixed $offset): void { unset( $this->widgetSchema[$offset], @@ -1227,7 +1227,7 @@ public function getErrors() /** * Resets the field names array to the beginning (implements the Iterator interface). */ - public function rewind() + public function rewind(): void { $this->fieldNames = $this->widgetSchema->getPositions(); @@ -1240,7 +1240,7 @@ public function rewind() * * @return string The key */ - public function key() + public function key(): mixed { return current($this->fieldNames); } @@ -1250,7 +1250,7 @@ public function key() * * @return mixed The escaped value */ - public function current() + public function current(): mixed { return $this[current($this->fieldNames)]; } @@ -1258,7 +1258,7 @@ public function current() /** * Moves to the next form field (implements the Iterator interface). */ - public function next() + public function next(): void { next($this->fieldNames); --$this->count; @@ -1269,7 +1269,7 @@ public function next() * * @return boolean The validity of the current element; true if it is valid */ - public function valid() + public function valid(): bool { return $this->count > 0; } @@ -1279,7 +1279,7 @@ public function valid() * * @return integer The number of embedded form fields */ - public function count() + public function count(): int { return count($this->getFormFieldSchema()); } diff --git a/lib/form/sfFormFieldSchema.class.php b/lib/form/sfFormFieldSchema.class.php index 520058dfe..c1bd4fc32 100644 --- a/lib/form/sfFormFieldSchema.class.php +++ b/lib/form/sfFormFieldSchema.class.php @@ -91,9 +91,9 @@ public function getHiddenFields($recursive = true) * * @return Boolean true if the widget exists, false otherwise */ - public function offsetExists($name) + public function offsetExists(mixed $offset): bool { - return isset($this->widget[$name]); + return isset($this->widget[$offset]); } /** @@ -103,7 +103,7 @@ public function offsetExists($name) * * @return sfFormField A form field instance */ - public function offsetGet($name) + public function offsetGet(mixed $name): mixed { if (!isset($this->fields[$name])) { @@ -144,7 +144,7 @@ public function offsetGet($name) * * @throws LogicException */ - public function offsetSet($offset, $value) + public function offsetSet(mixed $offset, mixed $value): void { throw new LogicException('Cannot update form fields (read-only).'); } @@ -156,7 +156,7 @@ public function offsetSet($offset, $value) * * @throws LogicException */ - public function offsetUnset($offset) + public function offsetUnset(mixed $offset): void { throw new LogicException('Cannot remove form fields (read-only).'); } @@ -164,7 +164,7 @@ public function offsetUnset($offset) /** * Resets the field names array to the beginning (implements the Iterator interface). */ - public function rewind() + public function rewind(): void { reset($this->fieldNames); $this->count = count($this->fieldNames); @@ -175,7 +175,7 @@ public function rewind() * * @return string The key */ - public function key() + public function key(): mixed { return current($this->fieldNames); } @@ -185,7 +185,7 @@ public function key() * * @return mixed The escaped value */ - public function current() + public function current(): mixed { return $this[current($this->fieldNames)]; } @@ -193,7 +193,7 @@ public function current() /** * Moves to the next form field (implements the Iterator interface). */ - public function next() + public function next(): void { next($this->fieldNames); --$this->count; @@ -204,7 +204,7 @@ public function next() * * @return boolean The validity of the current element; true if it is valid */ - public function valid() + public function valid(): bool { return $this->count > 0; } @@ -214,7 +214,7 @@ public function valid() * * @return integer The number of embedded form fields */ - public function count() + public function count(): int { return count($this->fieldNames); } diff --git a/lib/helper/DateHelper.php b/lib/helper/DateHelper.php index 564aae975..51265f48e 100644 --- a/lib/helper/DateHelper.php +++ b/lib/helper/DateHelper.php @@ -17,7 +17,7 @@ * @version SVN: $Id$ */ -function format_daterange($start_date, $end_date, $format = 'd', $full_text, $start_text, $end_text, $culture = null, $charset = null) +function format_daterange($start_date, $end_date, $format = 'd', $full_text = '', $start_text = '', $end_text = '', $culture = null, $charset = null) { if ($start_date != '' && $end_date != '') { diff --git a/lib/i18n/sfDateFormat.class.php b/lib/i18n/sfDateFormat.class.php index 80a5a571f..90b2aded3 100644 --- a/lib/i18n/sfDateFormat.class.php +++ b/lib/i18n/sfDateFormat.class.php @@ -239,9 +239,10 @@ public function format($time, $pattern = 'F', $inputPattern = null, $charset = ' } else { - $function = ucfirst($this->getFunctionName($pattern)); + $function = $this->getFunctionName($pattern); if ($function != null) { + $function = ucfirst($function); $fName = 'get'.$function; if (in_array($fName, $this->methods)) { diff --git a/lib/log/sfFileLogger.class.php b/lib/log/sfFileLogger.class.php index dfb610a8e..edfd51aa3 100644 --- a/lib/log/sfFileLogger.class.php +++ b/lib/log/sfFileLogger.class.php @@ -100,7 +100,7 @@ protected function doLog($message, $priority) fwrite($this->fp, strtr($this->format, array( '%type%' => $this->type, '%message%' => $message, - '%time%' => strftime($this->timeFormat), + '%time%' => date($this->timeFormat, time()), '%priority%' => $this->getPriority($priority), '%EOL%' => PHP_EOL, ))); diff --git a/lib/plugins/sfDoctrinePlugin/lib/generator/sfDoctrineColumn.class.php b/lib/plugins/sfDoctrinePlugin/lib/generator/sfDoctrineColumn.class.php index 6611f26a3..3587ba93a 100644 --- a/lib/plugins/sfDoctrinePlugin/lib/generator/sfDoctrineColumn.class.php +++ b/lib/plugins/sfDoctrinePlugin/lib/generator/sfDoctrineColumn.class.php @@ -349,22 +349,22 @@ public function getTable() return $this->table; } - public function offsetExists($offset) + public function offsetExists(mixed $offset): bool { return isset($this->definition[$offset]); } - public function offsetSet($offset, $value) + public function offsetSet(mixed $offset, mixed $value): void { $this->definition[$offset] = $value; } - public function offsetGet($offset) + public function offsetGet(mixed $offset): mixed { return $this->definition[$offset]; } - public function offsetUnset($offset) + public function offsetUnset(mixed $offset): void { unset($this->definition[$offset]); } diff --git a/lib/request/sfRequest.class.php b/lib/request/sfRequest.class.php index b7249728b..9b5945ee8 100644 --- a/lib/request/sfRequest.class.php +++ b/lib/request/sfRequest.class.php @@ -173,9 +173,9 @@ public function setMethod($method) * * @return bool true if the request parameter exists, false otherwise */ - public function offsetExists($name) + public function offsetExists(mixed $offset): bool { - return $this->hasParameter($name); + return $this->hasParameter($offset); } /** @@ -185,9 +185,9 @@ public function offsetExists($name) * * @return mixed The request parameter if exists, null otherwise */ - public function offsetGet($name) + public function offsetGet(mixed $offset): mixed { - return $this->getParameter($name, false); + return $this->getParameter($offset, false); } /** @@ -196,7 +196,7 @@ public function offsetGet($name) * @param string $offset The parameter name * @param string $value The parameter value */ - public function offsetSet($offset, $value) + public function offsetSet(mixed $offset, mixed $value): void { $this->setParameter($offset, $value); } @@ -206,7 +206,7 @@ public function offsetSet($offset, $value) * * @param string $offset The parameter name */ - public function offsetUnset($offset) + public function offsetUnset(mixed $offset): void { $this->getParameterHolder()->remove($offset); } diff --git a/lib/response/sfResponse.class.php b/lib/response/sfResponse.class.php index 0dac345cb..1998c3211 100644 --- a/lib/response/sfResponse.class.php +++ b/lib/response/sfResponse.class.php @@ -154,11 +154,15 @@ public function __call($method, $arguments) * * @return array Objects instance */ - public function serialize() + public function serialize(): string { - return serialize($this->content); + return serialize($this->__serialize()); } + public function __serialize(): array + { + return $this->content; + } /** * Unserializes a sfResponse instance. * @@ -167,8 +171,13 @@ public function serialize() * @param string $serialized A serialized sfResponse instance * */ - public function unserialize($serialized) + public function unserialize(string $serialized) + { + $this->__unserialize(unserialize($serialized)); + } + + public function __unserialize(array $unserialized) { - $this->content = unserialize($serialized); + $this->content = $unserialized; } } diff --git a/lib/response/sfWebResponse.class.php b/lib/response/sfWebResponse.class.php index 4a9a6585a..f8f68d839 100644 --- a/lib/response/sfWebResponse.class.php +++ b/lib/response/sfWebResponse.class.php @@ -874,18 +874,29 @@ public function merge(sfWebResponse $response) /** * @see sfResponse */ - public function serialize() + public function __serialize(): array { - return serialize(array($this->content, $this->statusCode, $this->statusText, $this->options, $this->headerOnly, $this->headers, $this->metas, $this->httpMetas, $this->stylesheets, $this->javascripts, $this->slots)); + return array($this->content, $this->statusCode, $this->statusText, $this->options, $this->headerOnly, $this->headers, $this->metas, $this->httpMetas, $this->stylesheets, $this->javascripts, $this->slots); } + public function serialize(): string + { + return serialize($this->__serialize()); + } + + /** * @see sfResponse * @inheritdoc */ - public function unserialize($serialized) + public function unserialize(string $serialized) + { + $this->__unserialize(unserialize($serialized)); + } + + public function __unserialize(array $unserialized) { - list($this->content, $this->statusCode, $this->statusText, $this->options, $this->headerOnly, $this->headers, $this->metas, $this->httpMetas, $this->stylesheets, $this->javascripts, $this->slots) = unserialize($serialized); + list($this->content, $this->statusCode, $this->statusText, $this->options, $this->headerOnly, $this->headers, $this->metas, $this->httpMetas, $this->stylesheets, $this->javascripts, $this->slots) = $unserialized; } /** diff --git a/lib/routing/sfRoute.class.php b/lib/routing/sfRoute.class.php index 6887e4e24..79d5f53cd 100644 --- a/lib/routing/sfRoute.class.php +++ b/lib/routing/sfRoute.class.php @@ -285,7 +285,7 @@ protected function generateWithTokens($parameters) switch ($token[0]) { case 'variable': - if (!$optional || !isset($this->defaults[$token[3]]) || $parameters[$token[3]] != $this->defaults[$token[3]]) + if (!$optional || !isset($this->defaults[$token[3]]) || (isset($parameters[$token[3]]) && isset($this->defaults[$token[3]]) && ($parameters[$token[3]] != $this->defaults[$token[3]]))) { $url[] = urlencode($parameters[$token[3]]); $optional = false; @@ -791,7 +791,7 @@ protected function fixDefaults() } else { - $this->defaults[$key] = urldecode($value); + $this->defaults[$key] = ($value) ? urldecode($value) : ''; } } } @@ -845,17 +845,27 @@ protected function fixSuffix() } } - public function serialize() + public function serialize(): string + { + return serialize($this->__serialize()); + } + + public function __serialize(): array { // always serialize compiled routes $this->compile(); // sfPatternRouting will always re-set defaultParameters, so no need to serialize them - return serialize(array($this->tokens, $this->defaultOptions, $this->options, $this->pattern, $this->staticPrefix, $this->regex, $this->variables, $this->defaults, $this->requirements, $this->suffix, $this->customToken)); + return array($this->tokens, $this->defaultOptions, $this->options, $this->pattern, $this->staticPrefix, $this->regex, $this->variables, $this->defaults, $this->requirements, $this->suffix, $this->customToken); + } + + public function unserialize(string $serialized) + { + $this->__unserialize(unserialize($serialized)); } - public function unserialize($data) + public function __unserialize(array $unserialized) { - list($this->tokens, $this->defaultOptions, $this->options, $this->pattern, $this->staticPrefix, $this->regex, $this->variables, $this->defaults, $this->requirements, $this->suffix, $this->customToken) = unserialize($data); + list($this->tokens, $this->defaultOptions, $this->options, $this->pattern, $this->staticPrefix, $this->regex, $this->variables, $this->defaults, $this->requirements, $this->suffix, $this->customToken) = $unserialized; $this->compiled = true; } } diff --git a/lib/routing/sfRouteCollection.class.php b/lib/routing/sfRouteCollection.class.php index ee0117185..dd5e08be2 100644 --- a/lib/routing/sfRouteCollection.class.php +++ b/lib/routing/sfRouteCollection.class.php @@ -61,7 +61,7 @@ public function getOptions() /** * Reset the error array to the beginning (implements the Iterator interface). */ - public function rewind() + public function rewind(): void { reset($this->routes); @@ -73,7 +73,7 @@ public function rewind() * * @return string The key */ - public function key() + public function key(): mixed { return key($this->routes); } @@ -83,7 +83,7 @@ public function key() * * @return mixed The escaped value */ - public function current() + public function current(): mixed { return current($this->routes); } @@ -91,7 +91,7 @@ public function current() /** * Moves to the next route (implements the Iterator interface). */ - public function next() + public function next(): void { next($this->routes); @@ -103,7 +103,7 @@ public function next() * * @return boolean The validity of the current route; true if it is valid */ - public function valid() + public function valid(): bool { return $this->count > 0; } diff --git a/lib/user/sfUser.class.php b/lib/user/sfUser.class.php index 2b65fa065..6b52c2f22 100644 --- a/lib/user/sfUser.class.php +++ b/lib/user/sfUser.class.php @@ -227,9 +227,9 @@ public function getCulture() * * @return Boolean true if the user attribute exists, false otherwise */ - public function offsetExists($name) + public function offsetExists(mixed $offset): bool { - return $this->hasAttribute($name); + return $this->hasAttribute($offset); } /** @@ -239,7 +239,7 @@ public function offsetExists($name) * * @return mixed The user attribute if exists, null otherwise */ - public function offsetGet($name) + public function offsetGet(mixed $name): mixed { return $this->getAttribute($name, false); } @@ -250,7 +250,7 @@ public function offsetGet($name) * @param string $offset The parameter name * @param string $value The parameter value */ - public function offsetSet($offset, $value) + public function offsetSet(mixed $offset, mixed $value): void { $this->setAttribute($offset, $value); } @@ -260,7 +260,7 @@ public function offsetSet($offset, $value) * * @param string $offset The parameter name */ - public function offsetUnset($offset) + public function offsetUnset(mixed $offset): void { $this->getAttributeHolder()->remove($offset); } diff --git a/lib/util/sfBrowserBase.class.php b/lib/util/sfBrowserBase.class.php index 21d3de7da..f6a937727 100755 --- a/lib/util/sfBrowserBase.class.php +++ b/lib/util/sfBrowserBase.class.php @@ -908,7 +908,7 @@ public function doClickElement(DOMElement $item, $arguments = array(), $options } else { - $queryString = http_build_query($arguments, null, '&'); + $queryString = ($arguments) ? http_build_query($arguments, null, '&') : ""; $sep = false === strpos($url, '?') ? '?' : '&'; return array($url.($queryString ? $sep.$queryString : ''), 'get', array()); diff --git a/lib/util/sfContext.class.php b/lib/util/sfContext.class.php index 439cbf5a6..e64d38bb3 100644 --- a/lib/util/sfContext.class.php +++ b/lib/util/sfContext.class.php @@ -508,9 +508,9 @@ public function getConfigCache() * * @return Boolean true if the context object exists, false otherwise */ - public function offsetExists($name) + public function offsetExists(mixed $offset): bool { - return $this->has($name); + return $this->has($offset); } /** @@ -520,9 +520,9 @@ public function offsetExists($name) * * @return mixed The context object if exists, null otherwise */ - public function offsetGet($name) + public function offsetGet(mixed $offset): mixed { - return $this->get($name); + return $this->get($offset); } /** @@ -531,7 +531,7 @@ public function offsetGet($name) * @param string $offset Service name * @param mixed $value Service */ - public function offsetSet($offset, $value) + public function offsetSet(mixed $offset, mixed $value): void { $this->set($offset, $value); } @@ -541,7 +541,7 @@ public function offsetSet($offset, $value) * * @param string $offset The parameter name */ - public function offsetUnset($offset) + public function offsetUnset(mixed $offset): void { unset($this->factories[$offset]); } @@ -581,7 +581,7 @@ public function set($name, $object) * * @return bool true if the object is not null, false otherwise */ - public function has($name) + public function has($name): bool { return isset($this->factories[$name]); } diff --git a/lib/util/sfDomCssSelector.class.php b/lib/util/sfDomCssSelector.class.php index 8a6d2362f..e0d6d9958 100644 --- a/lib/util/sfDomCssSelector.class.php +++ b/lib/util/sfDomCssSelector.class.php @@ -563,7 +563,7 @@ protected function nth($cur, $result = 1, $dir = 'nextSibling') /** * Reset the array to the beginning (as required for the Iterator interface). */ - public function rewind() + public function rewind(): void { reset($this->nodes); @@ -575,7 +575,7 @@ public function rewind() * * @return string The key */ - public function key() + public function key(): mixed { return key($this->nodes); } @@ -585,7 +585,7 @@ public function key() * * @return mixed The escaped value */ - public function current() + public function current(): mixed { return current($this->nodes); } @@ -593,7 +593,7 @@ public function current() /** * Moves to the next element (as required by the Iterator interface). */ - public function next() + public function next(): void { next($this->nodes); @@ -609,7 +609,7 @@ public function next() * * @return bool The validity of the current element; true if it is valid */ - public function valid() + public function valid(): bool { return $this->count > 0; } @@ -619,7 +619,7 @@ public function valid() * * @param integer The number of matching nodes */ - public function count() + public function count(): int { return count($this->nodes); } diff --git a/lib/util/sfInflector.class.php b/lib/util/sfInflector.class.php index 378d5e79e..aedc3b31a 100644 --- a/lib/util/sfInflector.class.php +++ b/lib/util/sfInflector.class.php @@ -27,7 +27,9 @@ class sfInflector */ public static function camelize($lower_case_and_underscored_word) { - + if (!$lower_case_and_underscored_word) { + return $lower_case_and_underscored_word; + } return strtr(ucwords(strtr($lower_case_and_underscored_word, array('/' => ':: ', '_' => ' ', '-' => ' '))), array(' ' => '')); } @@ -41,6 +43,9 @@ public static function camelize($lower_case_and_underscored_word) public static function underscore($camel_cased_word) { $tmp = $camel_cased_word; + if (!$tmp) { + return ''; + } $tmp = str_replace('::', '/', $tmp); $tmp = sfToolkit::pregtr($tmp, array('/([A-Z]+)([A-Z][a-z])/' => '\\1_\\2', '/([a-z\d])([A-Z])/' => '\\1_\\2')); diff --git a/lib/util/sfNamespacedParameterHolder.class.php b/lib/util/sfNamespacedParameterHolder.class.php index 18eb76c67..f205e2263 100644 --- a/lib/util/sfNamespacedParameterHolder.class.php +++ b/lib/util/sfNamespacedParameterHolder.class.php @@ -368,9 +368,14 @@ public function addByRef(& $parameters, $ns = null) * * @return array Objects instance */ - public function serialize() + public function serialize(): string + { + return serialize($this->__serialize()); + } + + public function __serialize(): array { - return serialize(array($this->default_namespace, $this->parameters)); + return array($this->default_namespace, $this->parameters); } /** @@ -378,9 +383,14 @@ public function serialize() * * @param string $serialized A serialized sfNamespacedParameterHolder instance */ - public function unserialize($serialized) + public function unserialize(string $serialized) + { + $this->__unserialize(unserialize($serialized)); + } + + public function __unserialize(array $unserialized) { - $data = unserialize($serialized); + $data = $unserialized; $this->default_namespace = $data[0]; $this->parameters = $data[1]; diff --git a/lib/util/sfParameterHolder.class.php b/lib/util/sfParameterHolder.class.php index 6f46b64f3..3e8a0b20b 100644 --- a/lib/util/sfParameterHolder.class.php +++ b/lib/util/sfParameterHolder.class.php @@ -183,9 +183,14 @@ public function addByRef(& $parameters) * * @return array Objects instance */ - public function serialize() + public function serialize(): string { - return serialize($this->parameters); + return serialize($this->__serialize()); + } + + public function __serialize(): array + { + return $this->parameters; } /** @@ -193,8 +198,13 @@ public function serialize() * * @param string $serialized A serialized sfParameterHolder instance */ - public function unserialize($serialized) + public function unserialize(string $serialized) + { + $this->__unserialize(unserialize($serialized)); + } + + public function __unserialize(array $unserialized) { - $this->parameters = unserialize($serialized); + $this->parameters = $unserialized; } } diff --git a/lib/util/sfToolkit.class.php b/lib/util/sfToolkit.class.php index b3bda1000..352768908 100644 --- a/lib/util/sfToolkit.class.php +++ b/lib/util/sfToolkit.class.php @@ -366,7 +366,7 @@ public static function replaceConstants($value) */ public static function pregtr($search, $replacePairs) { - return preg_replace(array_keys($replacePairs), array_values($replacePairs), $search); + return ($search) ? preg_replace(array_keys($replacePairs), array_values($replacePairs), $search) : $search; } /** diff --git a/lib/validator/sfValidatorError.class.php b/lib/validator/sfValidatorError.class.php index 5eab900ae..51f3c29fc 100644 --- a/lib/validator/sfValidatorError.class.php +++ b/lib/validator/sfValidatorError.class.php @@ -138,9 +138,14 @@ public function getMessageFormat() * * @return string The instance as a serialized string */ - public function serialize() + public function serialize(): string { - return serialize(array($this->validator, $this->arguments, $this->code, $this->message)); + return serialize($this->__serialize()); + } + + public function __serialize(): array + { + return array($this->validator, $this->arguments, $this->code, $this->message); } /** @@ -149,8 +154,13 @@ public function serialize() * @param string $serialized A serialized sfValidatorError instance * */ - public function unserialize($serialized) + public function unserialize(string $serialized) + { + $this->__unserialize(unserialize($serialized)); + } + + public function __unserialize(array $unserialized) { - list($this->validator, $this->arguments, $this->code, $this->message) = unserialize($serialized); + list($this->validator, $this->arguments, $this->code, $this->message) = $unserialized; } } diff --git a/lib/validator/sfValidatorErrorSchema.class.php b/lib/validator/sfValidatorErrorSchema.class.php index d722102ac..a44f9118f 100644 --- a/lib/validator/sfValidatorErrorSchema.class.php +++ b/lib/validator/sfValidatorErrorSchema.class.php @@ -176,7 +176,7 @@ public function getMessageFormat() * * @return int The number of array */ - public function count() + public function count(): int { return count($this->errors); } @@ -184,7 +184,7 @@ public function count() /** * Reset the error array to the beginning (implements the Iterator interface). */ - public function rewind() + public function rewind(): void { reset($this->errors); @@ -196,7 +196,7 @@ public function rewind() * * @return string The key */ - public function key() + public function key(): mixed { return key($this->errors); } @@ -206,7 +206,7 @@ public function key() * * @return mixed The escaped value */ - public function current() + public function current(): mixed { return current($this->errors); } @@ -214,7 +214,7 @@ public function current() /** * Moves to the next error (implements the Iterator interface). */ - public function next() + public function next(): void { next($this->errors); @@ -226,7 +226,7 @@ public function next() * * @return boolean The validity of the current element; true if it is valid */ - public function valid() + public function valid(): bool { return $this->count > 0; } @@ -238,9 +238,9 @@ public function valid() * * @return bool true if the error exists, false otherwise */ - public function offsetExists($name) + public function offsetExists(mixed $offset): bool { - return isset($this->errors[$name]); + return isset($this->errors[$offset]); } /** @@ -250,7 +250,7 @@ public function offsetExists($name) * * @return sfValidatorError A sfValidatorError instance */ - public function offsetGet($name) + public function offsetGet(mixed $name): mixed { return isset($this->errors[$name]) ? $this->errors[$name] : null; } @@ -263,7 +263,7 @@ public function offsetGet($name) * * @throws LogicException */ - public function offsetSet($offset, $value) + public function offsetSet(mixed $offset, mixed $value): void { throw new LogicException('Unable update an error.'); } @@ -273,7 +273,7 @@ public function offsetSet($offset, $value) * * @param string $offset (ignored) */ - public function offsetUnset($offset) + public function offsetUnset(mixed $offset): void { } @@ -304,9 +304,14 @@ protected function updateMessage() * * @return string The instance as a serialized string */ - public function serialize() + public function serialize(): string { - return serialize(array($this->validator, $this->arguments, $this->code, $this->message, $this->errors, $this->globalErrors, $this->namedErrors)); + return serialize($this->__serialize()); + } + + public function __serialize(): array + { + return array($this->validator, $this->arguments, $this->code, $this->message, $this->errors, $this->globalErrors, $this->namedErrors); } /** @@ -315,8 +320,13 @@ public function serialize() * @param string $serialized A serialized sfValidatorError instance * */ - public function unserialize($serialized) + public function unserialize(string $serialized) + { + $this->__unserialize(unserialize($serialized)); + } + + public function __unserialize(array $unserialized) { - list($this->validator, $this->arguments, $this->code, $this->message, $this->errors, $this->globalErrors, $this->namedErrors) = unserialize($serialized); + list($this->validator, $this->arguments, $this->code, $this->message, $this->errors, $this->globalErrors, $this->namedErrors) = $unserialized; } } diff --git a/lib/validator/sfValidatorSchema.class.php b/lib/validator/sfValidatorSchema.class.php index bbd215203..c7edeed66 100644 --- a/lib/validator/sfValidatorSchema.class.php +++ b/lib/validator/sfValidatorSchema.class.php @@ -309,9 +309,9 @@ public function getPostValidator() * * @return bool true if the schema has a field with the given name, false otherwise */ - public function offsetExists($name) + public function offsetExists(mixed $offset): bool { - return isset($this->fields[$name]); + return isset($this->fields[$offset]); } /** @@ -321,7 +321,7 @@ public function offsetExists($name) * * @return sfValidatorBase The sfValidatorBase instance associated with the given name, null if it does not exist */ - public function offsetGet($name) + public function offsetGet(mixed $name): mixed { return isset($this->fields[$name]) ? $this->fields[$name] : null; } @@ -332,7 +332,7 @@ public function offsetGet($name) * @param string $name The field name * @param sfValidatorBase $validator An sfValidatorBase instance */ - public function offsetSet($name, $validator) + public function offsetSet(mixed $name, mixed $validator): void { if (!$validator instanceof sfValidatorBase) { @@ -347,7 +347,7 @@ public function offsetSet($name, $validator) * * @param string $name */ - public function offsetUnset($name) + public function offsetUnset(mixed $name): void { unset($this->fields[$name]); } diff --git a/lib/vendor/lime/lime.php b/lib/vendor/lime/lime.php index 53fdd0dd1..d087dd631 100644 --- a/lib/vendor/lime/lime.php +++ b/lib/vendor/lime/lime.php @@ -564,7 +564,7 @@ protected function find_caller($traces) return array($traces[$last]['file'], $traces[$last]['line']); } - public function handle_error($code, $message, $file, $line, $context) + public function handle_error($code, $message, $file, $line, $context = null) { if (!$this->options['error_reporting'] || ($code & error_reporting()) == 0) { diff --git a/lib/view/sfViewParameterHolder.class.php b/lib/view/sfViewParameterHolder.class.php index 5172c8aac..b9ecbd61c 100644 --- a/lib/view/sfViewParameterHolder.class.php +++ b/lib/view/sfViewParameterHolder.class.php @@ -167,9 +167,14 @@ public function setEscapingMethod($method) * * @return array Objects instance */ - public function serialize() + public function serialize(): string { - return serialize(array($this->getAll(), $this->escapingMethod, $this->escaping)); + return serialize($this->__serialize()); + } + + public function __serialize(): array + { + return array($this->getAll(), $this->escapingMethod, $this->escaping); } /** @@ -177,9 +182,14 @@ public function serialize() * * @param string $serialized The serialized instance data */ - public function unserialize($serialized) + public function unserialize(string $serialized) + { + $this->__unserialize(unserialize($serialized)); + } + + public function __unserialize(array $unserialized) { - list($this->parameters, $escapingMethod, $escaping) = unserialize($serialized); + list($this->parameters, $escapingMethod, $escaping) = $unserialized; $this->initialize(sfContext::hasInstance() ? sfContext::getInstance()->getEventDispatcher() : new sfEventDispatcher()); diff --git a/lib/widget/sfWidgetFormSchema.class.php b/lib/widget/sfWidgetFormSchema.class.php index acc3090d4..e9fd33b04 100644 --- a/lib/widget/sfWidgetFormSchema.class.php +++ b/lib/widget/sfWidgetFormSchema.class.php @@ -659,9 +659,9 @@ public function generateName($name) * * @return bool true if the schema has a field with the given name, false otherwise */ - public function offsetExists($name) + public function offsetExists(mixed $offset): bool { - return isset($this->fields[$name]); + return isset($this->fields[$offset]); } /** @@ -671,7 +671,7 @@ public function offsetExists($name) * * @return sfWidget|null The sfWidget instance associated with the given name, null if it does not exist */ - public function offsetGet($name) + public function offsetGet(mixed $name): mixed { return isset($this->fields[$name]) ? $this->fields[$name] : null; } @@ -684,7 +684,7 @@ public function offsetGet($name) * * @throws InvalidArgumentException when the field is not instance of sfWidget */ - public function offsetSet($name, $widget) + public function offsetSet(mixed $name, mixed $widget): void { if (!$widget instanceof sfWidget) { @@ -710,7 +710,7 @@ public function offsetSet($name, $widget) * * @param string $name field name */ - public function offsetUnset($name) + public function offsetUnset(mixed $name): void { unset($this->fields[$name]); if (false !== $position = array_search((string) $name, $this->positions)) diff --git a/lib/widget/sfWidgetFormSchemaDecorator.class.php b/lib/widget/sfWidgetFormSchemaDecorator.class.php index c5d414068..e00cf5cc4 100644 --- a/lib/widget/sfWidgetFormSchemaDecorator.class.php +++ b/lib/widget/sfWidgetFormSchemaDecorator.class.php @@ -346,16 +346,16 @@ public function moveField($field, $action, $pivot = null) * @see sfWidgetFormSchema * @inheritdoc */ - public function offsetExists($name) + public function offsetExists(mixed $offset): bool { - return isset($this->widget[$name]); + return isset($this->widget[$offset]); } /** * @see sfWidgetFormSchema * @inheritdoc */ - public function offsetGet($name) + public function offsetGet(mixed $name): mixed { return $this->widget[$name]; } @@ -364,7 +364,7 @@ public function offsetGet($name) * @see sfWidgetFormSchema * @inheritdoc */ - public function offsetSet($name, $widget) + public function offsetSet(mixed $name, mixed $widget): void { $this->widget[$name] = $widget; } @@ -373,7 +373,7 @@ public function offsetSet($name, $widget) * @see sfWidgetFormSchema * @inheritdoc */ - public function offsetUnset($name) + public function offsetUnset(mixed $name): void { unset($this->widget[$name]); } diff --git a/test/unit/escaper/sfOutputEscaperObjectDecoratorTest.php b/test/unit/escaper/sfOutputEscaperObjectDecoratorTest.php index 967bde98a..8403cc8cf 100644 --- a/test/unit/escaper/sfOutputEscaperObjectDecoratorTest.php +++ b/test/unit/escaper/sfOutputEscaperObjectDecoratorTest.php @@ -74,7 +74,7 @@ class Foo class FooCountable implements Countable { - public function count() + public function count(): int { return 2; } diff --git a/test/unit/response/sfResponseTest.php b/test/unit/response/sfResponseTest.php index 31aad5842..69a089324 100644 --- a/test/unit/response/sfResponseTest.php +++ b/test/unit/response/sfResponseTest.php @@ -12,8 +12,10 @@ class myResponse extends sfResponse { - function serialize() {} - function unserialize($serialized) {} + function serialize(): string {} + function __serialize(): array {} + function unserialize(string $serialized) + function __unserialize(array $unserialized) } class fakeResponse diff --git a/test/unit/validator/sfValidatorErrorSchemaTest.php b/test/unit/validator/sfValidatorErrorSchemaTest.php index e7768a9a6..fdd0e5e5d 100644 --- a/test/unit/validator/sfValidatorErrorSchemaTest.php +++ b/test/unit/validator/sfValidatorErrorSchemaTest.php @@ -178,12 +178,22 @@ class NotSerializable implements Serializable { - public function serialize() + public function serialize(): string { throw new Exception('Not serializable'); } - public function unserialize($serialized) + public function __serialize(): array + { + throw new Exception('Not serializable'); + } + + public function unserialize(string $serialized) + { + throw new Exception('Not serializable'); + } + + public function __unserialize(array $unserialized) { throw new Exception('Not serializable'); } diff --git a/test/unit/validator/sfValidatorErrorTest.php b/test/unit/validator/sfValidatorErrorTest.php index 41b03f4c3..099c7f7e8 100644 --- a/test/unit/validator/sfValidatorErrorTest.php +++ b/test/unit/validator/sfValidatorErrorTest.php @@ -56,12 +56,22 @@ // even if you use PDO as a session handler class NotSerializable implements Serializable { - public function serialize() + public function serialize(): string { throw new Exception('Not serializable'); } - public function unserialize($serialized) + public function __serialize(): array + { + throw new Exception('Not serializable'); + } + + public function unserialize(string $serialized) + { + throw new Exception('Not serializable'); + } + + public function __unserialize(array $unserialized) { throw new Exception('Not serializable'); }