develop
分支作为基础分支feature/
开头 + 基础分支 + 姓名 + 功能 + 日期。例如: feature/develop-order-zhaohao-0423
## --path=(可选。可以是migrations文件夹下的一个目录)
php bin/hyperf.php gen:migration create_users_table --table=表名
use HyperfDbConnectionDb;
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('user', function (Blueprint $table) {
$table->bigIncrements('id')->comment('用户id');
$table->bigInteger('uid', false, true)->nullable(false)->comment('用户id');
$table->tinyInteger('status', false, false)->nullable(false)->default(1)->comment('用户状态 1正常');
$table->timestamps();
$table->unique('uid', 'uid');
$table->index('status', 'status');
});
Db::statement("ALTER TABLE `users` COMMENT = '用户表'");
}
servcie方法
记得增加参数的类型以及返回值的类型,接收外部参数记得转换类型composer check
。其中: composer cs-fix
格式化代码,composer analyse
静态检测外部接口
都要编写自动化测试队列
必须可以重复执行cache key
必须在对应配置文件中配置<?php
declare(strict_types=1);
use AppConstants;
/**
* 测试
* Class DevelopTest
*/
class DevelopTest
{
/**
* Test constructor.
*/
public function __construct()
{
}
/**
* @param int $userId
* @return int
*/
public function test(int $userId): int
{
return $userId;
}
}
执行命令
composer cs-fix
格式化代码
> composer cs-fix && composer analyze
> php-cs-fixer fix $1
Loaded config default from "/hyperf-skeleton/项目/.php_cs".
1) 项目/app/Repositories/BaseRepository.php
2) 项目/migrations/2021_04_25_153106_creat_user_wechat_table.php
格式化代码的风格在项目根目录.php_cs 中定义,目前按照以下方式来格式化代码
<?php
$header = <<<'EOF'
This file is part of 666.
@link 666
@document 666
EOF;
return PhpCsFixerConfig::create()
->setRiskyAllowed(true)
->setRules([
'@PSR2' => true,
'@Symfony' => true,
'@DoctrineAnnotation' => true,
'@PhpCsFixer' => true,
'header_comment' => [
'commentType' => 'PHPDoc',
'header' => $header,
'separate' => 'none',
'location' => 'after_declare_strict',
],
'array_syntax' => [
'syntax' => 'short'
],
'list_syntax' => [
'syntax' => 'short'
],
'concat_space' => [
'spacing' => 'one'
],
'blank_line_before_statement' => [
'statements' => [
'declare',
],
],
'general_phpdoc_annotation_remove' => [
'annotations' => [
'author'
],
],
'ordered_imports' => [
'imports_order' => [
'class', 'function', 'const',
],
'sort_algorithm' => 'alpha',
],
'single_line_comment_style' => [
'comment_types' => [
],
],
'yoda_style' => [
'always_move_variable' => false,
'equal' => false,
'identical' => false,
],
'phpdoc_align' => [
'align' => 'left',
],
'multiline_whitespace_before_semicolons' => [
'strategy' => 'no_multi_line',
],
'class_attributes_separation' => true,
'combine_consecutive_unsets' => true,
'declare_strict_types' => true,
'linebreak_after_opening_tag' => true,
'lowercase_constants' => true,
'lowercase_static_reference' => true,
'no_useless_else' => true,
'no_unused_imports' => true,
'not_operator_with_successor_space' => true,
'not_operator_with_space' => false,
'ordered_class_elements' => true,
'php_unit_strict' => false,
'phpdoc_separation' => false,
'single_quote' => true,
'standardize_not_equals' => true,
'multiline_comment_opening_closing' => true,
])
->setFinder(
PhpCsFixerFinder::create()
->exclude('public')
->exclude('runtime')
->exclude('vendor')
->in(__DIR__)
)
->setUsingCache(false);
执行脚本 composer analyse,对项目进行静态检测,便可以找到出现问题的代码段。
$ salesperson-service(develop*) » composer analyse
> phpstan analyse --memory-limit 300M -l 0 -c phpstan.neon ./app ./src ./config
181/181 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
[OK] No errors