Save 37% off PRO during our Black Friday Sale! »

Enter Cookbook: refactoring under a microscope

Enter Cookbook: refactoring under a microscope

Solutions for refactoring.

8acd244ea0fc3d21c38306560794a2dd?s=128

Kamil Samigullin

April 28, 2016
Tweet

Transcript

  1. Episode #1.0.2 (2016-04-18) Enter Cookbook Refactoring under a microscope Level:

    Beginner
  2. • following the best practices (SOLID, DRY, etc.) • converting

    to a unified code style (PSR, etc.) • reducing algorithmic complexity (KISS, etc.) The main target of refactoring is increase code quality by
  3. • resistance to modifications • improving maintainability • internal satisfaction

    of a team The main benefits of increasing code quality are
  4. Integrated Development Environment

  5. • reduction of errors and misprints due to a built-in

    code analyzer and autocompletion • increase in productivity through powerful features for refactoring Solved problems by using IDE
  6. • PhpStorm for PHP projects • WebStorm for front-end and

    Node.js projects • PyCharm for DevOps tools (SaltStack, Fabric) • IntelliJ IDEA for our ESB (based on ServiceMix) Products that we are using
  7. How it looks

  8. Code Review

  9. • knowledge transfer about the task • the division of

    responsibility • quality control of coding • sharing of experience Solved problems through code review
  10. • GitHub, our choice (+ Gogs as failover mirror) •

    Bitbucket • GitLab • Upsource Services that I have tried
  11. None
  12. Continuous Integration

  13. • exclusion parser errors of interpreted languages through static code

    analysis • prevent regression of functionality by applying unit and integration tests • collection of codebase quality metrics Solved problems by using CI
  14. • works on Jenkins • all configurations (for PHP and

    Node.js projects) in one repository • a role in refactoring is static analysis and collection of code quality metrics What is CI in Enter?
  15. a typical Ant configuration What it includes for a PHP

    project?
  16. squizlabs/php_codesniffer • Packagist • GitHub • Documentation Detects violations of

    a defined set of coding standards. a typical configuration
  17. Our dynamics of transition to the PSR-2 standard

  18. sensiolabs-de/deprecation-detector • Packagist • GitHub Command line tool to detect

    usage of deprecated code. a typical configuration
  19. None
  20. phpmetrics/phpmetrics • Packagist • GitHub • Homepage Static analyzer tool

    for PHP: Coupling, Cyclomatic complexity, Maintainability Index, Halstead's metrics... and more! a typical configuration
  21. None
  22. None
  23. Logs aggregation

  24. Solutions that I have tried • RSYSLOG, our choice (+

    Fabric with Python scripts as a tool for analysis) • ELK stack Solved problems through logs aggregation • understanding of what is happening in a runtime on a large VPS cluster
  25. Simple script on the basis of decision 1. get the

    base name of fpm log files: ls pool-*.log 2>/dev/null | cat 2. get errors for each of them: cat %s* | grep -Eo "PHP.*[0-9]" | sort | uniq -c 3. send email to the team
  26. None
  27. Profiling

  28. • search performance bottlenecks • assessing adequacy of an algorithm

    • reducing algorithmic complexity Solved problems through profiling
  29. • Blackfire, our choice • XHProf with XHGui or XHProf.io

    • Xdebug with KCachegrind/QCachegrind Tools that I have tried
  30. How it looks

  31. What about open source projects?

  32. Services that I recommend • Travis CI • Scrutinizer •

    Code Climate • SensioLabsInsight
  33. Visual appearance of Travis CI

  34. Visual appearance of Scrutinizer

  35. Visual appearance of CodeClimate

  36. How looks my typical project

  37. • https://refactoring.guru • http://www.phptherightway.com • http://www.sonarqube.org • http://phpqatools.org • http://jenkins-php.org

    Useful links
  38. • SensioLabsInsight • SonarLint • Php Inspections (EA Extended) •

    PHP Advanced AutoComplete Useful plugins
  39. My related content Enter: legacy code [rus] Enter: code style

    [rus]
  40. Thank you for your attention! Have questions? Kamil Samigullin a

    some developer kamil@samigullin.info @ikamilsk github.com/kamilsk linkedin.com/in/kamilsk