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 Include: Exclude: ~~~~~~~~

Slide 22

Slide 22 text

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

Slide 23

Slide 23 text

Customizing Sniffs

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

elvis santana Choose Your Poison

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

JS CSS PHP (+ inc)

Slide 28

Slide 28 text

Code Style Documentation Code Smells Code Metrics Best Practices Code Compatibility

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

Recognizing External Standards jeltovski

Slide 33

Slide 33 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 34

Slide 34 text

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

Slide 35

Slide 35 text

Tips and Tricks kenbrasier

Slide 36

Slide 36 text

Explain

Slide 37

Slide 37 text

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

Slide 38

Slide 38 text

Seemann

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

Interactive Mode

Slide 41

Slide 41 text

--filter=GitModified --filter=GitStaged

Slide 42

Slide 42 text

Boni Idem Ignoring Issues

Slide 43

Slide 43 text

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

Slide 44

Slide 44 text

--ignore-annotations

Slide 45

Slide 45 text

Maintaining PHP_CodeSniffer and Standards

Slide 46

Slide 46 text

Typical Tasks Coaching New Features PHP+ CI/QA

Slide 47

Slide 47 text

Keeping up with PHP ❑ Fix deprecation notices & errors (runtime compatible) ❑ Add support for new syntaxes to the PHPCS Tokenizer (PHP 5.4+) ❑ Add support to utility functions ❑ Update existing sniffs to support new features (feature compatible) ❑ Create new sniffs related to new features

Slide 48

Slide 48 text

Architecture of External Standards PHP_CodeSniffer PHPCSUtils PHPCompatibility PHPCSExtra WordPressCS ??

Slide 49

Slide 49 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/PHPCSStandards/composer-installer ✓ PHPCSDevTools, PHPCSUtils, PHPCSExtra, PHPCompatibility et al https://github.com/PHPCSStandards https://github.com/PHPCompatibility

Slide 50

Slide 50 text

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