承接 larastrict/conventions 相关项目开发

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

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

larastrict/conventions

Composer 安装命令:

composer require larastrict/conventions

包简介

LaraStrict conventions for your Laravel apps - PHPStan, Easy Coding Standard, RectorPHP and appropriate rules.

README 文档

README

.github/banner.webp

Enhance the robustness and consistency of your Laravel applications with LaraStrict conventions. This package integrates essential tools like PHPStan, Easy Coding Standard, RectorPHP, and tailored rules to streamline your development process.

This package extends the StrictPHP conventions.

Key Features

This package bundles a selection of powerful tools and configurations to support your development workflow:

  • PHPStan Configuration and Custom Rules: Integrates PHPStan, with pre-defined configurations and rules tailored for our projects.
  • Easy Coding Standard Configuration: Utilizes Easy Coding Standard for enforcing consistent coding styles and practices.
  • PHPUnit 10/11 Support: Ensures compatibility with PHPUnit to facilitate comprehensive testing.
  • RectorPHP Configuration: Provides configurations for RectorPHP for better code quality.
  • Extended PHPStan Packages: Includes additional packages to augment PHPStan's capabilities. For more details, see the included composer.json file.

Prerequisites

Before installation, ensure your environment meets these requirements:

  • PHP version 8.1 or higher (based on your Laravel version).
  • Composer
  • Laravel 10+
  • Enabled Extension installer for PHPStan, which is automatically installed by our package to allow extension discovery.

Only the latest major version of this package is maintained.

Version PHPUnit PHP Laravel
2.x 10-13 8.3+ 12-13
1.x 10/11 8.2+ 10-12
0.x 9 8.1+ 9

Installation

To integrate LaraStrict Conventions into your project, run the following command in your terminal:

composer require larastrict/conventions --dev

This installs the package as a development dependency. During installation, you'll be prompted to confirm the installation of the plugin:

Do you trust "phpstan/extension-installer" to execute code and wish to enable it now? (yes/no) [y]:

Type y to use all provided extensions.

Getting Started

After installation, you can tailor the provided configurations to meet your project's requirements.

Setting Up Easy Coding Standard

To use Easy Coding Standard, create or update an ecs.php file at your project's root with the following setup:

<?php

declare(strict_types=1);

use Symplify\EasyCodingStandard\Config\ECSConfig;

return ECSConfig::configure()
    ->withRootFiles()
    ->withPaths(\LaraStrict\Conventions\ExtensionFiles::paths(baseDir: __DIR__, laravel11Structure: true))
    // This is required to include the StrictPHP Conventions
    ->withSets([\LaraStrict\Conventions\ExtensionFiles::Ecs]);

Check extension-ecs.php to see what is included:

  • Do not run ecs on blade files.

Configuring RectorPHP

For integrating RectorPHP, add or update a rector.php file in your project's root with the following configuration:

<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;

return RectorConfig::configure()
    ->withRootFiles()
    ->withPaths(\LaraStrict\Conventions\ExtensionFiles::paths(baseDir: __DIR__, laravel11Structure: true))
    // This is required to include the StrictPHP Conventions
    ->withSets([\LaraStrict\Conventions\ExtensionFiles::Rector]);

Check extension-rector.php to see what is included:

  • Prevent rector changing callable in routes.
  • Do not run rector on blade files.

Implemented rector

CarbonCreateToCreateStrictRector

Change Carbon::create() to Carbon::createStrict()

Integrating PHPStan

Ensure you use the PHPStan extension installer to install the required extensions.

PHPStan Configuration

Your phpstan should look like this:

parameters:

    level: max

    paths:
        - app
        - config
        - database/migrations
        - database/seeders
        - routes
        - tests
        - ecs.php
        - rector.php
        # Laravel 11 structure (comment if different)
        - bootstrap/app.php
        - bootstrap/providers.php

    #ignoreErrors:
    #    - identifier: missingType.iterableValue

Rules

The package includes the following rules:

UsableInContainerRule

Customization does not work yet. Currently disabled

The package includes rules for ensuring DI classes/contracts are used appropriately:

  • Ensures Contracts are Injectable: Checks if an implementation is registered for the contract.
  • Ensures Classes are Injectable: Checks if a registered class has injectable dependencies.

You can customize these settings as needed. Example configuration:

services:
    -
        class: LaraStrict\Conventions\PHPStan\UsableInContainerRule
        tags: [phpstan.rules.rule]
        arguments:
            enabled: true
            # Ensure that classes that extends these classes are injectable
            extends:
                - Illuminate\Console\Command
                - Illuminate\Database\Seeder
            # Do not check if classes that has these suffixes are injectable
            excludeSuffixes:
                - MySuffix
            # Check classes in these namespaces
            namespaces:
                - \DIClasses\
            # Do not check if classes file contains these folders
            excludeFolders:
                - my_folder

Default settings can be found in ./extension.neon file

Acknowledgement

This project owes its existence to the generous support of several other impactful projects:

Explore more of our open-source initiatives:

  • Larastrict - Enhancing the Laravel Framework with a suite of convenient tools and packages.
  • StrictPHP - Enabling strictness in PHP projects through a curated set of packages and conventions, fostering the development of robust production-grade applications.
  • WrkFlow - Streamlining development workflows with a comprehensive set of tools designed to boost efficiency.

License

Open-source software licensed under the MIT License. Feel free to use and modify it according to your needs.

larastrict/conventions 适用场景与选型建议

larastrict/conventions 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 460 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 04 月 06 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 larastrict/conventions 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 larastrict/conventions 我们能提供哪些服务?
定制开发 / 二次开发

基于 larastrict/conventions 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-04-06