Skip to content

Commit 20ee99f

Browse files
committed
Update .php handling to keep <?php at the top
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.
1 parent 3db4982 commit 20ee99f

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

main.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func licenseHeader(path string, tmpl *template.Template, data *copyrightData) ([
222222
case ".html", ".xml":
223223
lic, err = prefix(tmpl, data, "<!--", " ", "-->")
224224
case ".php":
225-
lic, err = prefix(tmpl, data, "<?php", "// ", "?>")
225+
lic, err = prefix(tmpl, data, "", "// ", "")
226226
case ".ml", ".mli", ".mll", ".mly":
227227
lic, err = prefix(tmpl, data, "(**", " ", "*)")
228228
}
@@ -242,6 +242,7 @@ var head = []string{
242242
"<!doctype", // HTML doctype
243243
"# encoding:", // Ruby encoding
244244
"# frozen_string_literal:", // Ruby interpreter instruction
245+
"<?php", // PHP opening tag
245246
}
246247

247248
func hashBang(b []byte) []byte {

testdata/expected/file.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
// See the License for the specific language governing permissions and
1414
// limitations under the License.
15-
?>
1615

17-
<?php phpinfo(); ?>
16+
namespace App;
17+
phpinfo();

testdata/initial/file.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
<?php phpinfo(); ?>
1+
<?php
2+
namespace App;
3+
phpinfo();

0 commit comments

Comments
 (0)