Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong wrapping condition in array formater #45

Closed
zeleznypa opened this issue Jun 21, 2019 · 3 comments · Fixed by #47
Closed

Wrong wrapping condition in array formater #45

zeleznypa opened this issue Jun 21, 2019 · 3 comments · Fixed by #47

Comments

@zeleznypa
Copy link
Contributor

@zeleznypa zeleznypa commented Jun 21, 2019

Version: 3.2.*

Bug Description

Wrapping condition ignore the length of the property name and needed characters $ = []
https://github.com/nette/php-generator/blob/master/src/PhpGenerator/Helpers.php#L97

Steps To Reproduce

Actual generator produce code:

    /** @var int[] */
    public $terminalsValues = ['true' => 3, 'false' => 4, 'null' => 5, '{' => 6, '}' => 7, ',' => 8, ':' => 9, '[' => 10, ']' => 11];

Expected Behavior

Generate code:

    /** @var int[] */
    public $terminalsValues = [
        'true' => 3, 
        'false' => 4, 
        'null' => 5, 
        '{' => 6, 
        '}' => 7, 
        ',' => 8, 
        ':' => 9, 
        '[' => 10, 
        ']' => 11
    ];

Possible Solution

Add possibility to modify Helper::WRAP_LENGTH by custom length that will be filled here by str_len($property->getName()) + 6

@ttomdewit

This comment has been minimized.

Copy link

@ttomdewit ttomdewit commented Jul 16, 2019

This would be very neat, indeed. Hopefully this’ll get implemented.

@ttomdewit

This comment has been minimized.

Copy link

@ttomdewit ttomdewit commented Jul 18, 2019

Having changed \Nette\PhpGenerator\Helpers::WRAP_LENGTH to, for example, 10, allowed to me to create the following array:

/**
 * The attributes that should be mutated to dates.
 *
 * @var array $dates
 */
public $dates = [
    self::CREATED_AT,
    self::UPDATED_AT,
];

What normally happens is the following:

/**
 * The attributes that should be mutated to dates.
 *
 * @var array $dates
 */
public $dates = [self::CREATED_AT, self::UPDATED_AT];

I personally prefer the former over the latter and I'd like to be able to configure this setting.

Thanks for your time!

Tom

@ttomdewit

This comment has been minimized.

Copy link

@ttomdewit ttomdewit commented Nov 19, 2019

Thank you!

dg added a commit that referenced this issue Nov 19, 2019
dg added a commit that referenced this issue Nov 19, 2019
dg added a commit that referenced this issue Nov 19, 2019
dg added a commit that referenced this issue Nov 19, 2019
dg added a commit that referenced this issue Nov 19, 2019
dg added a commit that referenced this issue Nov 20, 2019
dg added a commit that referenced this issue Nov 20, 2019
dg added a commit that referenced this issue Nov 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.