$30 off During Our Annual Pro Sale. View Details »

PHPStan: finding bugs in your code without runn...

PHPStan: finding bugs in your code without running it

PHPStan is a static analysis tool for our code, which can find common errors like erroneous written functions and methods, more complex errors like verifications that always return true or false, and even returns that do not match the scope of the function. It will be shown all its configuration, customization, extension and how this tool has changed many applications throughout the PHP ecosystem.

Gabriel Caruso

June 08, 2019
Tweet

More Decks by Gabriel Caruso

Other Decks in Programming

Transcript

  1. PHPStan: finding bugs in your code without even running it

    by Gabriel Caruso Darkmira Tour PHP 2019
  2. Who am I? • Backend Engineer at Usabilla • PHP

    enthusiastic • PHPSP member • OSS contributor • Stickers/ELEPHANTS lover
  3. Interpreted language PHP, JavaScript, Ruby... “An interpreted language is a

    type of programming language for which most of its implementations execute instructions directly and freely, without previously compiling a program into machine-language instructions.”
  4. Compiled Language Java, C, Swift... “A compiled language is a

    programming language whose implementations are typically compilers (translators that generate machine code from source code), and not interpreters”
  5. Static Analyzer “Static Analyzer Tool is the analysis of computer

    software that is performed without actually executing programs.”
  6. PHPStan “PHPStan focuses on finding errors in your code without

    actually running it. It catches whole classes of bugs even before you write tests for the code. It moves PHP closer to compiled languages in the sense that the correctness of each line of the code can be checked before you run the actual line”
  7. - Do you have 100% coverage of your code? -

    Do your tests run under a minute?
  8. The four essential tools for modern PHP development PHP Lint:

    checks if your code is right PHPUnit: checks if your business logic is right PHP Code Sniffer: checks if your code is readable PHPStan: checks if your code does not have bugs
  9. What does happen in the first run? - Parse/Fatal Errors

    - Misconfigured PSR-4 Autoloading - Extra arguments passed to functions - Magic behaviour that needs to be defined (We'll talk more about this point in specific in a second) What happens after I solve all first-run errors?
  10. Using PHPStan extensions - Doctrine - PHPUnit - Symfony -

    Mockery Some magic functions of ORMs and Frameworks need some extra work
  11. - Tweet me @carusogabriel - Give a feedback to this

    talk Questionings? Thank you ♡