PHPStorm refactoring.

This commit is contained in:
Andrés Montañez
2014-08-06 14:01:39 -03:00
parent 4c584b2634
commit fddeebe59a
48 changed files with 2011 additions and 1996 deletions
+36 -34
View File
@@ -34,10 +34,10 @@ class Inline
/**
* Converts a YAML string to a PHP array.
*
* @param string $value A YAML string
* @param bool $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise
* @param bool $objectSupport true if object support is enabled, false otherwise
* @param bool $objectForMap true if maps should return a stdClass instead of array()
* @param string $value A YAML string
* @param bool $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise
* @param bool $objectSupport true if object support is enabled, false otherwise
* @param bool $objectForMap true if maps should return a stdClass instead of array()
*
* @return array A PHP array representing the YAML string
*
@@ -55,7 +55,7 @@ class Inline
return '';
}
if (function_exists('mb_internal_encoding') && ((int) ini_get('mbstring.func_overload')) & 2) {
if (function_exists('mb_internal_encoding') && ((int)ini_get('mbstring.func_overload')) & 2) {
$mbEncoding = mb_internal_encoding();
mb_internal_encoding('ASCII');
}
@@ -89,9 +89,9 @@ class Inline
/**
* Dumps a given PHP variable to a YAML string.
*
* @param mixed $value The PHP variable to convert
* @param bool $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise
* @param bool $objectSupport true if object support is enabled, false otherwise
* @param mixed $value The PHP variable to convert
* @param bool $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise
* @param bool $objectSupport true if object support is enabled, false otherwise
*
* @return string The YAML string representing the PHP array
*
@@ -108,7 +108,7 @@ class Inline
return 'null';
case is_object($value):
if ($objectSupport) {
return '!!php/object:'.serialize($value);
return '!!php/object:' . serialize($value);
}
if ($exceptionOnInvalidType) {
@@ -125,7 +125,7 @@ class Inline
case false === $value:
return 'false';
case ctype_digit($value):
return is_string($value) ? "'$value'" : (int) $value;
return is_string($value) ? "'$value'" : (int)$value;
case is_numeric($value):
$locale = setlocale(LC_NUMERIC, 0);
if (false !== $locale) {
@@ -155,9 +155,9 @@ class Inline
/**
* Dumps a PHP array to a YAML string.
*
* @param array $value The PHP array to dump
* @param bool $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise
* @param bool $objectSupport true if object support is enabled, false otherwise
* @param array $value The PHP array to dump
* @param bool $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise
* @param bool $objectSupport true if object support is enabled, false otherwise
*
* @return string The YAML string representing the PHP array
*/
@@ -166,7 +166,9 @@ class Inline
// array
$keys = array_keys($value);
if ((1 == count($keys) && '0' == $keys[0])
|| (count($keys) > 1 && array_reduce($keys, function ($v, $w) { return (int) $v + $w; }, 0) == count($keys) * (count($keys) - 1) / 2)
|| (count($keys) > 1 && array_reduce($keys, function ($v, $w) {
return (int)$v + $w;
}, 0) == count($keys) * (count($keys) - 1) / 2)
) {
$output = array();
foreach ($value as $val) {
@@ -188,11 +190,11 @@ class Inline
/**
* Parses a scalar to a YAML string.
*
* @param scalar $scalar
* @param string $delimiters
* @param array $stringDelimiters
* @param int &$i
* @param bool $evaluate
* @param scalar $scalar
* @param string $delimiters
* @param array $stringDelimiters
* @param int &$i
* @param bool $evaluate
*
* @return string A YAML string
*
@@ -220,7 +222,7 @@ class Inline
if (false !== $strpos = strpos($output, ' #')) {
$output = rtrim(substr($output, 0, $strpos));
}
} elseif (preg_match('/^(.+?)('.implode('|', $delimiters).')/', substr($scalar, $i), $match)) {
} elseif (preg_match('/^(.+?)(' . implode('|', $delimiters) . ')/', substr($scalar, $i), $match)) {
$output = $match[1];
$i += strlen($output);
} else {
@@ -239,7 +241,7 @@ class Inline
* Parses a quoted scalar to YAML.
*
* @param string $scalar
* @param int &$i
* @param int &$i
*
* @return string A YAML string
*
@@ -247,7 +249,7 @@ class Inline
*/
private static function parseQuotedScalar($scalar, &$i)
{
if (!preg_match('/'.self::REGEX_QUOTED_STRING.'/Au', substr($scalar, $i), $match)) {
if (!preg_match('/' . self::REGEX_QUOTED_STRING . '/Au', substr($scalar, $i), $match)) {
throw new ParseException(sprintf('Malformed inline YAML string (%s).', substr($scalar, $i)));
}
@@ -268,8 +270,8 @@ class Inline
/**
* Parses a sequence to a YAML string.
*
* @param string $sequence
* @param int &$i
* @param string $sequence
* @param int &$i
*
* @return string A YAML string
*
@@ -304,7 +306,7 @@ class Inline
if (!$isQuoted && false !== strpos($value, ': ')) {
// embedded mapping?
try {
$value = self::parseMapping('{'.$value.'}');
$value = self::parseMapping('{' . $value . '}');
} catch (\InvalidArgumentException $e) {
// no, it's not
}
@@ -324,8 +326,8 @@ class Inline
/**
* Parses a mapping to a YAML string.
*
* @param string $mapping
* @param int &$i
* @param string $mapping
* @param int &$i
*
* @return string A YAML string
*
@@ -346,7 +348,7 @@ class Inline
continue 2;
case '}':
if (self::$objectForMap) {
return (object) $output;
return (object)$output;
}
return $output;
@@ -425,7 +427,7 @@ class Inline
case '' === $scalar:
case '~' === $scalar:
/** @noinspection PhpInconsistentReturnPointsInspection */
return;
return;
case 'true' === $scalarLower:
return true;
case 'false' === $scalarLower:
@@ -435,7 +437,7 @@ class Inline
case $scalar[0] === '+' || $scalar[0] === '-' || $scalar[0] === '.' || $scalar[0] === '!' || is_numeric($scalar[0]):
switch (true) {
case 0 === strpos($scalar, '!str'):
return (string) substr($scalar, 5);
return (string)substr($scalar, 5);
case 0 === strpos($scalar, '! '):
return intval(self::parseScalar(substr($scalar, 2)));
case 0 === strpos($scalar, '!!php/object:'):
@@ -453,14 +455,14 @@ class Inline
$raw = $scalar;
$cast = intval($scalar);
return '0' == $scalar[0] ? octdec($scalar) : (((string) $raw == (string) $cast) ? $cast : $raw);
return '0' == $scalar[0] ? octdec($scalar) : (((string)$raw == (string)$cast) ? $cast : $raw);
case '-' === $scalar[0] && ctype_digit(substr($scalar, 1)):
$raw = $scalar;
$cast = intval($scalar);
return '0' == $scalar[1] ? octdec($scalar) : (((string) $raw == (string) $cast) ? $cast : $raw);
return '0' == $scalar[1] ? octdec($scalar) : (((string)$raw == (string)$cast) ? $cast : $raw);
case is_numeric($scalar):
return '0x' == $scalar[0].$scalar[1] ? hexdec($scalar) : floatval($scalar);
return '0x' == $scalar[0] . $scalar[1] ? hexdec($scalar) : floatval($scalar);
case '.inf' === $scalarLower:
case '.nan' === $scalarLower:
return -log(0);
@@ -472,7 +474,7 @@ class Inline
return strtotime($scalar);
}
default:
return (string) $scalar;
return (string)$scalar;
}
}