Slide 1

Slide 1 text

What are Coding Standards in PHP? by Gabriel Caruso phpDay 2019

Slide 2

Slide 2 text

Who am I? ● Backend Developer at Leroy Merlin ● PHP enthusiastic ● PHPSP member ● OSS contributor ● Refactor/Stickers/ELEPHANTS lover

Slide 3

Slide 3 text

What are Coding Standards?

Slide 4

Slide 4 text

Code - Organization - Writing - Visual

Slide 5

Slide 5 text

Team - Automation - Agile - Standards

Slide 6

Slide 6 text

Why should your team have a Coding Standards?

Slide 7

Slide 7 text

- Ensure patterns - Code focusing in business logic - Speed up Code Review

Slide 8

Slide 8 text

What are the differences between Coding Standards, Code Design and Code Style?

Slide 9

Slide 9 text

Coding Standards Ensure the standardization of common patterns in the code. doctrine/coding-standard

Slide 10

Slide 10 text

Code Design Is a pattern, that might affect some logics. Strict Programming

Slide 11

Slide 11 text

Code Style The design of the code.

Slide 12

Slide 12 text

PSRs and PHP-FIG

Slide 13

Slide 13 text

How to ensure these standards?

Slide 14

Slide 14 text

Code Standards tools - PHP-CS-Fixer - PHP_CodeSniffer

Slide 15

Slide 15 text

Differences PHP-CS-Fixer ● Fixers ● Only work fixing code ● Array syntax to configure ● Focus only in Coding Standards ● Easy to create Fixers PHP_CodeSniffer ● Linters ● Can only alert without fixing ● XML syntax to configure ● Flexible for Code Design and Mess Detector ● Harder to create Sniffs

Slide 16

Slide 16 text

Continuous Integration - A step in the CI tool to report any fail - Git hooks to avoid commits with fails

Slide 17

Slide 17 text

How this affects your Git history?

Slide 18

Slide 18 text

Git - Git blame can be overwritten - Git bisect reports false-positives - Creates unnecessary “fix cs” commits

Slide 19

Slide 19 text

How to implement a new Coding Standards in PHP?

Slide 20

Slide 20 text

Roadmap Coding Standards First step, not changing any logic Strict Programming Helps to define the strict code style PHP 7 Scalar Type Hints Review your codebase to avoid false-positives Strict types Last step, closing the circle

Slide 21

Slide 21 text

@carusogabriel Questionings? Thank you ♡