Giter Site home page Giter Site logo

Comments (5)

dg avatar dg commented on June 8, 2024 2

Since PHP 7 is no longer supported, I don't want to add support for it which would complicate the code.

I think it will be sufficient to remove the commas with a regular expression, something like preg_replace('~,(\n\t*\))~', '$1', $s)

from php-generator.

dg avatar dg commented on June 8, 2024 1

But please do it in your own Printer, I don't want to merge this into the code, because PHP 7 is outdated.

from php-generator.

klkvsk avatar klkvsk commented on June 8, 2024

Added a flag in Printer.

But the other case is when parameters are printed within a function call:

$method = new \Nette\PhpGenerator\Method('foo');
$method->addBody('return bar(...?);', [[
    '1234567890-1234567890-1234567890-1234567890',
    '1234567890-1234567890-1234567890-1234567890',
    '1234567890-1234567890-1234567890-1234567890',
]]);

$printer = new \Nette\PhpGenerator\Printer();
echo $printer->printMethod($method);

Output:

function foo()
{
        return bar(
                '1234567890-1234567890-1234567890-1234567890',
                '1234567890-1234567890-1234567890-1234567890',
                '1234567890-1234567890-1234567890-1234567890',
        );
}

This output is done by Dumper (Dumper::dumpArguments). Sure we can pass the flag from Printer to Dumper as done with indentation and wrapLength properties. But, as I see, it's not always being passed. Like in FunctionLike::addBody there's just a new instance of Dumper created without configuration.

Not sure what's the best way to deal with that without global refactoring. Any ideas besides implementing some kind of DumperFactory stuff?

from php-generator.

klkvsk avatar klkvsk commented on June 8, 2024

I just noticed that rendered bodies are passed through Printer::indent, where it converts the indentation where needed.
Putting said preg_replace there as the most non-invasive fix.

from php-generator.

nevmerzhitsky avatar nevmerzhitsky commented on June 8, 2024

Issues like this (remove or add the comma) may be solved by an additional call of tools like "PHP Coding Standards Fixer" which changes code style, imho.

from php-generator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.