From f32705e1252fa55a25b2c291dcecf61ed43d481b Mon Sep 17 00:00:00 2001 From: Zachary Tong Date: Thu, 23 Jan 2014 11:32:31 -0500 Subject: [PATCH 1/6] [YAML] Added support for object maps Previously, the parser treated maps ( {} ) the same as sets ( [] ). Both were returned as PHP associative arrays. Since these are distinct entities, this can cause considerably problems for the users, especially when YAML is being serialized into another format such as JSON. This commit allows the user to enable object-map support via a third parameter on the Parse method. It defaults to `false`, which means that this commit does not break backwards compatibility. If the user enables object-map support, maps are represented by stdClass() objects. Sets remain as arrays. --- src/Symfony/Component/Yaml/Inline.php | 54 +++++--- .../Component/Yaml/Tests/InlineTest.php | 122 ++++++++++++++++++ 2 files changed, 158 insertions(+), 18 deletions(-) diff --git a/src/Symfony/Component/Yaml/Inline.php b/src/Symfony/Component/Yaml/Inline.php index 45efced3c89ac..a5267b9bd1aa9 100644 --- a/src/Symfony/Component/Yaml/Inline.php +++ b/src/Symfony/Component/Yaml/Inline.php @@ -26,18 +26,20 @@ class Inline private static $exceptionOnInvalidType = false; private static $objectSupport = false; + /** * Converts a YAML string to a PHP array. * * @param string $value A YAML string * @param Boolean $exceptionOnInvalidType true if an exception must be thrown on invalid types (a PHP resource or object), false otherwise * @param Boolean $objectSupport true if object support is enabled, false otherwise + * @param Boolean $objectForMap true if maps should return a stdClass instead of array() * + * @throws Exception\ParseException * @return array A PHP array representing the YAML string * - * @throws ParseException */ - public static function parse($value, $exceptionOnInvalidType = false, $objectSupport = false) + public static function parse($value, $exceptionOnInvalidType = false, $objectSupport = false, $objectForMap = false) { self::$exceptionOnInvalidType = $exceptionOnInvalidType; self::$objectSupport = $objectSupport; @@ -56,11 +58,11 @@ public static function parse($value, $exceptionOnInvalidType = false, $objectSup $i = 0; switch ($value[0]) { case '[': - $result = self::parseSequence($value, $i); + $result = self::parseSequence($value, $i, $objectForMap); ++$i; break; case '{': - $result = self::parseMapping($value, $i); + $result = self::parseMapping($value, $i, $objectForMap); ++$i; break; default: @@ -256,17 +258,18 @@ private static function parseQuotedScalar($scalar, &$i) return $output; } + /** * Parses a sequence to a YAML string. * - * @param string $sequence + * @param string $sequence * @param integer &$i + * @param Boolean $objectForMap true if maps should return a stdClass instead of array() * + * @throws Exception\ParseException * @return string A YAML string - * - * @throws ParseException When malformed inline YAML string is parsed */ - private static function parseSequence($sequence, &$i = 0) + private static function parseSequence($sequence, &$i = 0, $objectForMap = false) { $output = array(); $len = strlen($sequence); @@ -277,11 +280,11 @@ private static function parseSequence($sequence, &$i = 0) switch ($sequence[$i]) { case '[': // nested sequence - $output[] = self::parseSequence($sequence, $i); + $output[] = self::parseSequence($sequence, $i, $objectForMap); break; case '{': // nested mapping - $output[] = self::parseMapping($sequence, $i); + $output[] = self::parseMapping($sequence, $i, $objectForMap); break; case ']': return $output; @@ -295,7 +298,8 @@ private static function parseSequence($sequence, &$i = 0) if (!$isQuoted && false !== strpos($value, ': ')) { // embedded mapping? try { - $value = self::parseMapping('{'.$value.'}'); + $j = 0; + $value = self::parseMapping('{'.$value.'}', $j, $objectForMap); } catch (\InvalidArgumentException $e) { // no, it's not } @@ -312,19 +316,26 @@ private static function parseSequence($sequence, &$i = 0) throw new ParseException(sprintf('Malformed inline YAML string %s', $sequence)); } + /** * Parses a mapping to a YAML string. * - * @param string $mapping + * @param string $mapping * @param integer &$i + * @param Boolean $objectForMap true if maps should return a stdClass instead of array() * + * @throws Exception\ParseException * @return string A YAML string * - * @throws ParseException When malformed inline YAML string is parsed */ - private static function parseMapping($mapping, &$i = 0) + private static function parseMapping($mapping, &$i = 0, $objectForMap = false) { - $output = array(); + if ($objectForMap === true) { + $output = new \stdClass(); + } else { + $output = array(); + } + $len = strlen($mapping); $i += 1; @@ -344,23 +355,30 @@ private static function parseMapping($mapping, &$i = 0) // value $done = false; + + if ($objectForMap === true) { + $editPosition = &$output->$key; + } else { + $editPosition = &$output[$key]; + } + while ($i < $len) { switch ($mapping[$i]) { case '[': // nested sequence - $output[$key] = self::parseSequence($mapping, $i); + $editPosition = self::parseSequence($mapping, $i, $objectForMap); $done = true; break; case '{': // nested mapping - $output[$key] = self::parseMapping($mapping, $i); + $editPosition = self::parseMapping($mapping, $i, $objectForMap); $done = true; break; case ':': case ' ': break; default: - $output[$key] = self::parseScalar($mapping, array(',', '}'), array('"', "'"), $i); + $editPosition = self::parseScalar($mapping, array(',', '}'), array('"', "'"), $i); $done = true; --$i; } diff --git a/src/Symfony/Component/Yaml/Tests/InlineTest.php b/src/Symfony/Component/Yaml/Tests/InlineTest.php index af5018f2026f9..c328e11720761 100644 --- a/src/Symfony/Component/Yaml/Tests/InlineTest.php +++ b/src/Symfony/Component/Yaml/Tests/InlineTest.php @@ -22,6 +22,23 @@ public function testParse() } } + public function testParseWithMapObjects() + { + foreach ($this->getTestsForMapObjectParse() as $yaml => $value) { + $actual = Inline::parse($yaml, false, false, true); + if (is_object($value) === true) { + $this->assertInstanceOf(get_class($value), $actual); + $this->assertEquals(get_object_vars($value), get_object_vars($actual)); + } elseif (is_array($value) === true) { + $this->assertEquals($value, $actual); + $this->assertMixedArraysSame($value, $actual); + } else { + $this->assertSame($value, $actual); + } + } + + } + public function testDump() { $testsForDump = $this->getTestsForDump(); @@ -182,6 +199,88 @@ protected function getTestsForParse() ); } + protected function getTestsForMapObjectParse() + { + return array( + '' => '', + 'null' => null, + 'false' => false, + 'true' => true, + '12' => 12, + '-12' => -12, + '"quoted string"' => 'quoted string', + "'quoted string'" => 'quoted string', + '12.30e+02' => 12.30e+02, + '0x4D2' => 0x4D2, + '02333' => 02333, + '.Inf' => -log(0), + '-.Inf' => log(0), + "'686e444'" => '686e444', + '686e444' => 646e444, + '123456789123456789123456789123456789' => '123456789123456789123456789123456789', + '"foo\r\nbar"' => "foo\r\nbar", + "'foo#bar'" => 'foo#bar', + "'foo # bar'" => 'foo # bar', + "'#cfcfcf'" => '#cfcfcf', + '::form_base.html.twig' => '::form_base.html.twig', + + '2007-10-30' => mktime(0, 0, 0, 10, 30, 2007), + '2007-10-30T02:59:43Z' => gmmktime(2, 59, 43, 10, 30, 2007), + '2007-10-30 02:59:43 Z' => gmmktime(2, 59, 43, 10, 30, 2007), + '1960-10-30 02:59:43 Z' => gmmktime(2, 59, 43, 10, 30, 1960), + '1730-10-30T02:59:43Z' => gmmktime(2, 59, 43, 10, 30, 1730), + + '"a \\"string\\" with \'quoted strings inside\'"' => 'a "string" with \'quoted strings inside\'', + "'a \"string\" with ''quoted strings inside'''" => 'a "string" with \'quoted strings inside\'', + + // sequences + // urls are no key value mapping. see #3609. Valid yaml "key: value" mappings require a space after the colon + '[foo, http://urls.are/no/mappings, false, null, 12]' => array('foo', 'http://urls.are/no/mappings', false, null, 12), + '[ foo , bar , false , null , 12 ]' => array('foo', 'bar', false, null, 12), + '[\'foo,bar\', \'foo bar\']' => array('foo,bar', 'foo bar'), + + // mappings + '{foo:bar,bar:foo,false:false,null:null,integer:12}' => (object)array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12), + '{ foo : bar, bar : foo, false : false, null : null, integer : 12 }' => (object)array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12), + '{foo: \'bar\', bar: \'foo: bar\'}' => (object)array('foo' => 'bar', 'bar' => 'foo: bar'), + '{\'foo\': \'bar\', "bar": \'foo: bar\'}' => (object)array('foo' => 'bar', 'bar' => 'foo: bar'), + '{\'foo\'\'\': \'bar\', "bar\"": \'foo: bar\'}' => (object)array('foo\'' => 'bar', "bar\"" => 'foo: bar'), + '{\'foo: \': \'bar\', "bar: ": \'foo: bar\'}' => (object)array('foo: ' => 'bar', "bar: " => 'foo: bar'), + + // nested sequences and mappings + '[foo, [bar, foo]]' => array('foo', array('bar', 'foo')), + '[foo, {bar: foo}]' => array('foo', (object)array('bar' => 'foo')), + '{ foo: {bar: foo} }' => (object)array('foo' => (object)array('bar' => 'foo')), + '{ foo: [bar, foo] }' => (object)array('foo' => array('bar', 'foo')), + + '[ foo, [ bar, foo ] ]' => array('foo', array('bar', 'foo')), + + '[{ foo: {bar: foo} }]' => array((object)array('foo' => (object)array('bar' => 'foo'))), + + '[foo, [bar, [foo, [bar, foo]], foo]]' => array('foo', array('bar', array('foo', array('bar', 'foo')), 'foo')), + + '[foo, {bar: foo, foo: [foo, {bar: foo}]}, [foo, {bar: foo}]]' => array('foo', (object)array('bar' => 'foo', 'foo' => array('foo', (object)array('bar' => 'foo'))), array('foo', (object)array('bar' => 'foo'))), + + '[foo, bar: { foo: bar }]' => array('foo', '1' => (object)array('bar' => (object)array('foo' => 'bar'))), + '[foo, \'@foo.baz\', { \'%foo%\': \'foo is %foo%\', bar: \'%foo%\' }, true, \'@service_container\']' => array('foo', '@foo.baz', (object)array('%foo%' => 'foo is %foo%', 'bar' => '%foo%',), true, '@service_container',), + + + '{}' => new \stdClass(), + '{ foo : bar, bar : {} }' => (object)array('foo' => 'bar', 'bar' => new \stdClass()), + '{ foo : [], bar : {} }' => (object)array('foo' => array(), 'bar' => new \stdClass()), + '{foo: \'bar\', bar: {} }' => (object)array('foo' => 'bar', 'bar' => new \stdClass()), + '{\'foo\': \'bar\', "bar": {}}' => (object)array('foo' => 'bar', 'bar' => new \stdClass()), + '{\'foo\': \'bar\', "bar": \'{}\'}' => (object)array('foo' => 'bar', 'bar' => '{}'), + + '[foo, [{}, {}]]' => array('foo', array(new \stdClass(), new \stdClass())), + '[foo, [[], {}]]' => array('foo', array(array(), new \stdClass())), + '[foo, [[{}, {}], {}]]' => array('foo', array(array(new \stdClass(), new \stdClass()), new \stdClass())), + '[foo, {bar: {}}]' => array('foo', '1' => (object)array('bar' => new \stdClass())), + ); + } + + + protected function getTestsForDump() { return array( @@ -229,4 +328,27 @@ protected function getTestsForDump() '[foo, \'@foo.baz\', { \'%foo%\': \'foo is %foo%\', bar: \'%foo%\' }, true, \'@service_container\']' => array('foo', '@foo.baz', array('%foo%' => 'foo is %foo%', 'bar' => '%foo%',), true, '@service_container',), ); } + + protected function assertMixedArraysSame($a, $b) + { + + foreach ($a as $key => $value) { + if (array_key_exists($key, $b)) { + if (is_array($value)) { + $this->assertMixedArraysSame($value, $b[$key]); + } else { + if (is_object($value) === true) { + $this->assertEquals($value, $b[$key]); + $this->assertInstanceOf(get_class($value), $b[$key]); + $this->assertEquals(get_object_vars($value), get_object_vars($b[$key])); + } else { + $this->assertSame($value, $b[$key]); + } + } + } else { + $this->assertFail(); + } + } + + } } From 3e8adee5184b43895bbcfd7d3b60e5b79e2552d4 Mon Sep 17 00:00:00 2001 From: Zachary Tong Date: Thu, 20 Feb 2014 13:17:18 -0500 Subject: [PATCH 2/6] Coding standards to comply with Fabbot --- src/Symfony/Component/Yaml/Inline.php | 2 - .../Component/Yaml/Tests/InlineTest.php | 41 +++++++++---------- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/src/Symfony/Component/Yaml/Inline.php b/src/Symfony/Component/Yaml/Inline.php index a5267b9bd1aa9..f2645c969aa68 100644 --- a/src/Symfony/Component/Yaml/Inline.php +++ b/src/Symfony/Component/Yaml/Inline.php @@ -26,7 +26,6 @@ class Inline private static $exceptionOnInvalidType = false; private static $objectSupport = false; - /** * Converts a YAML string to a PHP array. * @@ -258,7 +257,6 @@ private static function parseQuotedScalar($scalar, &$i) return $output; } - /** * Parses a sequence to a YAML string. * diff --git a/src/Symfony/Component/Yaml/Tests/InlineTest.php b/src/Symfony/Component/Yaml/Tests/InlineTest.php index c328e11720761..e28b8257892f8 100644 --- a/src/Symfony/Component/Yaml/Tests/InlineTest.php +++ b/src/Symfony/Component/Yaml/Tests/InlineTest.php @@ -240,47 +240,44 @@ protected function getTestsForMapObjectParse() '[\'foo,bar\', \'foo bar\']' => array('foo,bar', 'foo bar'), // mappings - '{foo:bar,bar:foo,false:false,null:null,integer:12}' => (object)array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12), - '{ foo : bar, bar : foo, false : false, null : null, integer : 12 }' => (object)array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12), - '{foo: \'bar\', bar: \'foo: bar\'}' => (object)array('foo' => 'bar', 'bar' => 'foo: bar'), - '{\'foo\': \'bar\', "bar": \'foo: bar\'}' => (object)array('foo' => 'bar', 'bar' => 'foo: bar'), - '{\'foo\'\'\': \'bar\', "bar\"": \'foo: bar\'}' => (object)array('foo\'' => 'bar', "bar\"" => 'foo: bar'), - '{\'foo: \': \'bar\', "bar: ": \'foo: bar\'}' => (object)array('foo: ' => 'bar', "bar: " => 'foo: bar'), + '{foo:bar,bar:foo,false:false,null:null,integer:12}' => (object) array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12), + '{ foo : bar, bar : foo, false : false, null : null, integer : 12 }' => (object) array('foo' => 'bar', 'bar' => 'foo', 'false' => false, 'null' => null, 'integer' => 12), + '{foo: \'bar\', bar: \'foo: bar\'}' => (object) array('foo' => 'bar', 'bar' => 'foo: bar'), + '{\'foo\': \'bar\', "bar": \'foo: bar\'}' => (object) array('foo' => 'bar', 'bar' => 'foo: bar'), + '{\'foo\'\'\': \'bar\', "bar\"": \'foo: bar\'}' => (object) array('foo\'' => 'bar', "bar\"" => 'foo: bar'), + '{\'foo: \': \'bar\', "bar: ": \'foo: bar\'}' => (object) array('foo: ' => 'bar', "bar: " => 'foo: bar'), // nested sequences and mappings '[foo, [bar, foo]]' => array('foo', array('bar', 'foo')), - '[foo, {bar: foo}]' => array('foo', (object)array('bar' => 'foo')), - '{ foo: {bar: foo} }' => (object)array('foo' => (object)array('bar' => 'foo')), - '{ foo: [bar, foo] }' => (object)array('foo' => array('bar', 'foo')), + '[foo, {bar: foo}]' => array('foo', (object) array('bar' => 'foo')), + '{ foo: {bar: foo} }' => (object) array('foo' => (object) array('bar' => 'foo')), + '{ foo: [bar, foo] }' => (object) array('foo' => array('bar', 'foo')), '[ foo, [ bar, foo ] ]' => array('foo', array('bar', 'foo')), - '[{ foo: {bar: foo} }]' => array((object)array('foo' => (object)array('bar' => 'foo'))), + '[{ foo: {bar: foo} }]' => array((object) array('foo' => (object) array('bar' => 'foo'))), '[foo, [bar, [foo, [bar, foo]], foo]]' => array('foo', array('bar', array('foo', array('bar', 'foo')), 'foo')), - '[foo, {bar: foo, foo: [foo, {bar: foo}]}, [foo, {bar: foo}]]' => array('foo', (object)array('bar' => 'foo', 'foo' => array('foo', (object)array('bar' => 'foo'))), array('foo', (object)array('bar' => 'foo'))), - - '[foo, bar: { foo: bar }]' => array('foo', '1' => (object)array('bar' => (object)array('foo' => 'bar'))), - '[foo, \'@foo.baz\', { \'%foo%\': \'foo is %foo%\', bar: \'%foo%\' }, true, \'@service_container\']' => array('foo', '@foo.baz', (object)array('%foo%' => 'foo is %foo%', 'bar' => '%foo%',), true, '@service_container',), + '[foo, {bar: foo, foo: [foo, {bar: foo}]}, [foo, {bar: foo}]]' => array('foo', (object) array('bar' => 'foo', 'foo' => array('foo', (object) array('bar' => 'foo'))), array('foo', (object) array('bar' => 'foo'))), + '[foo, bar: { foo: bar }]' => array('foo', '1' => (object) array('bar' => (object) array('foo' => 'bar'))), + '[foo, \'@foo.baz\', { \'%foo%\': \'foo is %foo%\', bar: \'%foo%\' }, true, \'@service_container\']' => array('foo', '@foo.baz', (object) array('%foo%' => 'foo is %foo%', 'bar' => '%foo%',), true, '@service_container',), '{}' => new \stdClass(), - '{ foo : bar, bar : {} }' => (object)array('foo' => 'bar', 'bar' => new \stdClass()), - '{ foo : [], bar : {} }' => (object)array('foo' => array(), 'bar' => new \stdClass()), - '{foo: \'bar\', bar: {} }' => (object)array('foo' => 'bar', 'bar' => new \stdClass()), - '{\'foo\': \'bar\', "bar": {}}' => (object)array('foo' => 'bar', 'bar' => new \stdClass()), - '{\'foo\': \'bar\', "bar": \'{}\'}' => (object)array('foo' => 'bar', 'bar' => '{}'), + '{ foo : bar, bar : {} }' => (object) array('foo' => 'bar', 'bar' => new \stdClass()), + '{ foo : [], bar : {} }' => (object) array('foo' => array(), 'bar' => new \stdClass()), + '{foo: \'bar\', bar: {} }' => (object) array('foo' => 'bar', 'bar' => new \stdClass()), + '{\'foo\': \'bar\', "bar": {}}' => (object) array('foo' => 'bar', 'bar' => new \stdClass()), + '{\'foo\': \'bar\', "bar": \'{}\'}' => (object) array('foo' => 'bar', 'bar' => '{}'), '[foo, [{}, {}]]' => array('foo', array(new \stdClass(), new \stdClass())), '[foo, [[], {}]]' => array('foo', array(array(), new \stdClass())), '[foo, [[{}, {}], {}]]' => array('foo', array(array(new \stdClass(), new \stdClass()), new \stdClass())), - '[foo, {bar: {}}]' => array('foo', '1' => (object)array('bar' => new \stdClass())), + '[foo, {bar: {}}]' => array('foo', '1' => (object) array('bar' => new \stdClass())), ); } - - protected function getTestsForDump() { return array( From 244b50b6dce67ea5f2fdf2a71e588dc859cf0279 Mon Sep 17 00:00:00 2001 From: Zachary Tong Date: Fri, 21 Feb 2014 08:27:44 -0500 Subject: [PATCH 3/6] Cast to stdClass on return instead of each iteration --- src/Symfony/Component/Yaml/Inline.php | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/Symfony/Component/Yaml/Inline.php b/src/Symfony/Component/Yaml/Inline.php index f2645c969aa68..261d5bf13eb18 100644 --- a/src/Symfony/Component/Yaml/Inline.php +++ b/src/Symfony/Component/Yaml/Inline.php @@ -328,12 +328,7 @@ private static function parseSequence($sequence, &$i = 0, $objectForMap = false) */ private static function parseMapping($mapping, &$i = 0, $objectForMap = false) { - if ($objectForMap === true) { - $output = new \stdClass(); - } else { - $output = array(); - } - + $output = array(); $len = strlen($mapping); $i += 1; @@ -345,7 +340,11 @@ private static function parseMapping($mapping, &$i = 0, $objectForMap = false) ++$i; continue 2; case '}': - return $output; + if ($objectForMap === true) { + return (object)$output; + } else { + return $output; + } } // key @@ -354,29 +353,24 @@ private static function parseMapping($mapping, &$i = 0, $objectForMap = false) // value $done = false; - if ($objectForMap === true) { - $editPosition = &$output->$key; - } else { - $editPosition = &$output[$key]; - } while ($i < $len) { switch ($mapping[$i]) { case '[': // nested sequence - $editPosition = self::parseSequence($mapping, $i, $objectForMap); + $output[$key] = self::parseSequence($mapping, $i, $objectForMap); $done = true; break; case '{': // nested mapping - $editPosition = self::parseMapping($mapping, $i, $objectForMap); + $output[$key] = self::parseMapping($mapping, $i, $objectForMap); $done = true; break; case ':': case ' ': break; default: - $editPosition = self::parseScalar($mapping, array(',', '}'), array('"', "'"), $i); + $output[$key] = self::parseScalar($mapping, array(',', '}'), array('"', "'"), $i); $done = true; --$i; } From ed43239c0435eb19053266f98ad25c30883b46b3 Mon Sep 17 00:00:00 2001 From: Zachary Tong Date: Fri, 21 Feb 2014 08:58:21 -0500 Subject: [PATCH 4/6] Formatting fixes --- src/Symfony/Component/Yaml/Inline.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/Symfony/Component/Yaml/Inline.php b/src/Symfony/Component/Yaml/Inline.php index 261d5bf13eb18..0719bc66cde60 100644 --- a/src/Symfony/Component/Yaml/Inline.php +++ b/src/Symfony/Component/Yaml/Inline.php @@ -314,7 +314,6 @@ private static function parseSequence($sequence, &$i = 0, $objectForMap = false) throw new ParseException(sprintf('Malformed inline YAML string %s', $sequence)); } - /** * Parses a mapping to a YAML string. * @@ -340,11 +339,10 @@ private static function parseMapping($mapping, &$i = 0, $objectForMap = false) ++$i; continue 2; case '}': - if ($objectForMap === true) { - return (object)$output; - } else { - return $output; + if (true === $objectForMap ) { + return (object) $output; } + return $output; } // key From 53e699250cad6745da4b4daa524a321f28201dc0 Mon Sep 17 00:00:00 2001 From: Zachary Tong Date: Fri, 21 Feb 2014 09:05:39 -0500 Subject: [PATCH 5/6] More formatting --- src/Symfony/Component/Yaml/Tests/InlineTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Yaml/Tests/InlineTest.php b/src/Symfony/Component/Yaml/Tests/InlineTest.php index e28b8257892f8..5fe0db1c55e7b 100644 --- a/src/Symfony/Component/Yaml/Tests/InlineTest.php +++ b/src/Symfony/Component/Yaml/Tests/InlineTest.php @@ -26,10 +26,10 @@ public function testParseWithMapObjects() { foreach ($this->getTestsForMapObjectParse() as $yaml => $value) { $actual = Inline::parse($yaml, false, false, true); - if (is_object($value) === true) { + if (true === is_object($value)) { $this->assertInstanceOf(get_class($value), $actual); $this->assertEquals(get_object_vars($value), get_object_vars($actual)); - } elseif (is_array($value) === true) { + } elseif (true === is_array($value)) { $this->assertEquals($value, $actual); $this->assertMixedArraysSame($value, $actual); } else { @@ -334,7 +334,7 @@ protected function assertMixedArraysSame($a, $b) if (is_array($value)) { $this->assertMixedArraysSame($value, $b[$key]); } else { - if (is_object($value) === true) { + if (true === is_object($value)) { $this->assertEquals($value, $b[$key]); $this->assertInstanceOf(get_class($value), $b[$key]); $this->assertEquals(get_object_vars($value), get_object_vars($b[$key])); From e5d2f807eb181cd29e9b066e9444a4010ebc50ae Mon Sep 17 00:00:00 2001 From: Zachary Tong Date: Fri, 21 Feb 2014 09:18:31 -0500 Subject: [PATCH 6/6] Formatting --- src/Symfony/Component/Yaml/Inline.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Yaml/Inline.php b/src/Symfony/Component/Yaml/Inline.php index 0719bc66cde60..502f3983f80d9 100644 --- a/src/Symfony/Component/Yaml/Inline.php +++ b/src/Symfony/Component/Yaml/Inline.php @@ -339,9 +339,10 @@ private static function parseMapping($mapping, &$i = 0, $objectForMap = false) ++$i; continue 2; case '}': - if (true === $objectForMap ) { + if (true === $objectForMap) { return (object) $output; } + return $output; }