SlideShare a Scribd company logo
Code Quality with Magento 2
April 30th 2020 – Virtual Meet Magento Meetup #2
Andreas von Studnitz – integer_net – @avstudnitz
Co-Founder and Managing Director @ integer_net
Magento Developer, Trainer, Consultant
since 2008
Twitter: @avstudnitz
Andreas von Studnitz
Andreas von Studnitz – integer_net – @avstudnitz
2014
Image
Quality
Andreas von Studnitz – integer_net – @avstudnitz
2020
Code
Quality
Andreas von Studnitz – integer_net – @avstudnitz
Agenda
Magento-Specific Code Quality
Questions and Answers
General Code Quality
Tools for better Code Quality
Motivation
Andreas von Studnitz – integer_net – @avstudnitz
For developers
◦ Code is easy to read
◦ Easy to understand
◦ Easy to adapt
◦ Easy to extend
What is code quality good for?
For customers
• Fewer Bugs
• Reliability
• Security
• Updatability
• Less expensive long-term
General Code Quality
(independent of M2)
Andreas von Studnitz – integer_net – @avstudnitz
Soft Factors
• Code Reviews
• Working Hours
• Pair Programming
• Code Reviews
Andreas von Studnitz – integer_net – @avstudnitz
Keep it simple
• Minimal amount of LoC for demand – „only no code is
good code“
• Use existing functions: Generate price rules instead of
overwriting price logic
• Not going to break on an update
• Not going to show wrong VAT with tax included
• Not going to break on a credit memo
• Avoid unnecessary abstraction
“
Andreas von Studnitz – integer_net – @avstudnitz
“Debugging is twice as hard as
writing the code in the first place.
Therefore, if you write the code as
cleverly as possible, you are, by
definition, not smart enough to
debug it.”
- Brian Kernighan
Andreas von Studnitz – integer_net – @avstudnitz
Literature
Magento-specific
Code Quality
Andreas von Studnitz – integer_net – @avstudnitz
Updatability
• No core hacks, no hacks of external modules
• No changes of PHP classes
 Instead: Observer, Plugin or Preference
• No changes of template files
 Instead: Make a theme specific copy, or better use Layout XML
• No changes of language files
 Instead: Custom translation files, possibly in own language pack
