Composer.json Script, Returns 'event Returned With Error Code 2', Why?
I was studying composer, and when creating this script, it returns 'event returned with error code 2', but it doesn't prevent execution, when I run it directly without composer it also works, and it doesn't give this error, I would like to know why this error occurs and how to resolve it. Thanks.
//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
Answer
First Warning
End of line character is invalid; expected "\n" but found "\r\n"
Your line endings need to be LF and not CRLF, here's an article which explains the difference. If you're using VSCode then you can change the line ending in the bottom right where it uses CRLF by default. If you're not using VSCode then you will need to Google how to change the line endings for your IDE.
Second Warning
Expected 1 newline at end of file; 0 found
PSR12 coding standards require an empty line at the end of your PHP files.
Third Warning
A closing tag is not permitted at the end of a PHP file
PSR12 coding standards state that closing PHP tags at the end of the file should be omitted.
<?php
echo 'hello world';
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?