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

optimize: use multiline comments for PHP files #3

Merged
merged 1 commit into from
Oct 24, 2024

Conversation

clemlatz
Copy link
Contributor

@clemlatz clemlatz commented Oct 24, 2024

What type of PR is this?

optimize: A new optimization

Check the PR title.

  • This PR title match the format: <type>(optional scope): <description>
  • The description of this PR title is user-oriented and clear enough for others to understand.

(Optional) More detail description for this PR.

I'd like to propose to use multiline comments for license headers in PHP files

/*
 * …
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published
 * by the Free Software Foundation, version 3.
 * …
 */

instead of single line comments

// …
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, version 3.
// …

This a more common practice as can be seen in Symfony, one of the mostly used PHP frameworks:
https://github.com/symfony/http-foundation/blob/3d7bbf071b25f802f7d55524d408bed414ea71e2/Response.php#L1-12

@clemlatz clemlatz changed the title feat: use multiline comments for PHP files optimize: use multiline comments for PHP files Oct 24, 2024
@justlorain
Copy link
Member

justlorain commented Oct 24, 2024

Thank you again for your contribution!

By the way, NWA supports the --rawtmpl (-r) option, where you can specify a file path for a template.
NWA will read the content from this template file and add (or check, update, delete) it directly to the header of the file where a license header is needed. This option is suitable for users who have more advanced requirements for the license header.

For example, suppose you have created a nwatmpl.txt file in the current directory, then you can use this custom template with the following command:

nwa add -r nwatmpl.txt *.php

The content of nwatmpl.txt might look like this:


/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */
 

You may notice that both the first and last lines of nwatmpl.txt are blank. This is how you can achieve a format similar to Symfony's.

<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

...

If you use NWA's built-in template to add the license header, NWA’s default behavior is to place the license header directly after <?php, resulting in something like this:

<?php
/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <[email protected]>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

...

So comparatively, --rawtmpl offers more flexibility. I will add documentation on this later.

@justlorain justlorain merged commit 9fca974 into B1NARY-GR0UP:main Oct 24, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants