承接 avengerscodelovers/laravel-cs 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

avengerscodelovers/laravel-cs

最新稳定版本:v0.1.0

Composer 安装命令:

composer require avengerscodelovers/laravel-cs

包简介

Laravel coding standards config

README 文档

README

This project aims to provide a common coding standards, static analysis configuration for Laravel projects.

Purpose

The purpose of this project is to share a standardized PHP-CS-Fixer and PHPStan configuration that can be easily used across different Laravel projects. By using this configuration, you can ensure consistent code formatting, style, and static analysis throughout your codebase.

Install

To use this configuration, install this composer package:

composer require --dev avengerscodelovers/laravel-cs

Usage

Code conventions

You can use PHP-CS-Fixer to check code conventions, format code with --config option:

./vendor/bin/php-cs-fixer fix --config=./vendor/avengerscodelovers/laravel-cs/.php-cs-fixer.dist.php

To incorporate CI integration, you can utilize the following command to verify if the code adheres to the conventions:

./vendor/bin/php-cs-fixer fix --dry-run -v --config=./vendor/avengerscodelovers/laravel-cs/.php-cs-fixer.dist.php

By using this configuration, PHP-CS-Fixer will apply the defined rules to your codebase, ensuring that it adheres to the coding standards.

You can also add add the PHP-CS-Fixer command to the composer.json scripts:

    "scripts": {
        "cs": "php-cs-fixer fix --dry-run -v --config=./vendor/avengerscodelovers/laravel-cs/.php-cs-fixer.dist.php",
        "cs:fix": "php-cs-fixer fix -v --config=./vendor/avengerscodelovers/laravel-cs/.php-cs-fixer.dist.php",
    }

After adding the script, you can run the PHP-CS-Fixer command by executing the following command in your terminal:

composer cs
composer cs:fix

Static analysis

To perform static analysis on your code and identify potential issues or errors, you can use PHPStan.

First, create a phpstan.neon or phpstan.neon.dist file in the root of your application. It might look like this:

includes:
    - ./vendor/avengerscodelovers/laravel-cs/phpstan.neon

parameters:

    paths:
        - app/

    # Level 9 is the highest level
    level: 5

    ## Exclude files or folder from analysis ##
    # excludePaths:
    #    - app/Modules/*/Tests/*

Then you can run PHPStan with the following command:

./vendor/bin/phpstan analyze

You may add the PHPStan command to the composer.json scripts:

"scripts": {
    "phpstan": "phpstan analyse --memory-limit 2G"
}

After adding the script, you can run PHPStan by executing the following command in your terminal:

composer phpstan

Usage with lint-staged

You can also integrate with lint-staged and pre-commit to automatically run the fixer, static analysis when committing changes:

"lint-staged": {
    "*.php": [
        "composer cs:fix",
        "composer phpstan"
    ]
}

统计信息

  • 总下载量: 13
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-07-24