Slide 1

Slide 1 text

Managing Code Quality and Code Consistency Juliette Reinders Folmer

Slide 2

Slide 2 text

“ Only half of programming is coding. The other 90% is debugging.

Slide 3

Slide 3 text

hotblack

Slide 4

Slide 4 text

Functional Technical Architectural Conceptual

Slide 5

Slide 5 text

Importance Conceptual Architectural Functional Technical

Slide 6

Slide 6 text

Attention Conceptual Architectural Functional Technical

Slide 7

Slide 7 text

Pull request Merged ... typo in documentation ... ... whitespace ... ... please add some tests ... ... is situation x handled ... ... use early return ... ... using PHP 8.0 syntax ... ... use strict checking in your tests ...

Slide 8

Slide 8 text

Pull request Merged ... please add some tests ... ... is situation x handled ...

Slide 9

Slide 9 text

Marnhe du Plooy

Slide 10

Slide 10 text

Psalm CS- Fixer PHP Stan PHP CS Exakat PHP CPD PHP Insights PHP MD Phan Rector PHP DCD Static Analysis Tools PHP MND

Slide 11

Slide 11 text

PHP CS Static Analysis Tools

Slide 12

Slide 12 text

Jon Ng Getting Started with PHP_CodeSniffer

Slide 13

Slide 13 text

Phar Composer Git clone PEAR Installation

Slide 14

Slide 14 text

Running PHP_CodeSniffer phpcs /path/to/code –-standard=StandardName -p (show progress) -s (show source/errorcodes) -l (local, do not recurse into subdirs) -n (no warnings) -vvv (verbosity) -i (show installed standards) -h (help, shows lots more options)

Slide 15

Slide 15 text

Fixing errors phpcs /path/to/code –-standard=StandardName phpcbf /path/to/code –-standard=StandardName

Slide 16

Slide 16 text

Which Standard Will Be Used ? Command line .phpcs.xml phpcs.xml .phpcs.xml.dist phpcs.xml.dist --standard=Standard --standard=myrules.xml

Slide 17

Slide 17 text

Standard: ruleset.xml .phpcs.xml.dist • Can add new sniffs • Can be used by name when registered with PHPCS

Slide 18

Slide 18 text

Brief (Re-)Introduction to PHP_CodeSniffer Nightsabre

Slide 19

Slide 19 text

How It Works Standard (ruleset) Sniffs Checks (errorcodes)

Slide 20

Slide 20 text

Standard Standard A Standard B Standard A Standard B Standard A Standard B

Slide 21

Slide 21 text

Standard.Subset.Sniff.ErrorCode Standard.Subset.Sniff.ErrorCode Standard.Subset.Sniff.ErrorCode Standard.Subset.Sniff.ErrorCode

Slide 22

Slide 22 text

Standard.Subset.Sniff.ErrorCode Include: Exclude: ~~~~~~~~

Slide 23

Slide 23 text

. */vendor/* */tests/* Standard A Standard B

Slide 24

Slide 24 text

Customizing Sniffs

Slide 25

Slide 25 text

. phpcs . -p –s --report=summary --extensions= php,inc,js,css,lib/php -d memory_limit=128M --parallel=8 (PHPCS 3+)

Slide 26

Slide 26 text

elvis santana Choose Your Poison

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

JS CSS PHP (+ inc)

Slide 29

Slide 29 text

Code Style Documentation Code Smells Code Metrics Best Practices Code Compatibility

Slide 30

Slide 30 text

PHPCS Build-in Standards PEAR PSR1 PSR2 Zend MySource Squiz PSR12 Generic

Slide 31

Slide 31 text

Framework/CMS Standards Laravel Joomla Symfony2 CodeIgniter4 Drupal Magento WordPress MediaWiki Zend Framework (WebImpress) TYPO3 Yii CakePHP

Slide 32

Slide 32 text

Functional Standards and Sniff Collections Object Calisthenics Variable Analysis Universal Slevomat Cognitive Complexity PHP Compatibility Import Detection Security Audit Normalized Arrays PHPCSExtra

Slide 33

Slide 33 text

Recognizing External Standards jeltovski

Slide 34

Slide 34 text

Registering External Standards [1] phpcs --config-set installed_paths /path/to/dir/above/standard phpcs --config-show phpcs --config-set installed_paths /path/to/dir/above/standard1,/path/to/dir/above/standard2

Slide 35

Slide 35 text

Registering External Standards [2] composer require –-dev dealerdirect/phpcodesniffer-composer-installer

Slide 36

Slide 36 text

Tips and Tricks kenbrasier

Slide 37

Slide 37 text

Explain

Slide 38

Slide 38 text

phpcs --standard=PSR12 --generator=Text (Markdown|HTML)

Slide 39

Slide 39 text

Seemann

Slide 40

Slide 40 text

Report Types diff code svnblame gitblame emacs xml checkstyle source full summary info csv json junit

Slide 41

Slide 41 text

Interactive Mode

Slide 42

Slide 42 text

--filter=GitModified --filter=GitStaged

Slide 43

Slide 43 text

Boni Idem Ignoring Issues

Slide 44

Slide 44 text

Handling Rule Exceptions // phpcs:ignore Stnd.Cat.Sniff.ErrorCode // phpcs:disable StndA,StndB.Cat.Sniff -- for reasons ... ... // phpcs:enable // phpcs:ignoreFile

Slide 45

Slide 45 text

--ignore-annotations

Slide 46

Slide 46 text

Links ✓ PHP_CodeSniffer https://github.com/squizlabs/PHP_CodeSniffer ✓ Find External Standards on Packagist https://packagist.org/?query=phpcs&type=phpcodesniffer-standard https://packagist.org/?query=php_codesniffer&type=phpcodesniffer-standard ✓ DealerDirect Composer PHPCS plugin https://github.com/Dealerdirect/phpcodesniffer-composer-installer ✓ PHPCSDevTools, PHPCSUtils, PHPCSExtra, PHPCompatibility et al https://github.com/PHPCSStandards https://github.com/PHPCompatibility

Slide 47

Slide 47 text

Questions ? Clodiney Cruz

Slide 48

Slide 48 text

Thanks! Slides: https://speakerdeck.com/jrf Follow me: https://twitter.com/jrf_nl https://github.com/jrfnl