Skip to content

Commit

Permalink
Update .php handling to keep <?php at the top
Browse files Browse the repository at this point in the history
Looking at https://www.php.net/manual/en/language.basic-syntax.phptags.php
there are just too many variations and I'm not convinced the added
complexity to support all of them would be worth it here.

Thus, support only the case where closing tag "?>" is either omitted
or on a separate line. A workaround for all other cases is to add
the license header manually.

Can always revisit this later.
  • Loading branch information
x1ddos committed Feb 22, 2020
1 parent 3db4982 commit 20ee99f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func licenseHeader(path string, tmpl *template.Template, data *copyrightData) ([
case ".html", ".xml":
lic, err = prefix(tmpl, data, "<!--", " ", "-->")
case ".php":
lic, err = prefix(tmpl, data, "<?php", "// ", "?>")
lic, err = prefix(tmpl, data, "", "// ", "")
case ".ml", ".mli", ".mll", ".mly":
lic, err = prefix(tmpl, data, "(**", " ", "*)")
}
Expand All @@ -242,6 +242,7 @@ var head = []string{
"<!doctype", // HTML doctype
"# encoding:", // Ruby encoding
"# frozen_string_literal:", // Ruby interpreter instruction
"<?php", // PHP opening tag
}

func hashBang(b []byte) []byte {
Expand Down
4 changes: 2 additions & 2 deletions testdata/expected/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
?>

<?php phpinfo(); ?>
namespace App;
phpinfo();
4 changes: 3 additions & 1 deletion testdata/initial/file.php
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
<?php phpinfo(); ?>
<?php
namespace App;
phpinfo();

0 comments on commit 20ee99f

Please sign in to comment.