Andreas von Studnitz – integer_net – @avstudnitz
From MVC to MVVM
• Model – View – ViewModel
• ViewModels provide data for the View
• PHP Classes which don’t need to inherit or implement
anything
• Read more: https://www.integer-net.com/view-models-
in-magento-1-and-2/
(by Fabian Schmengler)
Andreas von Studnitz – integer_net – @avstudnitz
An Example of View Models
module-catalog/view/frontend/layout/catalog_product_view.xml
module-catalog/view/frontend/templates/product/breadcrumbs.phtml
Andreas von Studnitz – integer_net – @avstudnitz
Configuration as Code
• Store configuration in the config.php and/or env.php
• bin/magento config:set --lock-config
• bin/magento config:set --lock-env
• Since Magento 2.2.4
• Can create websites and stores
• Can set store specific values
Andreas von Studnitz – integer_net – @avstudnitz
Example
Andreas von Studnitz – integer_net – @avstudnitz
Configuration: Suggestions
• config.php is for sharing
• Should contain everything you want to have control over
• Don’t add everything – some things are better kept in config.xml
• env.php is local only
• Add your base URLs
• Adjust security settings
• Disable services like Google Analytics
• Adjust payment methods and other sensitive data by environment
Andreas von Studnitz – integer_net – @avstudnitz
Setup Patches
• More “Configuration as Code” – don’t use the Magento
Admin for crucial changes
• Successor of Setup Scripts (since Magento 2.3)
• Attributes
• Content (CMS, categories, products, …)
• Accompanied by Declarative Schema for adjusting the
database schema
Andreas von Studnitz – integer_net – @avstudnitz
A Setup Patch
Tools for better Code
Quality with Magento 2
Andreas von Studnitz – integer_net – @avstudnitz
Automated Testing
• Huge improvement of M2 over M1
• In M1 automated testing not cost-effective in most mid-size cases
• In M2 automated testing is now cost effective in most mid-size
cases
• Different types of testing:
• Unit Tests
• Integration Tests
• Frontend Tests (MFTF)
Andreas von Studnitz – integer_net – @avstudnitz
Integration Tests
class NewProductsCategoryTest extends MagentoTestFrameworkTestCaseAbstractControlle
{
public static function loadFixture()
{
include __DIR__ . '/../_files/categories.php';
include __DIR__ . '/../_files/products.php';
}
public function testCategoryDisplaysCorrectProducts()
{
$this->dispatch('catalog/category/view/id/3');
$this->assertContains('Simple Product 1', $this->getResponse()->getBody());
$this->assertNotContains('Simple Product 2', $this->getResponse()->getBody());
}
}
• Hint: use https://github.com/tddwizard/magento2-fixtures
Andreas von Studnitz – integer_net – @avstudnitz
Static Tests
• Check the code with tools like PHP Codesniffer and PHP
Mess Detector
• Automate with GrumPhp: Code will be checked on
commit
• Only a few steps to setup
• Example:
Andreas von Studnitz – integer_net – @avstudnitz
Static Tests
• Check the code with tools like PHP Codesniffer and PHP
Mess Detector
• Automate with GrumPhp: Code will be checked on
commit
• Only a few steps to setup
• Example:
Andreas von Studnitz – integer_net – @avstudnitz
Static Tests
• Check the code with tools like PHP Codesniffer and PHP
Mess Detector
• Automate with GrumPhp: Code will be checked on
commit
• Only a few steps to setup
• Example:
#MM18DE
Installation of GrumPhp (1)
#MM18DE
Installation of GrumPhp (2)
grumphp.yml in project root directory
Andreas von Studnitz – integer_net – @avstudnitz
„The Obvious“
• Git for source code management and versioning
• Composer for managing dependencies
• PhpStorm
• See warnings and errors directly
• Easily integrate tools like Code Sniffer and Mess Detector
• Built-in commands for code formatting and small refactorings
Thank you!
Any Questions?
avs@integer-net.de
@avstudnitz
@integer_net
Presentation Template by SlidesCarnival

More Related Content

Similar to Code Quality with Magento 2

Beginners - Get Started With Unit Testing in .NET
Beginners - Get Started With Unit Testing in .NETBeginners - Get Started With Unit Testing in .NET
Beginners - Get Started With Unit Testing in .NET
Baskar K
 
Introduction to Integration Tests in Magento / Adobe Commerce
Introduction to Integration Tests in Magento / Adobe CommerceIntroduction to Integration Tests in Magento / Adobe Commerce
Introduction to Integration Tests in Magento / Adobe Commerce
Bartosz Górski
 
Introduction to Integration Tests in Magento / Adobe Commerce
Introduction to Integration Tests in Magento / Adobe CommerceIntroduction to Integration Tests in Magento / Adobe Commerce
Introduction to Integration Tests in Magento / Adobe Commerce
Bartosz Górski
 
Software Development : Jeremy Gleason Iscope Digital
Software Development : Jeremy Gleason Iscope DigitalSoftware Development : Jeremy Gleason Iscope Digital
Software Development : Jeremy Gleason Iscope Digital
Iscope Digital
 
agile with scrum methodology
agile with scrum methodology agile with scrum methodology
agile with scrum methodology
rahul reddy
 
Case Study - AMR Test Automation
Case Study - AMR Test AutomationCase Study - AMR Test Automation
Case Study - AMR Test Automation
iFocusSystec
 
V model Over View (Software Engineering)
V model Over View (Software Engineering) V model Over View (Software Engineering)
V model Over View (Software Engineering)
Badar Rameez. CH.
 
V model Over view (Software Engineering)
V model Over view (Software Engineering)V model Over view (Software Engineering)
V model Over view (Software Engineering)
Badar Rameez. CH.
 
Magento 2 Best Practice Workfow // David Lambauer // Meet Magento 2017 // Lei...
Magento 2 Best Practice Workfow // David Lambauer // Meet Magento 2017 // Lei...Magento 2 Best Practice Workfow // David Lambauer // Meet Magento 2017 // Lei...
Magento 2 Best Practice Workfow // David Lambauer // Meet Magento 2017 // Lei...
AOE
 
