+ - 0:00:00
Notes for current slide
Notes for next slide
Best coding practices

Best coding practices

according to ExtDN

1 of 33
Best coding practices

Jisse Reitsma

2 of 33
Best coding practices

Jisse Reitsma

  • A simple Dutch boy
2 of 33
Best coding practices

Jisse Reitsma

  • A simple Dutch boy
  • From the Netherlands (a real country!)
2 of 33
Best coding practices

Jisse Reitsma

  • A simple Dutch boy
  • From the Netherlands (a real country!)
  • Founder of Yireo
2 of 33
Best coding practices

Jisse Reitsma

  • A simple Dutch boy
  • From the Netherlands (a real country!)
  • Founder of Yireo
  • Extension developer
2 of 33
Best coding practices

Jisse Reitsma

  • A simple Dutch boy
  • From the Netherlands (a real country!)
  • Founder of Yireo
  • Extension developer
  • Trainer of Magento 2 developers
2 of 33
Best coding practices

Jisse Reitsma

  • A simple Dutch boy
  • From the Netherlands (a real country!)
  • Founder of Yireo
  • Extension developer
  • Trainer of Magento 2 developers
  • Creator of MageTestFest & Reacticon
2 of 33
Best coding practices

Jisse Reitsma

  • A simple Dutch boy
  • From the Netherlands (a real country!)
  • Founder of Yireo
  • Extension developer
  • Trainer of Magento 2 developers
  • Creator of MageTestFest & Reacticon
  • Magento Master 2017 & 2018 Mover
2 of 33
Best coding practices

Jisse Reitsma

  • A simple Dutch boy
  • From the Netherlands (a real country!)
  • Founder of Yireo
  • Extension developer
  • Trainer of Magento 2 developers
  • Creator of MageTestFest & Reacticon
  • Magento Master 2017 & 2018 Mover
  • Member of ExtDN.org
2 of 33
Best coding practices

ExtDN

https://extdn.org/

3 of 33
Best coding practices

ExtDN Working Groups

  • Extension Quality
  • Interoperability
  • Communications
4 of 33
Best coding practices

ExtDN Working Groups

  • Extension Quality
    • Collaboration with Magento Marketplace
    • PHP CodeSniffer
  • Interoperability
  • Communications
5 of 33
Best coding practices

ExtDN Working Groups

  • Extension Quality
  • Extension Interoperability
    • Less conflicts between extensions
    • Expectation of features
    • PWA compatibility
  • Communications
6 of 33
Best coding practices

ExtDN Working Groups

  • Extension Quality
  • Extension Interoperability
  • Communications
    • Talk with each other
    • Talk with Magento & Adobe
    • Talk with you
7 of 33
Best coding practices

Some of the goals

8 of 33
Best coding practices

Some of the goals

  • Better extension quality
8 of 33
Best coding practices

Some of the goals

  • Better extension quality
  • Less bugs, less conflicts
8 of 33
Best coding practices

Some of the goals

  • Better extension quality
  • Less bugs, less conflicts
  • More happiness
8 of 33
Best coding practices

8 points

9 of 33
Best coding practices

8 fold path

to achieve happiness

10 of 33
Best coding practices

8 points

11 of 33
Best coding practices

8 points

  • Do Use Composer
11 of 33
Best coding practices

8 points

  • Do Use Composer
  • Do Use Service Contracts
11 of 33
Best coding practices

8 points

  • Do Use Composer
  • Do Use Service Contracts
  • Do Write Tests
11 of 33
Best coding practices

8 points

  • Do Use Composer
  • Do Use Service Contracts
  • Do Write Tests
  • Do Document Your Dependencies
11 of 33
Best coding practices

8 points

  • Do Use Composer
  • Do Use Service Contracts
  • Do Write Tests
  • Do Document Your Dependencies
  • Do Version Releases
11 of 33
Best coding practices

8 points

  • Do Use Composer
  • Do Use Service Contracts
  • Do Write Tests
  • Do Document Your Dependencies
  • Do Version Releases
  • Do Provide A User Manual
11 of 33
Best coding practices

8 points

  • Do Use Composer
  • Do Use Service Contracts
  • Do Write Tests
  • Do Document Your Dependencies
  • Do Version Releases
  • Do Provide A User Manual
  • Do Use Events And Plugins
11 of 33
Best coding practices

8 points

  • Do Use Composer
  • Do Use Service Contracts
  • Do Write Tests
  • Do Document Your Dependencies
  • Do Version Releases
  • Do Provide A User Manual
  • Do Use Events And Plugins
  • Do Check Your Code
11 of 33
Best coding practices

1. Do Use Composer

12 of 33
Best coding practices

1. Do Use Composer

"Use composer packages to distribute (especially commercial) extensions. For a local environment, it is fine to develop your own code under app/code. However, once you distribute your module to other environments, it should be through composer as otherwise dependencies are left unmanaged. In a production environment, the app/code folder should therefore ideally be empty."

13 of 33
Best coding practices

