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

[Question] defining used PHP version #1575

Closed
mimmi20 opened this issue Jul 2, 2022 · 7 comments
Closed

[Question] defining used PHP version #1575

mimmi20 opened this issue Jul 2, 2022 · 7 comments
Labels
question Further information is requested

Comments

@mimmi20
Copy link

mimmi20 commented Jul 2, 2022

I am started using the megalinter when upgrading my projects to PHP 8.1.

In one project I got this error:

### Processed [PHP] files
- Using [php v7.4.26] https://megalinter.github.io/v5/descriptors/php_php
- MegaLinter key: [PHP_BUILTIN]
- Rules config: identified by [php]
[php] .php-cs-fixer.php - SUCCESS - 0 error(s)
[php] src/StreamFormatter.php - SUCCESS - 0 error(s)
[php] tests/StreamFormatterTest.php - ERROR - 1 error(s)
--Error detail:
PHP Parse error:  syntax error, unexpected ':', expecting ')' in /github/workspace/tests/StreamFormatterTest.php on line 242
Errors parsing /github/workspace/tests/StreamFormatterTest.php
❌ Linted [PHP] files with [php]: Found 1 error(s) - (0.05s)
[Text Reporter] Generated TEXT report: /github/workspace/report/linters_logs/ERROR-PHP_BUILTIN.log
### Processed [PHP] files
- Using [phplint v3.0] https://megalinter.github.io/v5/descriptors/php_phplint
- MegaLinter key: [PHP_PHPLINT]
- Rules config: [/github/workspace/.phplint.yml]
[phplint] .php-cs-fixer.php
[phplint] src/StreamFormatter.php
[phplint] tests/StreamFormatterTest.php
--Error detail:
phplint 3.0 by overtrue and contributors.
Loaded config from "/github/workspace/.phplint.yml"
.E.
Time: < 1 sec	Memory: 2.0 MiB	Cache: No
FAILURES!
Files: 3, Failures: 1
There was 1 errors:
1. /github/workspace/tests/StreamFormatterTest.php:242
    239|         $formatter = new StreamFormatter();
    240| 
    241|         $record = new LogRecord(
  > 242|             datetime: $datetime,
    243|             channel: $channel,
    244|             level: \Monolog\Level::Error,
    245|             message: $message,
 unexpected ':', expecting ')' in line 242
❌ Linted [PHP] files with [phplint]: Found 1 error(s) - (0.08s)

The linter uses PHP 7.4, but the code is written for PHP 8.1.

Is there any option to define the PHP version used by the linter?

@mimmi20 mimmi20 added the question Further information is requested label Jul 2, 2022
@Kurt-von-Laven
Copy link
Collaborator

@mimmi20, I have no relevant experience with PHP, but I think the short answer is no. Most likely, your best bet would be to disable phplint, and run it outside of MegaLinter. You can achieve that by adding the following to your MegaLinter config:

DISABLE_LINTERS:
  - PHP_PHPLINT

MegaLinter v6 will be released soon, but most likely without support for running phplint on PHP 8 unfortunately. My understanding is that there were some issues that are making upgrading difficult right now, although @llaville may correct me if I misunderstood.

@llaville
Copy link
Collaborator

llaville commented Jul 3, 2022

@Kurt-von-Laven I'm away from my Laptop, but yes there is a solution to switch PHP version runtime used.
I'll give the solution when I'll be back in few hours

@llaville
Copy link
Collaborator

llaville commented Jul 3, 2022

@Kurt-von-Laven and @mimmi20 PHP switch capability was introduced in MegaLinter since version 5.3 with #1083

All you have to do is to use the PRE_COMMAND syntax on PHP_PHPLINT like that :

Remember that in MegaLinter v5.x, default PHP BUILTIN linter version is PHP 7 (7.4.x)

PHP_PHPLINT_PRE_COMMANDS:
    - command: "update-alternatives --set php /usr/bin/php8"
      cwd: root

NOTE: PHPLint 3.0 is compatible PHP 7.4 and 8.0 (until we use composer built-in with a PHP 7 version)

@llaville
Copy link
Collaborator

llaville commented Jul 3, 2022

You should see in MegaLinter logs something like

[Pre][PHP_PHPLINT] run: [update-alternatives --set php /usr/bin/php8] in cwd [/]
[Pre][PHP_PHPLINT] [update-alternatives: using /usr/bin/php8 to provide /usr/bin/php (php) in manual mode
] update-alternatives: using /usr/bin/php8 to provide /usr/bin/php (php) in manual mode


### Processed [PHP] files
- Using [phplint v3.0] https://megalinter.github.io/v5/descriptors/php_phplint
- MegaLinter key: [PHP_PHPLINT]
- Rules config: [.phplint.yml]
- Number of files analyzed: [39]
✅ Linted [PHP] files with [phplint] successfully - (0.22s)

@mimmi20
Copy link
Author

mimmi20 commented Jul 3, 2022

@llaville Does this switch also exists for all other php related linters? As you may see in my sample, the PHP_BUILTIN linter has the same issue.

@llaville
Copy link
Collaborator

llaville commented Jul 3, 2022

yes it exist for all PHP linters

@mimmi20
Copy link
Author

mimmi20 commented Jul 9, 2022

I have decided to not change my config file, to disable the php checks for megalinter and run these checks in seperate tasks.

@mimmi20 mimmi20 closed this as completed Jul 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants