Skip to content

Commit

Permalink
Dumper: default $wrapLength changed to 120
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Nov 20, 2019
1 parent fee9c6c commit 758077b
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/PhpGenerator/Dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class Dumper
public $maxDepth = 50;

/** @var int */
public $wrapLength = 100;
public $wrapLength = 120;


/**
Expand Down
12 changes: 9 additions & 3 deletions tests/PhpGenerator/Closure.long.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require __DIR__ . '/../bootstrap.php';
$function = new Closure;
$function->setBody('return null;');

for ($name = 'abcde'; $name < 'abcdr'; $name++) {
for ($name = 'abcde'; $name < 'abcdu'; $name++) {
$function->addParameter($name);
$function->addUse($name);
}
Expand All @@ -30,7 +30,10 @@ same(
$abcdn,
$abcdo,
$abcdp,
$abcdq
$abcdq,
$abcdr,
$abcds,
$abcdt
) use (
$abcde,
$abcdf,
Expand All @@ -44,7 +47,10 @@ same(
$abcdn,
$abcdo,
$abcdp,
$abcdq
$abcdq,
$abcdr,
$abcds,
$abcdt
) {
return null;
}', (string) $function);
3 changes: 3 additions & 0 deletions tests/PhpGenerator/Dumper.dump().phpt
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ Assert::same('[$s]', $dumper->dump([new PhpLiteral('$s')]));

Assert::same('[1, 2, 3]', $dumper->dump([1, 2, 3]));
Assert::same("['a', 7 => 'b', 'c', '9a' => 'd', 'e']", $dumper->dump(['a', 7 => 'b', 'c', '9a' => 'd', 9 => 'e']));

$dumper->wrapLength = 100;
same("[
[
'a',
'loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong',
],
]", $dumper->dump([['a', 'loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong']]));

Assert::same("['a' => 1, [\"\\r\" => \"\\r\", 2], 3]", $dumper->dump(['a' => 1, ["\r" => "\r", 2], 3]));

Assert::same("(object) [\n\t'a' => 1,\n\t'b' => 2,\n]", $dumper->dump((object) ['a' => 1, 'b' => 2]));
Expand Down
2 changes: 2 additions & 0 deletions tests/PhpGenerator/Dumper.format().phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Assert::same('func(1 ? 2 : 3)', $dumper->format('func(1 \? 2 : 3)'));
Assert::same('func([1, 2])', $dumper->format('func(?)', [1, 2]));
Assert::same('func(1, 2)', $dumper->format('func(...?)', [1, 2]));
Assert::same('func(1, 2)', $dumper->format('func(?*)', [1, 2])); // old way

$dumper->wrapLength = 100;
same(
'func(
10,
Expand Down
10 changes: 5 additions & 5 deletions tests/PhpGenerator/Printer.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ $class->addConstant('FORCE_ARRAY', new PhpLiteral('Nette\Utils\Json::FORCE_ARRAY
->setVisibility('private')
->addComment('Commented');

$class->addConstant('MULTILINE_LONG', ['aaaaaaa' => 1, 'bbbbbbb' => 2, 'ccccccc' => 3, 'ddddddd' => 4, 'eeeeee' => 5]);
$class->addConstant('SHORT', ['aaaaaaa' => 1, 'bbbbbbb' => 2, 'ccccccc' => 3, 'ddddddd' => 4, 'eeeeee' => 5]);
$class->addConstant('MULTILINE_LONG', ['aaaaaaaa' => 1, 'bbbbbbbb' => 2, 'cccccccc' => 3, 'dddddddd' => 4, 'eeeeeeee' => 5, 'ffffffff' => 6]);
$class->addConstant('SHORT', ['aaaaaaaa' => 1, 'bbbbbbbb' => 2, 'cccccccc' => 3, 'dddddddd' => 4, 'eeeeeeee' => 5, 'ffffffff' => 6]);

$class->addProperty('handle')
->setVisibility('private')
Expand All @@ -36,14 +36,14 @@ $class->addProperty('handle')
$class->addProperty('order')
->setValue(new PhpLiteral('RecursiveIteratorIterator::SELF_FIRST'));

$class->addProperty('multilineLong', ['aaaaaaa' => 1, 'bbbbbbb' => 2, 'ccccccc' => 3, 'ddddddd' => 4, 'eeeeee' => 5]);
$class->addProperty('short', ['aaaaaaa' => 1, 'bbbbbbb' => 2, 'ccccccc' => 3, 'ddddddd' => 4, 'eeeeee' => 5]);
$class->addProperty('multilineLong', ['aaaaaaaa' => 1, 'bbbbbbbb' => 2, 'cccccccc' => 3, 'dddddddd' => 4, 'eeeeeeee' => 5, 'ffffffff' => 6]);
$class->addProperty('short', ['aaaaaaaa' => 1, 'bbbbbbbb' => 2, 'cccccccc' => 3, 'dddddddd' => 4, 'eeeeeeee' => 5, 'ffffffff' => 6]);

$class->addMethod('first')
->addComment('@return resource')
->setFinal(true)
->setReturnType('stdClass')
->setBody("func();\nreturn ?;", [['aaaaaaaaaaaa' => 1, 'bbbbbbbbbbb' => 2, 'cccccccccccccc' => 3, 'dddddddddddd' => 4, 'eeeeeeeeeeee' => 5]])
->setBody("func();\nreturn ?;", [['aaaaaaaaaaaa' => 1, 'bbbbbbbbbbb' => 2, 'cccccccccccccc' => 3, 'dddddddddddd' => 4, 'eeeeeeeeeeee' => 5, 'ffffffff' => 6]])
->addParameter('var')
->setType('stdClass');

Expand Down
10 changes: 5 additions & 5 deletions tests/PhpGenerator/PsrPrinter.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ $class->addConstant('FORCE_ARRAY', new PhpLiteral('Nette\Utils\Json::FORCE_ARRAY
->setVisibility('private')
->addComment('Commented');

$class->addConstant('MULTILINE_LONG', ['aaaaaaa' => 1, 'bbbbbbb' => 2, 'ccccccc' => 3, 'ddddddd' => 4, 'eeeeee' => 5]);
$class->addConstant('SHORT', ['aaaaaaa' => 1, 'bbbbbbb' => 2, 'ccccccc' => 3, 'ddddddd' => 4, 'eeeeee' => 5]);
$class->addConstant('MULTILINE_LONG', ['aaaaaaaa' => 1, 'bbbbbbbb' => 2, 'cccccccc' => 3, 'dddddddd' => 4, 'eeeeeeee' => 5, 'ffffffff' => 6]);
$class->addConstant('SHORT', ['aaaaaaaa' => 1, 'bbbbbbbb' => 2, 'cccccccc' => 3, 'dddddddd' => 4, 'eeeeeeee' => 5, 'ffffffff' => 6]);

$class->addProperty('handle')
->setVisibility('private')
Expand All @@ -35,14 +35,14 @@ $class->addProperty('handle')
$class->addProperty('order')
->setValue(new PhpLiteral('RecursiveIteratorIterator::SELF_FIRST'));

$class->addProperty('multilineLong', ['aaaaaaa' => 1, 'bbbbbbb' => 2, 'ccccccc' => 3, 'ddddddd' => 4, 'eeeeee' => 5]);
$class->addProperty('short', ['aaaaaaa' => 1, 'bbbbbbb' => 2, 'ccccccc' => 3, 'ddddddd' => 4, 'eeeeee' => 5]);
$class->addProperty('multilineLong', ['aaaaaaaa' => 1, 'bbbbbbbb' => 2, 'cccccccc' => 3, 'dddddddd' => 4, 'eeeeeeee' => 5, 'ffffffff' => 6]);
$class->addProperty('short', ['aaaaaaaa' => 1, 'bbbbbbbb' => 2, 'cccccccc' => 3, 'dddddddd' => 4, 'eeeeeeee' => 5, 'ffffffff' => 6]);

$class->addMethod('first')
->addComment('@return resource')
->setFinal(true)
->setReturnType('stdClass')
->setBody("func();\nreturn ?;", [['aaaaaaaaaaaa' => 1, 'bbbbbbbbbbb' => 2, 'cccccccccccccc' => 3, 'dddddddddddd' => 4, 'eeeeeeeeeeee' => 5]])
->setBody("func();\nreturn ?;", [['aaaaaaaaaaaa' => 1, 'bbbbbbbbbbb' => 2, 'cccccccccccccc' => 3, 'dddddddddddd' => 4, 'eeeeeeeeeeee' => 5, 'ffffffff' => 6]])
->addParameter('var')
->setType('stdClass');

Expand Down
27 changes: 15 additions & 12 deletions tests/PhpGenerator/expected/Printer.class.expect
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,30 @@ final class Example extends ParentClass implements IExample
/** Commented */
private const FORCE_ARRAY = Nette\Utils\Json::FORCE_ARRAY;
const MULTILINE_LONG = [
'aaaaaaa' => 1,
'bbbbbbb' => 2,
'ccccccc' => 3,
'ddddddd' => 4,
'eeeeee' => 5,
'aaaaaaaa' => 1,
'bbbbbbbb' => 2,
'cccccccc' => 3,
'dddddddd' => 4,
'eeeeeeee' => 5,
'ffffffff' => 6,
];
const SHORT = ['aaaaaaa' => 1, 'bbbbbbb' => 2, 'ccccccc' => 3, 'ddddddd' => 4, 'eeeeee' => 5];
const SHORT = ['aaaaaaaa' => 1, 'bbbbbbbb' => 2, 'cccccccc' => 3, 'dddddddd' => 4, 'eeeeeeee' => 5, 'ffffffff' => 6];

/** @var resource orignal file handle */
private $handle;

public $order = RecursiveIteratorIterator::SELF_FIRST;

public $multilineLong = [
'aaaaaaa' => 1,
'bbbbbbb' => 2,
'ccccccc' => 3,
'ddddddd' => 4,
'eeeeee' => 5,
'aaaaaaaa' => 1,
'bbbbbbbb' => 2,
'cccccccc' => 3,
'dddddddd' => 4,
'eeeeeeee' => 5,
'ffffffff' => 6,
];

public $short = ['aaaaaaa' => 1, 'bbbbbbb' => 2, 'ccccccc' => 3, 'ddddddd' => 4, 'eeeeee' => 5];
public $short = ['aaaaaaaa' => 1, 'bbbbbbbb' => 2, 'cccccccc' => 3, 'dddddddd' => 4, 'eeeeeeee' => 5, 'ffffffff' => 6];


/**
Expand All @@ -48,6 +50,7 @@ final class Example extends ParentClass implements IExample
'cccccccccccccc' => 3,
'dddddddddddd' => 4,
'eeeeeeeeeeee' => 5,
'ffffffff' => 6,
];
}

Expand Down
1 change: 1 addition & 0 deletions tests/PhpGenerator/expected/Printer.method.expect
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ final public function first(stdClass $var): stdClass
'cccccccccccccc' => 3,
'dddddddddddd' => 4,
'eeeeeeeeeeee' => 5,
'ffffffff' => 6,
];
}
27 changes: 15 additions & 12 deletions tests/PhpGenerator/expected/PsrPrinter.class.expect
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,30 @@ final class Example extends ParentClass implements IExample
/** Commented */
private const FORCE_ARRAY = Nette\Utils\Json::FORCE_ARRAY;
const MULTILINE_LONG = [
'aaaaaaa' => 1,
'bbbbbbb' => 2,
'ccccccc' => 3,
'ddddddd' => 4,
'eeeeee' => 5,
'aaaaaaaa' => 1,
'bbbbbbbb' => 2,
'cccccccc' => 3,
'dddddddd' => 4,
'eeeeeeee' => 5,
'ffffffff' => 6,
];
const SHORT = ['aaaaaaa' => 1, 'bbbbbbb' => 2, 'ccccccc' => 3, 'ddddddd' => 4, 'eeeeee' => 5];
const SHORT = ['aaaaaaaa' => 1, 'bbbbbbbb' => 2, 'cccccccc' => 3, 'dddddddd' => 4, 'eeeeeeee' => 5, 'ffffffff' => 6];

/** @var resource orignal file handle */
private $handle;

public $order = RecursiveIteratorIterator::SELF_FIRST;

public $multilineLong = [
'aaaaaaa' => 1,
'bbbbbbb' => 2,
'ccccccc' => 3,
'ddddddd' => 4,
'eeeeee' => 5,
'aaaaaaaa' => 1,
'bbbbbbbb' => 2,
'cccccccc' => 3,
'dddddddd' => 4,
'eeeeeeee' => 5,
'ffffffff' => 6,
];

public $short = ['aaaaaaa' => 1, 'bbbbbbb' => 2, 'ccccccc' => 3, 'ddddddd' => 4, 'eeeeee' => 5];
public $short = ['aaaaaaaa' => 1, 'bbbbbbbb' => 2, 'cccccccc' => 3, 'dddddddd' => 4, 'eeeeeeee' => 5, 'ffffffff' => 6];

/**
* @return resource
Expand All @@ -47,6 +49,7 @@ final class Example extends ParentClass implements IExample
'cccccccccccccc' => 3,
'dddddddddddd' => 4,
'eeeeeeeeeeee' => 5,
'ffffffff' => 6,
];
}

Expand Down

0 comments on commit 758077b

Please sign in to comment.