Skip to content
advanced Phase 112 · Leadership

Code Review Leadership in Magento 2

Building review culture, mentoring through reviews, and establishing quality standards

45m
2 problems
Topic Progress 0%

Building Review Culture

Review Culture Principles

Psychological Safety

Goal: Reviews improve code, not judge people

DO:
- Ask questions, don't make accusations
- Explain why something is a problem
- Suggest alternatives
- Acknowledge good work
- Be respectful of different approaches

DON'T:
- Use condescending language
- Make it personal
- Dismiss ideas without explanation
- Gatekeep with obscure rules
- Rush through reviews

Review as Learning

Frame reviews as:
- Knowledge sharing opportunity
- Team alignment mechanism
- Quality improvement process
- Mentoring touchpoint

Not as:
- Gatekeeping exercise
- Style preference enforcement
- Last minute roadblock

Response Guidelines

// Good response to feedback
"Thanks for catching that! I didn't consider the caching implication. 
 Updated the PR to use the cache interface."

// Good response to disagreement
"I see your point about the repository pattern. I chose the direct approach 
 because [reason]. Happy to discuss further if you think the trade-off 
 isn't worth it."

// Bad response
"This works fine, no need to change."

Review Turnaround

Target turnaround times:
- Critical fixes: 2 hours
- Regular PRs: 4 hours
- Large features: 24 hours

Block reviews:
- PRs waiting > 24 hours
- Review requests without context
- PRs touching critical systems

Mentoring Through Reviews

Teaching Moments

Level 1: Point Out Issue

Comment: "This method is too long."

Better: "This method is 150 lines. Consider breaking it into 
 smaller methods for readability and testability."

Level 2: Explain Why

Comment: "Use repository instead of direct model load."

Better: "Use ProductRepositoryInterface instead of ProductFactory::create() 
 because:
 1. Repository handles caching
 2. Supports extension attributes
 3. Follows service contract pattern
 4. Easier to mock in tests"

Level 3: Suggest Solution

Comment: "Add error handling."

Better: "This should handle the case where the product doesn't exist:

 ```php
 try {
     $product = $this->repository->get($sku);
 } catch (NoSuchEntityException $e) {
     $this->logger->warning('Product not found', ['sku' => $sku]);
     return null;
 }

This follows the Magento pattern for entity loading."


### Level 4: Link to Resources

// For architectural guidance
"This change affects the service contract. See our ADR-003
for the team's decision on service layer patterns."

// For style consistency
"We follow Magento coding standard for this. See:
https://devdocs.magento.com/guides/v2.4/coding-standards.html"

// For learning
"This pattern is called Repository Pattern. Here's a good
explanation: [link]. We use it throughout our codebase
for data access."


### Identifying Growth Areas
```php
// Track reviewer observations
$developerFeedback = [
    'junior_dev' => [
        'patterns' => ['missing_type_hints', 'no_error_handling'],
        'improvement' => 'Focus on defensive programming',
        'resources' => ['PHPStan tutorial', 'Exception handling guide']
    ],
    'mid_dev' => [
        'patterns' => ['tight_coupling', 'missing_abstractions'],
        'improvement' => 'Focus on SOLID principles',
        'resources' => ['Refactoring book', 'Design patterns']
    ]
];

Pair Review Sessions

For complex PRs or learning opportunities:
1. Schedule 30-minute review session
2. Screen share the code
3. Walk through together
4. Discuss alternatives
5. Both learn something

Benefits:
- Faster feedback
- Knowledge transfer
- Team bonding
- Better understanding

Quality Standards

Review Checklist

Functional Correctness

- [ ] Does it do what it's supposed to?
- [ ] Are edge cases handled?
- [ ] Is error handling appropriate?
- [ ] Are inputs validated?

Code Quality

- [ ] Follows coding standards
- [ ] Methods are single-purpose
- [ ] Variables are well-named
- [ ] No code duplication
- [ ] No magic numbers/strings

Architecture

- [ ] Follows established patterns
- [ ] Proper dependency injection
- [ ] Uses interfaces appropriately
- [ ] Follows SOLID principles

Performance

- [ ] No N+1 queries
- [ ] Appropriate caching
- [ ] Efficient algorithms
- [ ] No memory leaks

Security

