Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions library/Zend/Code/Generator/ValueGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,12 +351,8 @@ public function generate()
break;
case self::TYPE_ARRAY:
$output .= 'array(';
$curArrayMultiblock = false;
if (count($value) > 1) {
$curArrayMultiblock = true;
if ($this->outputMode == self::OUTPUT_MULTIPLE_LINE) {
$output .= self::LINE_FEED . str_repeat($this->indentation, $this->arrayDepth + 1);
}
if ($this->outputMode == self::OUTPUT_MULTIPLE_LINE) {
$output .= self::LINE_FEED . str_repeat($this->indentation, $this->arrayDepth + 1);
}
$outputParts = array();
$noKeyIndex = 0;
Expand Down Expand Up @@ -384,8 +380,8 @@ public function generate()
? self::LINE_FEED . str_repeat($this->indentation, $this->arrayDepth + 1)
: ' ';
$output .= implode(',' . $padding, $outputParts);
if ($curArrayMultiblock == true && $this->outputMode == self::OUTPUT_MULTIPLE_LINE) {
$output .= self::LINE_FEED . str_repeat($this->indentation, $this->arrayDepth + 1);
if ($this->outputMode == self::OUTPUT_MULTIPLE_LINE) {
$output .= self::LINE_FEED . str_repeat($this->indentation, $this->arrayDepth);
}
$output .= ')';
break;
Expand Down
2 changes: 1 addition & 1 deletion tests/ZendTest/Code/Generator/PropertyGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function testPropertyMultilineValue()
'null' => null,
'true' => true,
'bar\'s' => 'bar\'s'
);
);
EOS;

$property = new PropertyGenerator('myFoo', $targetValue);
Expand Down
16 changes: 11 additions & 5 deletions tests/ZendTest/Code/Generator/ValueGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,15 @@ public function testPropertyDefaultValueCanHandleStrings()

public function testPropertyDefaultValueCanHandleArray()
{
$expectedSource = <<<EOS
array(
'foo'
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case the close parenthesis should not be indented

EOS;

$valueGenerator = new ValueGenerator();
$valueGenerator->setValue(array('foo'));
$this->assertEquals('array(\'foo\')', $valueGenerator->generate());
$this->assertEquals($expectedSource, $valueGenerator->generate());
}

public function testPropertyDefaultValueCanHandleUnquotedString()
Expand Down Expand Up @@ -95,10 +101,10 @@ public function testPropertyDefaultValueCanHandleComplexArrayOfTypes()
'baz1',
'baz2',
'constant2' => ArrayObject::STD_PROP_LIST
)
),
)
),
PHP_EOL
)
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what you interpreted. Any of that examples shows the close parenthesis indented. Instead they are aligned to the first non white character in the line.

PD: Some parts of that article are outdated and don't follow PSR-2

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't get it. So your are saying, that this code block is not following the ZF2 standards?

array(
    'controllers' => array(
        'invokables' => array(
            'Event\Controller\IndexController' => 'Event\Controller\IndexController',
            'Event\Controller\ShopController' => 'Event\Controller\ShopController',
        )
    ),
    'view_manager' => array(
        'template_path_stack' => array(
            __DIR__ . '/../view'
        )
    )
)

If not, how should it look like?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RalfEggert Could you take a look from <<<EOS up to EOS; and tell me if the first level of the array is really how you expect?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Maks3w Yes, the result of the ValueGeneratorTest::testPropertyDefaultValueCanHandleArrayWithUnsortedKeys() runs as expected, since the ArrayDepth is set to 1 as default.

array(
        1 => 'a',
        0 => 'b',
        'c',
        7 => 'd',
        3 => 'e'
    )

If it would be set to 0, I would expect:

array(
    1 => 'a',
    0 => 'b',
    'c',
    7 => 'd',
    3 => 'e'
)

EOS;

$valueGenerator = new ValueGenerator();
Expand Down Expand Up @@ -127,7 +133,7 @@ public function testPropertyDefaultValueCanHandleArrayWithUnsortedKeys()
'c',
7 => 'd',
3 => 'e'
)
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

EOS;

$this->assertEquals($expectedSource, $valueGenerator->generate());
Expand Down