composer.json脚本,returns'event returned with error code 2',为什么?

composer.json script, returns 'event returned with error code 2', why?

我在研究作曲家,在创建这个脚本时,它returns 'event returned with error code 2',但它不会阻止执行,当我 运行 直接没有作曲家它也可以,而且它没有给出这个错误,我想知道为什么会出现这个错误以及如何解决它。谢谢。

 //src

 <?php

    echo 'hello world';

 ?>

//composer.json
    "require-dev": {
        "phpunit/phpunit": "^9.5",
        "squizlabs/php_codesniffer": "^3.6",
        "phan/phan": "^5.3"
    },
    "scripts": {
        "cs" : "phpcs --standard=PSR12 src/"
    },


//running

PS D:\xamp\htdocs\fonts\ambiente\buscador-cursos-alura> composer cs       
> phpcs --standard=PSR12 src/

FILE: ...:\xamp\htdocs\fonts\ambiente\buscador-cursos-alura\src\teste.php
----------------------------------------------------------------------
FOUND 3 ERRORS AFFECTING 2 LINES
----------------------------------------------------------------------
 1 | ERROR | [x] End of line character is invalid; expected "\n" but
   |       |     found "\r\n"
 5 | ERROR | [x] Expected 1 newline at end of file; 0 found
 5 | ERROR | [x] A closing tag is not permitted at the end of a PHP
   |       |     file
----------------------------------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Time: 102ms; Memory: 8MB

Script phpcs --standard=PSR12 src/ handling the cs event returned with error code 2

第一次警告

End of line character is invalid; expected "\n" but found "\r\n"

您的行结尾必须是 LF 而不是 CRLF,这里的 an article 解释了区别。如果您使用 VSCode 那么您可以更改以右下角结尾的行,默认情况下它使用 CRLF。如果您不使用 VSCode,那么您将需要 Google 如何更改 IDE.

的行尾

第二次警告

Expected 1 newline at end of file; 0 found

PSR12 编码标准要求您的 PHP 文件末尾有一个空行。

第三次警告

A closing tag is not permitted at the end of a PHP file

PSR12 编码标准规定应省略文件末尾的 PHP 结束标记。

<?php
    echo 'hello world';