- [ ] Input sanitization
- [ ] SQL injection prevention
- [ ] XSS protection
- [ ] CSRF tokens
- [ ] Authorization checks

Testing

- [ ] Unit tests included
- [ ] Edge cases tested
- [ ] Tests are meaningful
- [ ] No flaky tests

Magento Specific

- [ ] Service contracts used
- [ ] Plugins for extension
- [ ] Events for decoupling
- [ ] Cache tags configured
- [ ] Queue for async operations

Feedback Delivery

Constructive Feedback Framework

SBI Model

Situation: What happened
Behavior: What you observed
Impact: Why it matters

Example:
"In the OrderService class (situation), I noticed the method 
 accesses ObjectManager directly (behavior). This makes the code 
 hard to test and violates dependency injection principles (impact)."

Feedback Levels

Level 1: Nit (style, optional)
"Nit: Consider using early return for readability"

Level 2: Suggestion (improvement)
"Suggestion: This could be simplified with array_map"

Level 3: Request (should change)
"Please add error handling here - this can fail in production"

Level 4: Block (must change)
"Blocking: This introduces a security vulnerability"

Phrasing Examples

// Instead of "This is wrong"
"I think there might be an issue here because [reason]. 
 What about [alternative]?"

// Instead of "You always..."
"I've noticed in several PRs that [pattern]. 
 Let's discuss the best approach."

// Instead of "This is obvious"
"To clarify for future readers, [explanation]."

// Instead of "Just do X"
"Have you considered [alternative]? It might be better because [reason]."

Handling Disagreements

If reviewer and author disagree:

1. Both state their position
2. Reference documentation/ADRs
3. If still unresolved, escalate to tech lead
4. Document decision in ADR
5. Move forward without resentment

Key: Disagreement is healthy. It means we care about quality.

Review Metrics

Track to improve process:
- Average review turnaround
- Comments per PR
- PRs requiring re-review
- Bugs caught in review vs production
- Developer satisfaction scores

Goal: More learning, fewer bugs, faster delivery

Practice Problems

0 / 2 solved
Review Practice

Review a Magento pull request containing common issues and provide constructive feedback using the SBI model.

Review Standards

Create a code review checklist specific to a Magento project with clear criteria for each item.

Quiz

1. What is the goal of code review culture?

Question 1 options

2. What is the SBI model?

Question 2 options

3. What feedback level means 'must change'?

Question 3 options

4. What is the recommended PR review turnaround?

Question 4 options

Flashcards

Question

What is code review culture?

Answer

An environment where reviews improve code and team knowledge, not judge people

Question

What is SBI model?

Answer

Situation-Behavior-Impact framework for constructive feedback

Question

What are feedback levels?

Answer

Nit (style), Suggestion (improvement), Request (should change), Block (must change)

Question

What is target PR review time?

Answer

4 hours for regular PRs, 2 hours for critical fixes

Question

How to handle review disagreements?

Answer

State positions, reference docs/ADRs, escalate if needed, document decision

Revision Notes

Key Takeaways

  • 1. Build psychological safety - reviews improve code, not judge people
  • 2. Use 4-level teaching: point out, explain why, suggest solution, link resources
  • 3. SBI model: Situation-Behavior-Impact for constructive feedback
  • 4. Feedback levels: Nit, Suggestion, Request, Block
  • 5. Review checklist: functional, quality, architecture, performance, security, testing
  • 6. Track metrics: turnaround, comments, bugs caught, developer satisfaction

Interview Tips

  • How do you build a positive code review culture?
  • Describe your approach to mentoring through code reviews
  • How do you handle disagreements during code review?
  • What does your code review checklist include?
  • How do you measure code review effectiveness?

Cheat Sheet

Code Review Leadership Cheat Sheet

Culture:

  • Psychological safety
  • Reviews improve code, not judge people
  • Knowledge sharing opportunity

Teaching Levels:

  1. Point out issue
  2. Explain why
  3. Suggest solution
  4. Link resources

Feedback (SBI):

  • Situation: what happened
  • Behavior: what you observed
  • Impact: why it matters

Levels:

  • Nit: style (optional)
  • Suggestion: improvement
  • Request: should change
  • Block: must change

Metrics:

  • Turnaround: 4 hours
  • Track bugs caught
  • Developer satisfaction