Madison PHP - Getting Started with Magento 2
Madison PHP - Getting Started with Magento 2Madison PHP - Getting Started with Magento 2
Madison PHP - Getting Started with Magento 2
Mathew Beane
 
(Re)inventing software development productivity
(Re)inventing software development productivity(Re)inventing software development productivity
(Re)inventing software development productivity
Peter Hendriks
 
WDS trainer presentation - MLOps.pptx
WDS trainer presentation - MLOps.pptxWDS trainer presentation - MLOps.pptx
WDS trainer presentation - MLOps.pptx
Arthur240715
 
Training: MVVM Pattern
Training: MVVM PatternTraining: MVVM Pattern
Training: MVVM Pattern
Betclic Everest Group Tech Team
 
Meet Magento Spain 2019 - Our Experience with Magento Cloud
Meet Magento Spain 2019 - Our Experience with Magento CloudMeet Magento Spain 2019 - Our Experience with Magento Cloud
Meet Magento Spain 2019 - Our Experience with Magento Cloud
Lyzun Oleksandr
 
Expert guidance on migrating from magento 1 to magento 2
Expert guidance on migrating from magento 1 to magento 2Expert guidance on migrating from magento 1 to magento 2
Expert guidance on migrating from magento 1 to magento 2
James Cowie
 
Udvid din test portefølje med coded ui test og cloud load test
Udvid din test portefølje med coded ui test og cloud load testUdvid din test portefølje med coded ui test og cloud load test
Udvid din test portefølje med coded ui test og cloud load test
Peter Lindberg
 
Blending Realized Code
Blending Realized CodeBlending Realized Code
Blending Realized Code
Pathfinder Solutions
 
Moodle Development Best Pracitces
Moodle Development Best PracitcesMoodle Development Best Pracitces
Moodle Development Best Pracitces
Justin Filip
 
MidoNet roadmap
MidoNet roadmapMidoNet roadmap
MidoNet roadmap
Jean-Francois Joly
 
MidoNet Vision & Roadmap
MidoNet Vision & RoadmapMidoNet Vision & Roadmap
MidoNet Vision & Roadmap
MidoNet
 

Similar to Code Quality with Magento 2 (20)

Beginners - Get Started With Unit Testing in .NET
Beginners - Get Started With Unit Testing in .NETBeginners - Get Started With Unit Testing in .NET
Beginners - Get Started With Unit Testing in .NET
 
Introduction to Integration Tests in Magento / Adobe Commerce
Introduction to Integration Tests in Magento / Adobe CommerceIntroduction to Integration Tests in Magento / Adobe Commerce
Introduction to Integration Tests in Magento / Adobe Commerce
 
Introduction to Integration Tests in Magento / Adobe Commerce
Introduction to Integration Tests in Magento / Adobe CommerceIntroduction to Integration Tests in Magento / Adobe Commerce
Introduction to Integration Tests in Magento / Adobe Commerce
 
Software Development : Jeremy Gleason Iscope Digital
Software Development : Jeremy Gleason Iscope DigitalSoftware Development : Jeremy Gleason Iscope Digital
Software Development : Jeremy Gleason Iscope Digital
 
agile with scrum methodology
agile with scrum methodology agile with scrum methodology
agile with scrum methodology
 
Case Study - AMR Test Automation
Case Study - AMR Test AutomationCase Study - AMR Test Automation
Case Study - AMR Test Automation
 
V model Over View (Software Engineering)
V model Over View (Software Engineering) V model Over View (Software Engineering)
V model Over View (Software Engineering)
 
V model Over view (Software Engineering)
V model Over view (Software Engineering)V model Over view (Software Engineering)
V model Over view (Software Engineering)
 
Magento 2 Best Practice Workfow // David Lambauer // Meet Magento 2017 // Lei...
Magento 2 Best Practice Workfow // David Lambauer // Meet Magento 2017 // Lei...Magento 2 Best Practice Workfow // David Lambauer // Meet Magento 2017 // Lei...
Magento 2 Best Practice Workfow // David Lambauer // Meet Magento 2017 // Lei...
 
Madison PHP - Getting Started with Magento 2
Madison PHP - Getting Started with Magento 2Madison PHP - Getting Started with Magento 2
Madison PHP - Getting Started with Magento 2
 
(Re)inventing software development productivity
(Re)inventing software development productivity(Re)inventing software development productivity
(Re)inventing software development productivity
 
WDS trainer presentation - MLOps.pptx
WDS trainer presentation - MLOps.pptxWDS trainer presentation - MLOps.pptx
WDS trainer presentation - MLOps.pptx
 
Training: MVVM Pattern
Training: MVVM PatternTraining: MVVM Pattern
Training: MVVM Pattern
 
Meet Magento Spain 2019 - Our Experience with Magento Cloud
Meet Magento Spain 2019 - Our Experience with Magento CloudMeet Magento Spain 2019 - Our Experience with Magento Cloud
Meet Magento Spain 2019 - Our Experience with Magento Cloud
 
Expert guidance on migrating from magento 1 to magento 2
Expert guidance on migrating from magento 1 to magento 2Expert guidance on migrating from magento 1 to magento 2
Expert guidance on migrating from magento 1 to magento 2
 
Udvid din test portefølje med coded ui test og cloud load test
Udvid din test portefølje med coded ui test og cloud load testUdvid din test portefølje med coded ui test og cloud load test
Udvid din test portefølje med coded ui test og cloud load test
 
Blending Realized Code
Blending Realized CodeBlending Realized Code
Blending Realized Code
 
Moodle Development Best Pracitces
Moodle Development Best PracitcesMoodle Development Best Pracitces
Moodle Development Best Pracitces
 
MidoNet roadmap
MidoNet roadmapMidoNet roadmap
MidoNet roadmap
 
MidoNet Vision & Roadmap
MidoNet Vision & RoadmapMidoNet Vision & Roadmap
MidoNet Vision & Roadmap
 

More from Andreas von Studnitz

Successful projects with Hyvä - The impact of Developer Happiness
Successful projects with Hyvä - The impact of Developer HappinessSuccessful projects with Hyvä - The impact of Developer Happiness
Successful projects with Hyvä - The impact of Developer Happiness
Andreas von Studnitz
 
Vorstellung Hyvä: Modernes Frontend mit Magento 2
Vorstellung Hyvä: Modernes Frontend mit Magento 2Vorstellung Hyvä: Modernes Frontend mit Magento 2
Vorstellung Hyvä: Modernes Frontend mit Magento 2
Andreas von Studnitz
 
Dependency Injection Extended: the way to advanced Magento 2 development
Dependency Injection Extended: the way to advanced Magento 2 developmentDependency Injection Extended: the way to advanced Magento 2 development
Dependency Injection Extended: the way to advanced Magento 2 development
Andreas von Studnitz
 
Magento Audit - anonymisiert (German)
Magento Audit - anonymisiert (German)Magento Audit - anonymisiert (German)
Magento Audit - anonymisiert (German)
Andreas von Studnitz
 
Was kann denn schon passieren? Sicherheit in Magento-Shops
Was kann denn schon passieren? Sicherheit in Magento-ShopsWas kann denn schon passieren? Sicherheit in Magento-Shops
Was kann denn schon passieren? Sicherheit in Magento-Shops
Andreas von Studnitz
 
What could possibly go wrong? Security in Magento Shops
What could possibly go wrong? Security in Magento ShopsWhat could possibly go wrong? Security in Magento Shops
What could possibly go wrong? Security in Magento Shops
Andreas von Studnitz
 

More from Andreas von Studnitz (6)

Successful projects with Hyvä - The impact of Developer Happiness
Successful projects with Hyvä - The impact of Developer HappinessSuccessful projects with Hyvä - The impact of Developer Happiness
Successful projects with Hyvä - The impact of Developer Happiness
 
Vorstellung Hyvä: Modernes Frontend mit Magento 2
Vorstellung Hyvä: Modernes Frontend mit Magento 2Vorstellung Hyvä: Modernes Frontend mit Magento 2
Vorstellung Hyvä: Modernes Frontend mit Magento 2
 
Dependency Injection Extended: the way to advanced Magento 2 development
Dependency Injection Extended: the way to advanced Magento 2 developmentDependency Injection Extended: the way to advanced Magento 2 development
Dependency Injection Extended: the way to advanced Magento 2 development
 