1. Do Use Composer

14 of 33
Best coding practices

1. Do Use Composer

  • Use composer packages for extensions
14 of 33
Best coding practices

1. Do Use Composer

  • Use composer packages for extensions
  • Especially commercial extensions should use composer
14 of 33
Best coding practices

1. Do Use Composer

  • Use composer packages for extensions
  • Especially commercial extensions should use composer
  • This is not a debate, this is a base requirement
14 of 33
Best coding practices

1. Do Use Composer

15 of 33
Best coding practices

1. Do Use Composer

  • Locally, you can use app/code
15 of 33
Best coding practices

1. Do Use Composer

  • Locally, you can use app/code
  • But with deployment, composer should be used
15 of 33
Best coding practices

1. Do Use Composer

  • Locally, you can use app/code
  • But with deployment, composer should be used
  • And in production, app/code should be empty
15 of 33
Best coding practices

4. Do Document Your Dependencies

16 of 33
Best coding practices

4. Document Dependencies

"If your module depends on other modules, make sure that both your composer file and your module.xml file reflect this. If your module only depends on the Magento framework, your module should likely be treated as a library, not a module. Your composer version constraints should respect the semantic versioning standards of Magento."

17 of 33
Best coding practices

4. Document Dependencies

File etc/module.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Yireo_Foobar" setup_version="0.0.1" />
</config>
18 of 33
Best coding practices

4. Document Dependencies

File etc/module.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Yireo_Foobar" setup_version="0.0.1">
<sequence>
<module name="Magento_Catalog" />
</sequence>
</module>
</config>
19 of 33
Best coding practices

4. Document Dependencies

File etc/module.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Yireo_Foobar" setup_version="0.0.1">
<sequence>
<module name="Magento_Catalog" />
<module name="Magento_Backend" />
</sequence>
</module>
</config>
20 of 33
Best coding practices

4. Document Dependencies

File etc/module.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Yireo_Foobar" setup_version="0.0.1">
<sequence>
<module name="Magento_Catalog" />
<module name="Magento_Backend" />
<module name="Magento_Ui" />
</sequence>
</module>
</config>
21 of 33
Best coding practices

4. Document Dependencies

File etc/module.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Yireo_Foobar" setup_version="0.0.1">
<sequence>
<module name="Magento_Catalog" />
<module name="Magento_Backend" />
<module name="Magento_Ui" />
<module name="Magento_Store" />
</sequence>
</module>
</config>
22 of 33
Best coding practices

4. Document Dependencies

File composer.json:

"require": {
"magento/framework": "^100.1|^101.0|^102.0",
"magento/module-backend": "^101.0|^102.0",
"magento/module-catalog": "^100.0|^101.0",
"magento/module-store": "^100.1|^101.0",
"magento/module-ui": "^101.0",
"php": ">=7.0.0"
},
23 of 33
Best coding practices

8. Do Check Your Code

24 of 33
Best coding practices

8. Do Check Your Code

"Use a static analysis tool like PHP CodeSniffer (with the ExtDN and MEQP rulesets). Check whether your extension works in Production Mode. Confirm your extension works under the Magento versions that you claim compatibility with. Have a colleague or friend review your code before releasing it."

25 of 33
Best coding practices

8. Do Check Your Code

  • PHP CodeSniffer
26 of 33
Best coding practices

8. Do Check Your Code

  • PHP CodeSniffer
    • PSR1, PSR2
    • Magento Extension Quality Program
    • Magento Expert Consultancy Group
    • ExtDN
    • Object Calisthenics
27 of 33
Best coding practices

8. Do Check Your Code

  • PHP CodeSniffer
28 of 33
Best coding practices

8. Do Check Your Code

  • PHP CodeSniffer
  • PHPStan
28 of 33
Best coding practices

8. Do Check Your Code

  • PHP CodeSniffer
  • PHPStan
  • GrumPHP
28 of 33
Best coding practices

8. Do Check Your Code

  • PHP CodeSniffer
  • PHPStan
  • GrumPHP
  • roave/security-advisories
28 of 33
Best coding practices

8. Do Check Your Code

  • PHP CodeSniffer
  • PHPStan
  • GrumPHP
  • roave/security-advisories
  • Linting
28 of 33
Best coding practices

8. Do Check Your Code

  • PHP CodeSniffer
  • PHPStan
  • GrumPHP
  • roave/security-advisories
  • Linting
  • Testing (unit, integration, functional, acceptance)
28 of 33
Best coding practices

8. Do Check Your Code

Not just tools:

  • Code reviews, extension reviews
  • Pair programming, crown programming
  • Hackathons, Contribution Days
29 of 33
Best coding practices

ExtDN PHPCS project

https://github.com/extdn/extdn-phpcs

30 of 33
Best coding practices

stop bitching
start contributing

31 of 33
Best coding practices

stop complaining
start contributing

32 of 33
Best coding practices

thanks

33 of 33
Best coding practices

Jisse Reitsma

2 of 33
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow