Convert Figma logo to code with AI

nunomaduro logophpinsights

🔰 Instant PHP quality checks from your console

5,270
280
5,270
73

Top Related Projects

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

12,802

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

5,537

A static analysis tool for finding errors in PHP applications

5,528

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

2,321

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.

2,214

Copy/Paste Detector (CPD) for PHP code.

Quick Overview

PHP Insights is a powerful static analysis tool for PHP projects. It provides instant feedback on code quality, architecture, and complexity, helping developers improve their codebase. The tool offers a beautiful console interface and can be easily integrated into CI/CD pipelines.

Pros

  • Comprehensive analysis covering code quality, architecture, and complexity
  • Beautiful and intuitive console output with color-coded results
  • Easy integration with popular PHP frameworks like Laravel and Symfony
  • Customizable configuration to fit specific project needs

Cons

  • May produce false positives in some cases, requiring manual review
  • Can be resource-intensive for large codebases
  • Learning curve for interpreting and addressing all types of insights
  • Limited support for legacy PHP versions

Code Examples

  1. Running PHP Insights on a project:
<?php

use NunoMaduro\PhpInsights\InsightsApplication;

$app = new InsightsApplication();
$app->run();
  1. Customizing analysis configuration:
<?php

return [
    'preset' => 'default',
    'exclude' => [
        'tests',
        'vendor',
    ],
    'add' => [
        \NunoMaduro\PhpInsights\Domain\Insights\ForbiddenNormalClasses::class,
    ],
    'remove' => [
        \NunoMaduro\PhpInsights\Domain\Insights\ForbiddenTraits::class,
    ],
];
  1. Integrating PHP Insights with Laravel:
<?php

namespace App\Console\Commands;

use NunoMaduro\PhpInsights\InsightsCommand;

class AnalyzeCode extends InsightsCommand
{
    protected $signature = 'code:analyze';
    protected $description = 'Analyze code quality and architecture';
}

Getting Started

To get started with PHP Insights, follow these steps:

  1. Install PHP Insights via Composer:

    composer require nunomaduro/phpinsights --dev
    
  2. Run PHP Insights on your project:

    ./vendor/bin/phpinsights
    
  3. Review the output and address the reported issues to improve your code quality.

  4. Optionally, create a configuration file phpinsights.php in your project root to customize the analysis:

    <?php
    
    return [
        'preset' => 'default',
        'exclude' => [
            'tests',
        ],
    ];
    
  5. Integrate PHP Insights into your CI/CD pipeline for continuous code quality checks.

Competitor Comparisons

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

Pros of PHP_CodeSniffer

  • Mature and widely adopted in the PHP community
  • Highly customizable with extensive configuration options
  • Supports a wide range of coding standards out of the box

Cons of PHP_CodeSniffer

  • Can be complex to set up and configure for specific project needs
  • May require additional plugins for more advanced analysis
  • Output can be verbose and harder to interpret for beginners

Code Comparison

PHP_CodeSniffer:

<?php
$phpcsFile = $phpcsFile;
$tokens = $phpcsFile->getTokens();
foreach ($tokens as $token) {
    // Analyze token
}

PHPInsights:

<?php
use NunoMaduro\PhpInsights\Domain\Insights\ForbiddenNormalClasses;

class CustomInsight extends ForbiddenNormalClasses
{
    public function getTitle(): string
    {
        return 'Custom Insight';
    }
}

PHP_CodeSniffer focuses on token-level analysis, while PHPInsights provides a higher-level abstraction for creating custom insights. PHPInsights offers a more modern and user-friendly approach, with built-in metrics and a visually appealing console output. However, PHP_CodeSniffer's maturity and extensive customization options make it a solid choice for projects requiring fine-grained control over coding standards.

12,802

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

Pros of PHPStan

  • More extensive static analysis capabilities, focusing on finding bugs and errors
  • Larger community and ecosystem with numerous extensions available
  • Highly configurable with multiple rule levels and custom rules support

Cons of PHPStan

  • Steeper learning curve, especially for complex configurations
  • Primarily focused on error detection, lacking some code quality metrics
  • Can be more resource-intensive for large codebases

Code Comparison

PHPStan example:

<?php
function foo(int $a, int $b): int {
    return $a + $b;
}
foo('1', 2);

PHPInsights example:

<?php
function bar($a, $b) {
    return $a + $b;
}
bar(1, 2);

PHPStan would detect the type mismatch in the function call, while PHPInsights might focus on the lack of type hints in the function declaration.

Summary

PHPStan excels in deep static analysis and error detection, offering a more comprehensive approach to finding potential bugs. It's highly extensible but may require more setup time. PHPInsights, on the other hand, provides a broader overview of code quality, including style and complexity metrics, with a more user-friendly approach. The choice between the two depends on specific project needs and team preferences.

5,537

A static analysis tool for finding errors in PHP applications

Pros of Psalm

  • More comprehensive static analysis with advanced type checking
  • Supports a wider range of PHP versions (7.1+)
  • Offers more detailed and customizable error reporting

Cons of Psalm

  • Steeper learning curve for configuration and usage
  • Can be slower for large codebases due to its thorough analysis

Code Comparison

Psalm:

<?php
/**
 * @psalm-param array<string, int> $data
 * @psalm-return int
 */