Magento Audit - anonymisiert (German)
Magento Audit - anonymisiert (German)Magento Audit - anonymisiert (German)
Magento Audit - anonymisiert (German)
 
Was kann denn schon passieren? Sicherheit in Magento-Shops
Was kann denn schon passieren? Sicherheit in Magento-ShopsWas kann denn schon passieren? Sicherheit in Magento-Shops
Was kann denn schon passieren? Sicherheit in Magento-Shops
 
What could possibly go wrong? Security in Magento Shops
What could possibly go wrong? Security in Magento ShopsWhat could possibly go wrong? Security in Magento Shops
What could possibly go wrong? Security in Magento Shops
 

Recently uploaded

办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
uehowe
 
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
xjq03c34
 
Ready to Unlock the Power of Blockchain!
Ready to Unlock the Power of Blockchain!Ready to Unlock the Power of Blockchain!
Ready to Unlock the Power of Blockchain!
Toptal Tech
 
国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理
国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理
国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理
zoowe
 
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
vmemo1
 
Design Thinking NETFLIX using all techniques.pptx
Design Thinking NETFLIX using all techniques.pptxDesign Thinking NETFLIX using all techniques.pptx
Design Thinking NETFLIX using all techniques.pptx
saathvikreddy2003
 
Gen Z and the marketplaces - let's translate their needs
Gen Z and the marketplaces - let's translate their needsGen Z and the marketplaces - let's translate their needs
Gen Z and the marketplaces - let's translate their needs
Laura Szabó
 
不能毕业如何获得(USYD毕业证)悉尼大学毕业证成绩单一比一原版制作
不能毕业如何获得(USYD毕业证)悉尼大学毕业证成绩单一比一原版制作不能毕业如何获得(USYD毕业证)悉尼大学毕业证成绩单一比一原版制作
不能毕业如何获得(USYD毕业证)悉尼大学毕业证成绩单一比一原版制作
bseovas
 
Should Repositories Participate in the Fediverse?
Should Repositories Participate in the Fediverse?Should Repositories Participate in the Fediverse?
Should Repositories Participate in the Fediverse?
Paul Walk
 
Discover the benefits of outsourcing SEO to India
Discover the benefits of outsourcing SEO to IndiaDiscover the benefits of outsourcing SEO to India
Discover the benefits of outsourcing SEO to India
davidjhones387
 
一比一原版(USYD毕业证)悉尼大学毕业证如何办理
一比一原版(USYD毕业证)悉尼大学毕业证如何办理一比一原版(USYD毕业证)悉尼大学毕业证如何办理
一比一原版(USYD毕业证)悉尼大学毕业证如何办理
k4ncd0z
 
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
fovkoyb
 
制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理
制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理
制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理
cuobya
 
快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
3a0sd7z3
 
Azure EA Sponsorship - Customer Guide.pdf
Azure EA Sponsorship - Customer Guide.pdfAzure EA Sponsorship - Customer Guide.pdf
Azure EA Sponsorship - Customer Guide.pdf
AanSulistiyo
 
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
cuobya
 
7 Best Cloud Hosting Services to Try Out in 2024
7 Best Cloud Hosting Services to Try Out in 20247 Best Cloud Hosting Services to Try Out in 2024
7 Best Cloud Hosting Services to Try Out in 2024
Danica Gill
 
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalmanuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
wolfsoftcompanyco
 
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
cuobya
 
留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
uehowe
 

Recently uploaded (20)

办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
办理毕业证(NYU毕业证)纽约大学毕业证成绩单官方原版办理
 
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
 
Ready to Unlock the Power of Blockchain!
Ready to Unlock the Power of Blockchain!Ready to Unlock the Power of Blockchain!
Ready to Unlock the Power of Blockchain!
 
国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理
国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理
国外证书(Lincoln毕业证)新西兰林肯大学毕业证成绩单不能毕业办理
 
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
重新申请毕业证书(RMIT毕业证)皇家墨尔本理工大学毕业证成绩单精仿办理
 
