A presentation at CakeFest Online 2021 by Christopher Miller
Our Standards And Why We Use Them
Developer at Jump 24 Working with Laravel and CakePHP using TDD WHO AM I? WHAT AM I DOING HERE? Twitter: ccmiller2018 Email: chris@jump24.co.uk Website: jump24.co.uk WE ARE RECRUITING ACROSS THE BOARD REMOTE POSITIONS, MUST BE UK RESIDENT
Why Do We Need Standards? W E H AV E A L O T O F S Y S T E M S W E U S E !
What Is Our Stack? • CakePHP • Sass • Terraform • MySQL • AWS • Redis • PHP • HTML5 • Nginx • CSS3 • Laravel • Javascript • Inertia • Webpack • React • Docker
Key Takeaway STAN D ARD S H E L P - T H EY E NABL E D EVE LO PE R S T O W O RK T O GET H E R BET T E R - SI M PL I F I E S C O D E REVIEW - KEEPS CODE CONSISTENT ACROSS PROJECTS
PHP T H E S TA N D A R D S W E A P P LY
PHP Standards Are Our Centrepiece • Linter • ECS • PHPStan • Tests Everything we do is thought in terms of the “hit by a bus” scenario If a developer were not available tomorrow, could someone else pick up their work?
Linter NOT JUST MAKING IT PRETTY
A Bad Code Example <?php const MY_MESSAGE = ‘something’ function echoMe() { echo (MY_MESSAGE) echo ($otherMessage); } At First Glance This Looks Ok • But there are errors here • Quite a few of them
Our Code Fails To Execute
Bringing In Some Packages “require dev”: { “php parallel lint/php console highlighter”: “^0.5.0”, “php parallel lint/php parallel lint”: “^1.3” }, “scripts”: { “lint”: [ “vendor/bin/parallel lint ./ blame exclude vendor” ] } Two Packages And A Script • Run Composer Install • Run Composer Lint
Now We Can See Whats Wrong
Our Code Fixed <?php const MY_MESSAGE = ‘something’; function echoMe(string $otherMessage) { echo (MY_MESSAGE); echo ($otherMessage); } echoMe(‘else’);
Our Code Executes
Use Our Standards Packages N O W W E S TA RT T O E N F O R C E O U R PA RT I C U L A R C O D I N G S T Y L E
Bringing In All The Packages We Need “require dev”: { “jumptwentyfour/php coding standards”: “^0.0.1”, “jumptwentyfour/project analysers”: “^0.0.2”, “php parallel lint/php console highlighter”: “^0.5.0”, “php parallel lint/php parallel lint”: “^1.3”, },
And The Scripts “scripts”: { “lint”: [ “vendor/bin/parallel lint ./ blame exclude vendor” ], “ecs”: [ “vendor/bin/ecs check” ], “static”: [ “vendor/bin/phpstan analyse memory limit=2G” ], “test”: [ “vendor/bin/pest parallel” ], }
Now A PHPStan.neon le includes: - ./vendor/jumptwentyfour/php coding standards/phpstan.neon - ./phpstan baseline.neon parameters: # The level 8 is the highest level level: 8 excludePaths: - ‘vendor ’ - ‘_ide_helper.php’ - ‘_ide_helper_models.php’ - ‘.phpstorm.meta.php’ checkMissingIterableValueType: false AND DONT FORGET A BLANK PHPSTAN-BASELINE.NEON FILE
And ECS.php <?php use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; use Symplify\EasyCodingStandard\ValueObject\Option; return static function (ContainerConfigurator $containerConfigurator) void { $containerConfigurator import( DIR . ‘/vendor/jumptwentyfour/php coding standards/ecs.php’); $parameters = $containerConfigurator parameters(); $parameters set(Option PATHS, [ DIR . ‘/app’, DIR . ‘/tests’, ]); };
So What Are We Using Here? L I N T I N G , S TAT I C A N A LY S I S , C O D I N G S TA N D A R D S
Why Linting? IT HIGHLIGHTS CODE ERRORS
Why ECS? I T A L L O W S U S T O E N S U R E O U R S TA N D A R D S F O R C O D E A R E M E T, E X T E N D I N G T H I S E A S I LY, A N D AL LOW S FO R I N - E D I T O R H I GH L I GH T I N G O F OU R C U ST OM STAN D ARD S
What Standards Do We Apply? P SR - 1 2 AN D RE L AT E D O T H E R STAN D ARD S , S OM E E X T E RNAL STAN D ARD S SU C H A S S QU I Z L AB S , A S WELL AS SOME OF OUR OWN
Why PHPStan? I T I N T E G R AT E S B ET T E R , A L L O W S F O R S TAT I C A N A LY S I S , H E L P S T O S T R E N GT H E N O U R C O D E
Lets Try This Out WH AT C OUL D G O WRO NG WI T H L IVE C O D E!
This Is Only A Part Of Our Standards We have standards that apply to every single part of our stack. Over time these standards have evolved to cover not just how we code, but how we estimate, how we present to clients, how we manage our projects and almost every other part of our business
View Our Standards And Why We Use Them - CakePHP Version on Notist.
Dismiss
The following code examples from the presentation can be tried out live.
The Repo for the CakePHP Talk
Here’s what was said about this presentation on social media.
🍰 #CakeFest 2021 - UpdateLet’s talk standards with Chris Miller, and why we use them. Talking now is @ccmiller2018 💻— CakePHP (@cakephp) October 8, 2021
🍰 #CakeFest 2021 - UpdateLet’s talk standards with Chris Miller, and why we use them. Talking now is @ccmiller2018 💻