Bo's Code Review Style
Analysis of Bo’s code review style based on 400+ comments across 200 MRs. Use this guide for self-review before submission or to conduct reviews in a similar style.
Core Focus Areas
Section titled “Core Focus Areas”1. Code Simplification (Primary Focus)
Section titled “1. Code Simplification (Primary Focus)”Bo consistently identifies opportunities to simplify code by removing redundant variables, conditions, and operations.
Examples:
“变量可以省略”
“这个判断可以去掉”
“多余变量”
“直接返回array<int, App\Model\Task>就行吧”
“可以简化为
$client_display_chart = $tax_distribution_display_chart['client'] ?? $tax_distribution_display_chart;”
2. Type Safety & PHPDoc
Section titled “2. Type Safety & PHPDoc”Bo emphasizes proper type definitions and avoiding ambiguous types.
Examples:
“缺少类型定义”
“里面用 array shape 更好点”
“类型不对,应该是 list
”
“return type-hint”
“里面的数据类型是固定的,不应该用
mixed”
“可以补上 array shape”
3. Namespace & Import Style
Section titled “3. Namespace & Import Style”Bo prefers short namespaces and consistent import patterns.
Examples:
“use short namespace”
“short alias”
“使用use,尽量不要用fqcn”
“可以用Arr” (instead of full namespace)
4. Database Operations
Section titled “4. Database Operations”Bo focuses on proper database patterns and performance.
Examples:
“这里最好是改成 DB 的方式更符合 database migration”
“建议使用
chunkById”
“用 SQL 做聚合看起来不是很容易读, 可以考虑先查询出所有符合条件的 households 然后 groupBy”
“不能修改原来的 migration 文件,需要建新的来修改数据库结构”
5. Naming Conventions
Section titled “5. Naming Conventions”Bo ensures consistent naming patterns.
Examples:
“常量名和内容尽量保持一致吧”
“加上 ‘id’ 会不会好点:
new_legends_by_old_legend=>new_legend_ids_by_old_legend_id”
“命名不统一,有的地方叫engine_model_class,这里叫engine_object_class”
“字典序排列” (alphabetical ordering)
6. Collection & Array Operations
Section titled “6. Collection & Array Operations”Bo prefers Laravel Collection methods over manual loops.
Examples:
“可以考虑用
Arr::keyBy()”
“建议使用解构赋值并提供默认值”
“$tasks是Collection,可以通过 pluck(Task::COLUMN_ID)获取有效的ids”
“可以用 Collection::append 来添加元素更合适”
7. Conditional Logic
Section titled “7. Conditional Logic”Bo identifies redundant or incorrect conditional checks.
Examples:
“这个条件应该不需要”
“只需要这个判断就行,外层的 if else 不需要”
“这个 if 可以不需要了”
“判断逻辑有问题”
8. Modern PHP Features
Section titled “8. Modern PHP Features”Bo encourages using modern PHP syntax.
Examples:
“可以改用箭头函数”
“可以试试PHP8.1的新写法”
“Is it possible to use
matchto replaceswitchstatements”
“str_ends_with” / “str_starts_with” (instead of manual string checks)
Self-Review Checklist
Section titled “Self-Review Checklist”Before submitting for review, check these items:
Code Simplification
Section titled “Code Simplification”- Remove unnecessary intermediate variables
- Remove redundant conditions
- Inline simple expressions
- Avoid redundant array operations (toArray, get())
Type Safety
Section titled “Type Safety”- Add type hints to all parameters and return types
- Use array shapes instead of mixed
- Use list
for sequential arrays - Define @phpstan-type for complex repeated types
Namespace Style
Section titled “Namespace Style”- Use short namespace imports (use Arr instead of \Illuminate\Support\Arr)
- Use FQCN in PHPDoc comments
- Consistent import style throughout file
Database Operations
Section titled “Database Operations”- Use DB for data migrations, ORM for application code
- Use chunkById for large datasets
- Don’t modify existing migration files
- Use Schema::table for DDL operations
Naming
Section titled “Naming”- Constants contain what they describe (ids in name if contains ids)
- Alphabetical ordering for lists/constants
- Consistent naming across related code
- Variable names match their purpose
Collections
Section titled “Collections”- Use Arr::keyBy, Arr::first instead of manual loops
- Use pluck to extract values
- Use Collection methods instead of array functions
- Destructure with defaults instead of isset checks
Conditionals
Section titled “Conditionals”- Remove obviously true conditions
- Combine related if statements
- Use early returns to reduce nesting
- Check for inverted logic
Modern PHP
Section titled “Modern PHP”- Use arrow functions for simple callbacks
- Use match instead of switch when appropriate
- Use str_ends_with/str_starts_with
- Use constructor property promotion
Review Style Characteristics
Section titled “Review Style Characteristics”| Trait | Example |
|---|---|
| Simplification-focused | ”变量可以省略” |
| Type precision | ”里面用 array shape 更好点” |
| Short namespace preference | ”use short namespace” |
| Collection-savvy | ”可以考虑用 Arr::keyBy()“ |
| Alphabetical ordering | ”字典序排列” |
| Modern PHP advocate | ”可以试试PHP8.1的新写法” |
| Bilingual | Chinese for explanations, English for code terms |
Common Phrases
Section titled “Common Phrases”- “变量可以省略” — Remove unnecessary variables
- “可以简化为…” — Suggesting simplification
- “缺少类型定义” — Missing type definitions
- “字典序排列” — Alphabetical ordering
- “use short namespace” — Namespace style
- “这个判断可以去掉” — Redundant condition
- “可以改用…” — Suggesting alternatives
- “多余” — Redundant code/space
Patterns to Avoid
Section titled “Patterns to Avoid”Based on Bo’s reviews, avoid these patterns:
- Unnecessary variables that are used only once
- Redundant conditions that are always true
- Full namespace when import is available
- Mixed types when specific types are known
- Manual loops when Collection methods exist
- Modifying old migrations instead of creating new ones
- Inconsistent naming across related code
- Unsorted constants that should be alphabetical
Summary
Section titled “Summary”Bo’s review style is precision and simplification focused, emphasizing:
- Code reduction — Remove all unnecessary variables, conditions, and operations
- Type accuracy — Use specific types, array shapes, and proper type hints
- Namespace consistency — Short imports, consistent style
- Collection fluency — Use Laravel Collection methods effectively
- Modern PHP — Embrace arrow functions, match expressions, modern string functions
- Ordering discipline — Alphabetical ordering for maintainability
- Database correctness — Proper migration patterns and query optimization