Design Thinking NETFLIX using all techniques.pptx
Design Thinking NETFLIX using all techniques.pptxDesign Thinking NETFLIX using all techniques.pptx
Design Thinking NETFLIX using all techniques.pptx
 
Gen Z and the marketplaces - let's translate their needs
Gen Z and the marketplaces - let's translate their needsGen Z and the marketplaces - let's translate their needs
Gen Z and the marketplaces - let's translate their needs
 
不能毕业如何获得(USYD毕业证)悉尼大学毕业证成绩单一比一原版制作
不能毕业如何获得(USYD毕业证)悉尼大学毕业证成绩单一比一原版制作不能毕业如何获得(USYD毕业证)悉尼大学毕业证成绩单一比一原版制作
不能毕业如何获得(USYD毕业证)悉尼大学毕业证成绩单一比一原版制作
 
Should Repositories Participate in the Fediverse?
Should Repositories Participate in the Fediverse?Should Repositories Participate in the Fediverse?
Should Repositories Participate in the Fediverse?
 
Discover the benefits of outsourcing SEO to India
Discover the benefits of outsourcing SEO to IndiaDiscover the benefits of outsourcing SEO to India
Discover the benefits of outsourcing SEO to India
 
一比一原版(USYD毕业证)悉尼大学毕业证如何办理
一比一原版(USYD毕业证)悉尼大学毕业证如何办理一比一原版(USYD毕业证)悉尼大学毕业证如何办理
一比一原版(USYD毕业证)悉尼大学毕业证如何办理
 
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
存档可查的(USC毕业证)南加利福尼亚大学毕业证成绩单制做办理
 
制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理
制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理
制作毕业证书(ANU毕业证)莫纳什大学毕业证成绩单官方原版办理
 
快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
 
Azure EA Sponsorship - Customer Guide.pdf
Azure EA Sponsorship - Customer Guide.pdfAzure EA Sponsorship - Customer Guide.pdf
Azure EA Sponsorship - Customer Guide.pdf
 
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
假文凭国外(Adelaide毕业证)澳大利亚国立大学毕业证成绩单办理
 
7 Best Cloud Hosting Services to Try Out in 2024
7 Best Cloud Hosting Services to Try Out in 20247 Best Cloud Hosting Services to Try Out in 2024
7 Best Cloud Hosting Services to Try Out in 2024
 
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaalmanuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
manuaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaal
 
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
可查真实(Monash毕业证)西澳大学毕业证成绩单退学买
 
留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
留学挂科(UofM毕业证)明尼苏达大学毕业证成绩单复刻办理
 

