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

PHP 8.3 + 8.4 to master branch #151

Merged
merged 23 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8acc3cf
GH Actions: update PHP versions in workflows
jrfnl Dec 9, 2022
99b3a65
GH Actions: update for the release of PHP 8.3
jrfnl Nov 23, 2023
6038dcf
Allow version check in application entry file to work
jrfnl Feb 20, 2022
dd1ea0b
Make the version check more informative
jrfnl Jun 8, 2021
da3ea49
GH Actions: version update for various predefined actions
jrfnl Mar 5, 2022
5a4d8eb
SyntaxError::translateTokens(): prevent double translation
jrfnl Feb 20, 2022
edfe819
SyntaxError::getNormalizedMessage(): bug fix - file name containing r…
jrfnl Feb 20, 2022
b8d515c
SyntaxError::getNormalizedMessage(): bug fix - "in file on line" does…
jrfnl Feb 20, 2022
d054056
Fix typos
krsriq Aug 20, 2022
9256c44
GH Actions: fix download URL for box
jrfnl Apr 5, 2022
a528a8a
GH Actions: harden the workflow against PHPCS ruleset errors
jrfnl Oct 23, 2022
4d0a65a
GH Actions: update PHP versions in workflows
jrfnl Dec 9, 2022
96095f0
GH Actions: bust the cache semi-regularly
jrfnl Nov 4, 2022
3bc9df2
GH Actions: use `fail-fast` with setup-php when creating the binaries
jrfnl Dec 11, 2022
c7efb9a
GH Actions: fix up fail-fast for setup-php
jrfnl Dec 20, 2022
3d01e89
Align the percentage output
jrfnl Mar 16, 2024
7212796
Composer: update keywords
jrfnl Mar 16, 2024
222c1d0
Skip shebang sequence if it is the first line
xaben Aug 8, 2023
1d39ab1
[PHP 8.4] Fixes for implicit nullability deprecation
Ayesh Mar 15, 2024
b9df728
Make PHP 8.4 implicit nullability fix compatible with PHP < 7.1
jrfnl Mar 16, 2024
a28efcc
OutputTest: fix risky test
jrfnl Mar 16, 2024
c18e8ad
GH Actions: version update for various predefined actions
jrfnl Mar 16, 2024
c3b494c
GH Actions: fix duplicate release
jrfnl Mar 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 17 additions & 19 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -34,35 +34,39 @@ jobs:
ini-values: phar.readonly=Off, error_reporting=-1, display_errors=On, zend.assertions=1
# Autoload files generated with Composer 2.3 are not compatible with PHP < 7.0.
tools: composer:2.2
env:
fail-fast: true

- name: Install Composer dependencies
uses: ramsey/composer-install@v2
uses: ramsey/composer-install@v3
with:
composer-options: "--no-dev"
# Bust the cache at least once a month - output format: YYYY-MM.
custom-cache-suffix: $(date -u "+%Y-%m")

# Note: do NOT turn on the requirement checker in the box config as it is no longer
# compatible with PHP < 7.2.
- name: Install Box
run: wget https://github.com/humbug/box/releases/latest/download/box.phar -O box.phar && chmod 0755 box.phar && pwd
run: wget https://github.com/box-project/box/releases/latest/download/box.phar -O box.phar && chmod 0755 box.phar && pwd

- name: Validate configuration
run: php box.phar validate -i box.json

- name: Building binary...
run: php box.phar compile -v --config=box.json

- name: Show info about the build phar with humbug/box
- name: Show info about the build phar with box-project/box
run: php box.phar info -l parallel-lint.phar

- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
with:
name: parallel-lint-phar
path: ./parallel-lint.phar

verify:
name: Validate binary on PHP ${{ matrix.php }}
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.php == '8.2' }}
continue-on-error: ${{ matrix.php == '8.3' }}
needs:
- bundle

Expand All @@ -81,12 +85,13 @@ jobs:
- '8.0'
- '8.1'
- '8.2'
- '8.3'

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- uses: actions/download-artifact@v2
- uses: actions/download-artifact@v4
with:
name: parallel-lint-phar

Expand All @@ -108,24 +113,17 @@ jobs:
- verify

steps:
- uses: actions/download-artifact@v2
- uses: actions/download-artifact@v4
with:
name: parallel-lint-phar

- name: Draft Release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: true
prerelease: false

- name: Upload Phar as Release Asset
id: upload-release-asset
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
make_latest: true
files: parallel-lint.phar
fail_on_unmatched_files: true
47 changes: 34 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,25 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: 'latest'
coverage: none
tools: cs2pr

- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Install Composer dependencies
uses: ramsey/composer-install@v2
uses: ramsey/composer-install@v3
with:
# Bust the cache at least once a month - output format: YYYY-MM.
custom-cache-suffix: $(date -u "+%Y-%m")

- name: Run code sniffer
continue-on-error: true
id: phpcs
run: vendor/bin/phpcs --report-full --report-checkstyle=./phpcs-report.xml

- name: Show PHPCS results in PR
if: ${{ always() && steps.phpcs.outcome == 'failure' }}
run: cs2pr ./phpcs-report.xml

bundle:
Expand All @@ -46,7 +50,7 @@ jobs:

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -57,35 +61,39 @@ jobs:
ini-values: phar.readonly=Off, error_reporting=-1, display_errors=On, zend.assertions=1
# Autoload files generated with Composer 2.3 are not compatible with PHP < 7.0.
tools: composer:2.2
env:
fail-fast: true

- name: Install Composer dependencies
uses: ramsey/composer-install@v2
uses: ramsey/composer-install@v3
with:
composer-options: "--no-dev"
# Bust the cache at least once a month - output format: YYYY-MM.
custom-cache-suffix: $(date -u "+%Y-%m")

# Note: do NOT turn on the requirement checker in the box config as it is no longer
# compatible with PHP < 7.2.
- name: Install Box
run: wget https://github.com/humbug/box/releases/latest/download/box.phar -O box.phar && chmod 0755 box.phar && pwd
run: wget https://github.com/box-project/box/releases/latest/download/box.phar -O box.phar && chmod 0755 box.phar && pwd

- name: Validate configuration
run: php box.phar validate -i box.json

- name: Building binary...
run: php box.phar compile -v --config=box.json

- name: Show info about the build phar with humbug/box
- name: Show info about the build phar with box-project/box
run: php box.phar info -l parallel-lint.phar

- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
with:
name: parallel-lint-phar
path: ./parallel-lint.phar

test:
name: Run tests on PHP ${{ matrix.php }}
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.php == '8.2' }}
continue-on-error: ${{ matrix.php == '8.4' }}
needs:
- bundle

Expand All @@ -104,10 +112,12 @@ jobs:
- '8.0'
- '8.1'
- '8.2'
- '8.3'
- '8.4'

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -122,7 +132,18 @@ jobs:
run: composer remove --dev squizlabs/php_codesniffer --no-update --no-interaction

- name: Install Composer dependencies
uses: ramsey/composer-install@v2
if: ${{ matrix.php != '8.3' }}
uses: ramsey/composer-install@v3
with:
# Bust the cache at least once a month - output format: YYYY-MM.
custom-cache-suffix: $(date -u "+%Y-%m")

- name: "Install Composer dependencies (PHP 8.3, ignore PHP reqs)"
if: ${{ matrix.php == '8.3' }}
uses: ramsey/composer-install@v3
with:
composer-options: --ignore-platform-req=php
custom-cache-suffix: $(date -u "+%Y-%m")

- name: 'Integration test 1 - linting own code, no colors'
continue-on-error: true
Expand All @@ -139,7 +160,7 @@ jobs:
if: ${{ matrix.php >= 5.6 }}
run: composer test

- uses: actions/download-artifact@v2
- uses: actions/download-artifact@v4
with:
name: parallel-lint-phar

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Build Status](https://github.com/php-parallel-lint/PHP-Parallel-Lint/actions/workflows/test.yml/badge.svg)](https://github.com/php-parallel-lint/PHP-Parallel-Lint/actions/workflows/test.yml)
[![License](https://poser.pugx.org/php-parallel-lint/php-parallel-lint/license.svg)](https://packagist.org/packages/php-parallel-lint/php-parallel-lint)

This application checks syntax of PHP files in parallel.
This application checks the syntax of PHP files in parallel.
It can output in plain text, colored text, json and checksyntax formats.
Additionally `blame` can be used to show commits that introduced the breakage.

Expand Down Expand Up @@ -72,7 +72,7 @@ It is strongly recommended for existing users of the (unmaintained)
- `-a`, `--asp` Set asp_tags to On (default: Off).
- `-e <ext>` Check only files with selected extensions separated by comma. (default: php,php3,php4,php5,phtml,phpt)
- `-j <num>` Run <num> jobs in parallel (default: 10).
- `--exclude` Exclude a file or directory. If you want exclude multiple items, use multiple exclude parameters.
- `--exclude` Exclude a file or directory. If you want to exclude multiple items, use multiple exclude parameters.
- `--colors` Enable colors in console output. (disables auto detection of color support)
- `--no-colors` Disable colors in console output.
- `--no-progress` Disable progress in console output.
Expand Down Expand Up @@ -116,7 +116,7 @@ Note: The `// lint >= 7.4` comment has to be only the first line of the file and

## How to upgrade

Are you using `jakub-onderka/php-parallel-lint` package? You can switch to `php-parallel-lint/php-parallel-lint` using:
Are you using the `jakub-onderka/php-parallel-lint` package? You can switch to `php-parallel-lint/php-parallel-lint` using:

composer remove --dev jakub-onderka/php-parallel-lint
composer require --dev php-parallel-lint/php-parallel-lint
6 changes: 6 additions & 0 deletions bin/skip-linting.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
$f = @fopen($file, 'r');
if ($f) {
$firstLine = fgets($f);

// ignore shebang line
if (strpos($firstLine, '#!') === 0) {
$firstLine = fgets($f);
}

@fclose($f);

if (preg_match('~<?php\\s*\\/\\/\s*lint\s*([^\d\s]+)\s*([^\s]+)\s*~i', $firstLine, $m)) {
Expand Down
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
"description": "This tool checks the syntax of PHP files about 20x faster than serial check.",
"homepage": "https://github.com/php-parallel-lint/PHP-Parallel-Lint",
"license": "BSD-2-Clause",
"keywords": [
"lint",
"static analysis"
],
"authors": [
{
"name": "Jakub Onderka",
Expand Down
14 changes: 12 additions & 2 deletions parallel-lint
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ either expressed or implied, of the FreeBSD Project.
*/

if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50300) {
fwrite(STDERR, "PHP Parallel Lint requires PHP 5.3.0 or newer." . PHP_EOL);
fwrite(
STDERR,
sprintf(
'PHP Parallel Lint requires PHP 5.3.0 or newer.' . PHP_EOL
. 'You are using PHP %s (%s).' . PHP_EOL,
PHP_VERSION,
PHP_BINDIR
)
);
exit(254);
}

Expand Down Expand Up @@ -70,5 +78,7 @@ if (!$loaded) {

require_once __DIR__ . '/src/polyfill.php';

$app = new JakubOnderka\PhpParallelLint\Application();
// Prevent parse error on PHP < 5.3 so the version check above can work.
$className = 'JakubOnderka\PhpParallelLint\Application';
$app = new $className();
exit($app->run());
22 changes: 19 additions & 3 deletions src/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ function jsonSerialize()

class SyntaxError extends Error
{
const IN_ON_REGEX = '~ in %s on line [0-9]+$~';

/** @var Blame */
private $blame;

Expand All @@ -131,8 +133,22 @@ public function getLine()
*/
public function getNormalizedMessage($translateTokens = false)
{
$message = preg_replace('~^(Parse|Fatal) error: (syntax error, )?~', '', $this->message);
$message = preg_replace('~ in ' . preg_quote(basename($this->filePath)) . ' on line [0-9]+$~', '', $message);
$message = preg_replace('~^(Parse|Fatal) error: (syntax error, )?~', '', $this->message);
$baseName = basename($this->filePath);
$regex = sprintf(self::IN_ON_REGEX, preg_quote($baseName, '~'));
$message = preg_replace($regex, '', $message, -1, $count);

if ($count === 0 && strpos($baseName, '\\') !== false) {
$baseName = ltrim(strrchr($this->filePath, '\\'), '\\');
$regex = sprintf(self::IN_ON_REGEX, preg_quote($baseName, '~'));
$message = preg_replace($regex, '', $message, -1, $count);
}

if ($count === 0) {
$regex = sprintf(self::IN_ON_REGEX, preg_quote($this->filePath, '~'));
$message = preg_replace($regex, '', $message);
}

$message = ucfirst($message);

if ($translateTokens) {
Expand Down Expand Up @@ -194,7 +210,7 @@ protected function translateTokens($message)
'T_ECHO' => 'echo'
);

return preg_replace_callback('~T_([A-Z_]*)~', function ($matches) use ($translateTokens) {
return preg_replace_callback('~(?<!\()T_([A-Z_]*)(?!\))~', function ($matches) use ($translateTokens) {
list($tokenName) = $matches;
if (isset($translateTokens[$tokenName])) {
$operator = $translateTokens[$tokenName];
Expand Down
4 changes: 2 additions & 2 deletions src/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class Manager
* @throws Exception
* @throws \Exception
*/
public function run(Settings $settings = null)
public function run($settings = null)
{
$settings = $settings ?: new Settings;
$settings = ($settings instanceof Settings) ? $settings : new Settings();
$output = $this->output ?: $this->getDefaultOutput($settings);

$phpExecutable = PhpExecutable::getPhpExecutable($settings->phpExecutable);
Expand Down
4 changes: 2 additions & 2 deletions src/Output.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,9 @@ protected function writeMark($type)

protected function writePercent()
{
$percent = floor($this->checkedFiles / $this->totalFileCount * 100);
$percent = $this->stringWidth(floor($this->checkedFiles / $this->totalFileCount * 100), 3);
$current = $this->stringWidth($this->checkedFiles, strlen($this->totalFileCount));
$this->writeLine(" $current/$this->totalFileCount ($percent %)");
$this->writeLine(" $current/$this->totalFileCount ($percent%)");
}

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/Output.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class OutputTest extends Tester\TestCase

$result = (array) json_decode($writer->getLogs());

Assert::equal(count($errors), count($result));

for ($i = 0; $i < count($result) && $i < count($errors); $i++) {
$message = $errors[$i]->getMessage();
$filePath = $errors[$i]->getFilePath();
Expand Down
10 changes: 10 additions & 0 deletions tests/ParallelLint.lint.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ class ParallelLintLintTest extends Tester\TestCase
Assert::equal(0, count($result->getErrors()));
}

public function testSkipShebang()
{
$parallelLint = new ParallelLint($this->getPhpExecutable());
$result = $parallelLint->lint(array(__DIR__ . '/examples/example-07/example.php'));

Assert::equal(0, $result->getCheckedFilesCount());
Assert::equal(0, $result->getFilesWithSyntaxErrorCount());
Assert::equal(1, $result->getSkippedFilesCount());
}

public function testInvalidFile()
{
$parallelLint = new ParallelLint($this->getPhpExecutable());
Expand Down
Loading
Loading