Convert Figma logo to code with AI

overtrue logophplint

:bug: A tool that can speed up linting of php files by running several lint processes at once.

1,003
88
1,003
8

Top Related Projects

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.

13,286

PHP Static Analysis Tool - discover bugs in your code without running it!

5,643

A static analysis tool for finding errors in PHP applications

5,559

Phan is a static analyzer for PHP. Phan prefers to avoid false-positives and attempts to prove incorrectness rather than correctness.

A tool to automatically fix PHP Coding Standards issues

2,356

PHPMD is a spin-off project of PHP Depend and aims to be a PHP equivalent of the well known Java tool PMD. PHPMD can be seen as an user friendly frontend application for the raw metrics stream measured by PHP Depend.

Quick Overview

PHPLint is a tool for statically analyzing PHP code to detect potential errors and enforce coding standards. It scans PHP files for syntax errors, undefined variables, and other common issues without actually executing the code, making it a valuable tool for maintaining code quality and catching bugs early in the development process.

Pros

  • Fast and efficient, capable of scanning large codebases quickly
  • Integrates well with continuous integration (CI) pipelines
  • Customizable with configuration options to suit specific project needs
  • Supports parallel processing for improved performance

Cons

  • May produce false positives in some cases
  • Limited to static analysis, cannot detect runtime errors
  • Requires PHP 7.1 or higher, which may not be suitable for older projects
  • Some advanced features may require additional configuration

Code Examples

  1. Basic usage:
<?php
use Overtrue\PHPLint\Linter;

$path = __DIR__ . '/app';
$linter = new Linter($path);
$violations = $linter->lint();

foreach ($violations as $violation) {
    echo $violation->getFile() . ': ' . $violation->getMessage() . PHP_EOL;
}

This example demonstrates how to use PHPLint to scan a directory and report any violations found.

  1. Configuring ignored directories:
<?php
use Overtrue\PHPLint\Linter;

$path = __DIR__ . '/app';
$linter = new Linter($path, [
    'exclude' => ['vendor', 'tests']
]);
$violations = $linter->lint();

This code shows how to exclude specific directories from the linting process.

  1. Using parallel processing:
<?php
use Overtrue\PHPLint\Linter;

$path = __DIR__ . '/app';
$linter = new Linter($path);
$violations = $linter->lint([], 8); // Use 8 parallel processes

This example demonstrates how to enable parallel processing to improve linting performance.

Getting Started

To get started with PHPLint, follow these steps:

  1. Install PHPLint using Composer:

    composer require overtrue/phplint --dev
    
  2. Create a configuration file named .phplint.yml in your project root:

    path: ./
    jobs: 10
    extensions:
      - php
    exclude:
      - vendor
    
  3. Run PHPLint from the command line:

    ./vendor/bin/phplint
    

This will scan your project for PHP files and report any linting errors found.

Competitor Comparisons

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.

Pros of PHP_CodeSniffer

  • More comprehensive code analysis, covering a wider range of coding standards and best practices
  • Highly customizable with the ability to create custom sniffs and rulesets
  • Integrates well with various IDEs and CI/CD pipelines

Cons of PHP_CodeSniffer

  • Slower performance, especially on larger codebases
  • Steeper learning curve due to its extensive configuration options
  • Can produce false positives in certain scenarios, requiring fine-tuning

Code Comparison

PHP_CodeSniffer:

<?php
phpcs --standard=PSR12 /path/to/code

phplint:

<?php
./vendor/bin/phplint /path/to/code

PHP_CodeSniffer offers more detailed analysis and customization options, while phplint focuses primarily on syntax checking. PHP_CodeSniffer's command allows specifying coding standards, whereas phplint provides a simpler syntax-only check.

PHP_CodeSniffer is better suited for projects requiring adherence to specific coding standards and in-depth code quality analysis. phplint, on the other hand, excels in quick syntax checks and is ideal for rapid development cycles or as part of a CI/CD pipeline where speed is crucial.

Both tools have their place in PHP development workflows, often complementing each other. PHP_CodeSniffer provides comprehensive code quality checks, while phplint offers fast syntax validation.

13,286

PHP Static Analysis Tool - discover bugs in your code without running it!

Pros of PHPStan

  • More comprehensive static analysis, detecting a wider range of issues
  • Customizable rule sets and configuration options
  • Integrates with popular frameworks and libraries

Cons of PHPStan

  • Steeper learning curve and more complex setup
  • May produce more false positives, requiring fine-tuning

Code Comparison

PHPStan:

<?php
declare(strict_types=1);

use PHPStan\Analyser\Analyser;
use PHPStan\DependencyInjection\ContainerFactory;

$containerFactory = new ContainerFactory(getcwd());
$container = $containerFactory->create(sys_get_temp_dir(), [__DIR__ . '/config.neon'], []);
$analyser = $container->getByType(Analyser::class);

PHPLint:

<?php
use Overtrue\PHPLint\Linter;

$path = __DIR__ . '/app';
$excludes = [
    'vendor',
];

$linter = new Linter($path, $excludes);
$errors = $linter->lint();

PHPStan offers more advanced static analysis capabilities, making it suitable for larger projects with complex codebases. It provides deeper insights into potential issues but requires more setup and configuration. PHPLint, on the other hand, is simpler to use and focuses primarily on syntax checking, making it a good choice for quick linting tasks or smaller projects. The code comparison shows that PHPStan requires more setup but offers more advanced analysis options, while PHPLint provides a straightforward interface for basic linting.

5,643

A static analysis tool for finding errors in PHP applications

Pros of Psalm

  • More comprehensive static analysis, including type inference and security checks
  • Supports gradual typing and can be integrated into CI/CD pipelines
  • Offers a wider range of configuration options and customization

Cons of Psalm

  • Steeper learning curve due to its advanced features
  • May produce more false positives, requiring fine-tuning
  • Slower analysis speed compared to simpler linters

Code Comparison

Psalm configuration example:

<?xml version="1.0"?>
<psalm errorLevel="3">
    <projectFiles>
        <directory name="src" />
    </projectFiles>
</psalm>

PHPLint configuration example:

{
    "path": ["src"],
    "extensions": ["php"]
}

Psalm offers more detailed configuration options, allowing for fine-grained control over the analysis process. PHPLint, on the other hand, provides a simpler configuration focused primarily on specifying which files to lint.

While both tools aim to improve code quality, Psalm offers a more comprehensive analysis at the cost of increased complexity. PHPLint is simpler to set up and use but provides less advanced features. The choice between the two depends on the project's needs, team expertise, and desired level of code analysis.

5,559

Phan is a static analyzer for PHP. Phan prefers to avoid false-positives and attempts to prove incorrectness rather than correctness.

Pros of phan

  • More comprehensive static analysis with advanced type checking and inference
  • Detects a wider range of potential issues and bugs
  • Highly configurable with numerous options for customization

Cons of phan

  • Steeper learning curve and more complex setup
  • Can be slower for large codebases due to its in-depth analysis
  • May produce more false positives, requiring careful configuration

Code Comparison

phan example:

<?php
function example(int $a, string $b): void {
    echo $a + $b; // Phan will detect type mismatch
}

phplint example:

<?php
function example($a, $b) {
    echo $a + $b; // phplint will only check for syntax errors
}

phan provides more detailed analysis, detecting type mismatches and potential issues, while phplint focuses primarily on syntax checking.

phplint is simpler to use and faster for basic linting, making it suitable for quick syntax checks in CI/CD pipelines. However, phan offers more comprehensive static analysis, making it better for in-depth code quality checks and catching potential runtime errors before they occur.

Both tools have their place in PHP development workflows, with phplint being ideal for rapid syntax checking and phan for more thorough code analysis and type checking.

A tool to automatically fix PHP Coding Standards issues

Pros of PHP-CS-Fixer

  • More comprehensive: Fixes coding standards issues in addition to linting
  • Highly configurable: Offers a wide range of rules and options
  • Actively maintained: Regular updates and improvements