Code Quality with Magento 2

  • 1. Code Quality with Magento 2 April 30th 2020 – Virtual Meet Magento Meetup #2 Andreas von Studnitz – integer_net – @avstudnitz
  • 2. Co-Founder and Managing Director @ integer_net Magento Developer, Trainer, Consultant since 2008 Twitter: @avstudnitz Andreas von Studnitz
  • 3. Andreas von Studnitz – integer_net – @avstudnitz 2014 Image Quality
  • 4. Andreas von Studnitz – integer_net – @avstudnitz 2020 Code Quality
  • 5. Andreas von Studnitz – integer_net – @avstudnitz Agenda Magento-Specific Code Quality Questions and Answers General Code Quality Tools for better Code Quality Motivation
  • 6. Andreas von Studnitz – integer_net – @avstudnitz For developers ◦ Code is easy to read ◦ Easy to understand ◦ Easy to adapt ◦ Easy to extend What is code quality good for? For customers • Fewer Bugs • Reliability • Security • Updatability • Less expensive long-term
  • 8. Andreas von Studnitz – integer_net – @avstudnitz Soft Factors • Code Reviews • Working Hours • Pair Programming • Code Reviews
  • 9. Andreas von Studnitz – integer_net – @avstudnitz Keep it simple • Minimal amount of LoC for demand – „only no code is good code“ • Use existing functions: Generate price rules instead of overwriting price logic • Not going to break on an update • Not going to show wrong VAT with tax included • Not going to break on a credit memo • Avoid unnecessary abstraction
  • 10. “ Andreas von Studnitz – integer_net – @avstudnitz “Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.” - Brian Kernighan
  • 11. Andreas von Studnitz – integer_net – @avstudnitz Literature
  • 13. Andreas von Studnitz – integer_net – @avstudnitz Updatability • No core hacks, no hacks of external modules • No changes of PHP classes  Instead: Observer, Plugin or Preference • No changes of template files  Instead: Make a theme specific copy, or better use Layout XML • No changes of language files  Instead: Custom translation files, possibly in own language pack
  • 14. Andreas von Studnitz – integer_net – @avstudnitz From MVC to MVVM • Model – View – ViewModel • ViewModels provide data for the View • PHP Classes which don’t need to inherit or implement anything • Read more: https://www.integer-net.com/view-models- in-magento-1-and-2/ (by Fabian Schmengler)
  • 15. Andreas von Studnitz – integer_net – @avstudnitz An Example of View Models module-catalog/view/frontend/layout/catalog_product_view.xml module-catalog/view/frontend/templates/product/breadcrumbs.phtml
  • 16. Andreas von Studnitz – integer_net – @avstudnitz Configuration as Code • Store configuration in the config.php and/or env.php • bin/magento config:set --lock-config • bin/magento config:set --lock-env • Since Magento 2.2.4 • Can create websites and stores • Can set store specific values
  • 17. Andreas von Studnitz – integer_net – @avstudnitz Example
  • 18. Andreas von Studnitz – integer_net – @avstudnitz Configuration: Suggestions • config.php is for sharing • Should contain everything you want to have control over • Don’t add everything – some things are better kept in config.xml • env.php is local only • Add your base URLs • Adjust security settings • Disable services like Google Analytics • Adjust payment methods and other sensitive data by environment
  • 19. Andreas von Studnitz – integer_net – @avstudnitz Setup Patches • More “Configuration as Code” – don’t use the Magento Admin for crucial changes • Successor of Setup Scripts (since Magento 2.3) • Attributes • Content (CMS, categories, products, …) • Accompanied by Declarative Schema for adjusting the database schema
  • 20. Andreas von Studnitz – integer_net – @avstudnitz A Setup Patch
  • 21. Tools for better Code Quality with Magento 2
  • 22. Andreas von Studnitz – integer_net – @avstudnitz Automated Testing • Huge improvement of M2 over M1 • In M1 automated testing not cost-effective in most mid-size cases • In M2 automated testing is now cost effective in most mid-size cases • Different types of testing: • Unit Tests • Integration Tests • Frontend Tests (MFTF)
  • 23. Andreas von Studnitz – integer_net – @avstudnitz Integration Tests class NewProductsCategoryTest extends MagentoTestFrameworkTestCaseAbstractControlle { public static function loadFixture() { include __DIR__ . '/../_files/categories.php'; include __DIR__ . '/../_files/products.php'; } public function testCategoryDisplaysCorrectProducts() { $this->dispatch('catalog/category/view/id/3'); $this->assertContains('Simple Product 1', $this->getResponse()->getBody()); $this->assertNotContains('Simple Product 2', $this->getResponse()->getBody()); } } • Hint: use https://github.com/tddwizard/magento2-fixtures
  • 24. Andreas von Studnitz – integer_net – @avstudnitz Static Tests • Check the code with tools like PHP Codesniffer and PHP Mess Detector • Automate with GrumPhp: Code will be checked on commit • Only a few steps to setup • Example:
  • 25. Andreas von Studnitz – integer_net – @avstudnitz Static Tests • Check the code with tools like PHP Codesniffer and PHP Mess Detector • Automate with GrumPhp: Code will be checked on commit • Only a few steps to setup • Example:
  • 26. Andreas von Studnitz – integer_net – @avstudnitz Static Tests • Check the code with tools like PHP Codesniffer and PHP Mess Detector • Automate with GrumPhp: Code will be checked on commit • Only a few steps to setup • Example:
  • 28. #MM18DE Installation of GrumPhp (2) grumphp.yml in project root directory
  • 29. Andreas von Studnitz – integer_net – @avstudnitz „The Obvious“ • Git for source code management and versioning • Composer for managing dependencies • PhpStorm • See warnings and errors directly • Easily integrate tools like Code Sniffer and Mess Detector • Built-in commands for code formatting and small refactorings