function sumValues(array $data): int {
    return array_sum($data);
}

PHPInsights:

<?php
function sumValues(array $data): int {
    return array_sum($data);
}

Psalm provides more detailed type annotations, allowing for stricter type checking and better code documentation. PHPInsights focuses on general code quality and style, without the advanced type checking capabilities.

Both tools aim to improve PHP code quality, but Psalm excels in static analysis and type inference, while PHPInsights offers a more accessible approach to code quality assessment with a focus on best practices and coding standards.

Psalm is better suited for larger projects requiring strict type checking and advanced static analysis, while PHPInsights is ideal for teams looking for a quick and easy way to improve overall code quality and adherence to coding standards.

5,528

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
  • Supports a wider range of PHP versions (5.6 to 8.1)
  • Highly configurable with numerous options for customization

Cons of phan

  • Steeper learning curve and more complex setup
  • Can produce more false positives, requiring fine-tuning
  • Slower analysis speed, especially on larger codebases

Code Comparison

phan:

<?php
/**
 * @param int $x
 * @return string
 */
function foo($x) {
    return $x;  // Phan: PhanTypeMismatchReturn Returning int but foo() is declared to return string
}

phpinsights:

<?php
function foo($x) {
    return $x;  // PHPInsights: Type hint for the parameter $x is missing
}

phan provides more detailed type checking and can detect mismatches between declared and actual return types. phpinsights focuses on code style and best practices, suggesting improvements like adding type hints.

Both tools offer valuable insights for improving PHP code quality, but they have different strengths. phan excels in deep static analysis and type checking, while phpinsights provides a more accessible approach to code quality assessment with a focus on best practices and maintainability.

2,321

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

  • Longer history and more established in the PHP community
  • Highly customizable with extensive rule sets
  • Integrates well with various CI/CD tools and IDEs

Cons of PHPMD

  • Less user-friendly output compared to PHPInsights
  • Requires more configuration to get started effectively
  • Slower performance on large codebases

Code Comparison

PHPMD configuration:

<ruleset name="My PHPMD rule set">
    <rule ref="rulesets/cleancode.xml" />
    <rule ref="rulesets/codesize.xml" />
    <rule ref="rulesets/controversial.xml" />
    <rule ref="rulesets/design.xml" />
    <rule ref="rulesets/naming.xml" />
</ruleset>

PHPInsights configuration:

return [
    'preset' => 'default',
    'ide' => 'phpstorm',
    'exclude' => [
        'tests',
    ],
];

Both tools aim to improve code quality, but PHPInsights offers a more modern and user-friendly approach with its preset configurations and visually appealing output. PHPMD, on the other hand, provides more granular control over rules and has been a staple in PHP development for years. PHPInsights is generally easier to set up and use out of the box, while PHPMD requires more initial configuration but offers greater customization options.

2,214

Copy/Paste Detector (CPD) for PHP code.

Pros of phpcpd

  • Focused specifically on detecting copy-pasted code
  • Lightweight and fast execution
  • Integrates well with CI/CD pipelines

Cons of phpcpd

  • Limited to copy-paste detection only
  • Lacks comprehensive code quality analysis features
  • May require additional tools for a complete code review

Code Comparison

phpcpd:

<?php
$finder = new Finder();
$finder->files()->in($path);

$cpd = new PHPCPD();
$result = $cpd->run($finder);

phpinsights:

<?php
use NunoMaduro\PhpInsights\InsightsApplication;

$application = new InsightsApplication($config);
$result = $application->run();

Key Differences

  1. Scope: phpcpd focuses solely on copy-paste detection, while phpinsights offers a comprehensive code quality analysis.

  2. Features: phpinsights provides a wider range of insights, including architecture, style, and complexity metrics, whereas phpcpd is limited to duplicate code detection.

  3. Integration: Both tools can be integrated into development workflows, but phpinsights offers a more user-friendly interface and detailed reports.

  4. Community: phpinsights has a larger and more active community, with frequent updates and contributions.

  5. Customization: phpinsights allows for more customization through configuration files, while phpcpd has fewer options for tailoring its analysis.

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

PHP Insights PHP Insights Preview

Unit Tests Total Downloads Latest Version License

For full documentation, visit phpinsights.com.

PHP Insights was carefully crafted to simplify the analysis of your code directly from your terminal, and is the perfect starting point to analyze the code quality of your PHP projects. It was created by Nuno Maduro, logo design Caneco, and currently is maintained by Chris Gmyr, Jibé Barth, and Steve McDougall.

🚀 Quick start

First, install:

composer require nunomaduro/phpinsights --dev

Then, use it:

./vendor/bin/phpinsights

For Laravel:

First, publish the configuration file:

php artisan vendor:publish --provider="NunoMaduro\PhpInsights\Application\Adapters\Laravel\InsightsServiceProvider"

Then, use it:

php artisan insights

✨ Features

  • Analysis of code quality and coding style
  • Beautiful overview of code architecture and its complexity
  • Designed to work out-of-the-box with Laravel, Symfony, Yii, Magento, and more
  • Contains built-in checks for making code reliable, loosely coupled, simple, and clean

💖 Support the development

Do you like this project? Support it by donating

Click the "💖 Sponsor" at the top of this repo.

PHP Insights is open-sourced software licensed under the MIT license.