Cons of PHP-CS-Fixer

  • Slower execution: Takes longer to run due to its extensive functionality
  • Steeper learning curve: More complex configuration and usage

Code Comparison

PHP-CS-Fixer:

$config = new PhpCsFixer\Config();
return $config->setRules([
    '@PSR2' => true,
    'array_syntax' => ['syntax' => 'short'],
    'no_unused_imports' => true,
]);

phplint:

$phplint = new overtrue\phplint\Linter($path, $options);
$phplint->lint();

PHP-CS-Fixer offers more extensive configuration options and can automatically fix issues, while phplint focuses solely on syntax checking. PHP-CS-Fixer is better suited for projects requiring strict adherence to coding standards, whereas phplint is simpler and faster for basic syntax validation.

2,356

PHPMD is a spin-off project of PHP Depend and aims to be a PHP equivalent of the well known Java tool PMD. PHPMD can be seen as an user friendly frontend application for the raw metrics stream measured by PHP Depend.

Pros of PHPMD

  • More comprehensive analysis: PHPMD checks for a wider range of issues, including code complexity, unused variables, and potential bugs
  • Customizable rulesets: Allows users to define their own rules or use predefined rulesets
  • Integration with various tools: Can be easily integrated with IDEs, CI/CD pipelines, and other development tools

Cons of PHPMD

  • Steeper learning curve: Requires more configuration and understanding of rulesets
  • Potentially slower execution: Due to its more extensive analysis, it may take longer to run on large codebases
  • False positives: May generate more false positives that require manual review

Code Comparison

PHPLint:

<?php
$linter = new Overtrue\PHPLint\Linter($path);
$linter->lint([$filename]);

PHPMD:

<?php
$renderer = new \PHPMD\Renderer\TextRenderer();
$ruleSetFactory = new \PHPMD\RuleSetFactory();
$phpmd = new \PHPMD\PHPMD();
$phpmd->processFiles($filename, $format, $ruleSets, $renderer);

Both tools aim to improve code quality, but PHPLint focuses primarily on syntax errors, while PHPMD provides a more comprehensive analysis of code quality and potential issues. PHPLint is simpler to use and faster for basic syntax checking, while PHPMD offers more in-depth analysis at the cost of complexity and execution time.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

PHPLint

`phplint` is a tool that can speed up linting of php files by running several lint processes at once.

Release Status Latest Stable Version Total Downloads License FOSSA Status

VersionStatusRequirements
9.xActive developmentPHP >= 8.1
9.6Active supportPHP >= 8.1
9.5Active supportPHP >= 8.1
9.4End Of LifePHP >= 8.1
9.3End Of LifePHP >= 8.1
9.2End Of LifePHP >= 8.1
9.1End Of LifePHP >= 8.1
9.0End Of LifePHP >= 8.0
6.xEnd Of LifePHP >= 8.2
5.xEnd Of LifePHP >= 8.1
4.xEnd Of LifePHP >= 8.0
3.xEnd Of LifePHP >= 7.4

NOTE if you have an older version of PHP lower than 8.0, we recommend to use the latest version 3.4.0

Major version 9.0 is a full code rewrites that have the same source code (main branch) for all PHP 8.x versions (4.x, 5.x or 6.x), with a lot of improvement, full documentation, and full unit code tested.

Table of Contents

  1. Installation
    1. Requirements
    2. PHAR
    3. Docker
    4. Phive
    5. Composer
  2. Usage
  3. Configuration
  4. Upgrading
  5. Contributing
  6. Architecture

:heart: Sponsor me

Sponsor me

如果你喜欢我的项目并想支持它,点击这里 :heart:

Project supported by JetBrains

Many thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects.

PHP 扩展包开发

想知道如何从零开始构建 PHP 扩展包?

请关注我的实战课程,我会在此课程中分享一些扩展开发经验 —— 《PHP 扩展包实战教程 - 从入门到发布》

License

MIT