PHPStan is popular tool for analyzing PHP code that can help you greatly reduce the number of bugs in your code. Have you ever wondered how analysis of dynamic, gradually typed languages such as PHP is done? In this talk we're going to explore how PHPStan internally models many aspects of PHP language. We're going to have a close look at PHPStan's type system. How does it model both simple and complex types. How types are combined together and how such combinations can be used to model many dynamic aspects of PHP language or how they allow us to do reliable dead code detection. I'll introduce the concept of trinary logic and how it allows PHPStan to support both legacy and modern code bases. We're also going to have a look at type guards. How they work. What they can and what they currently cannot do. And I'll show you how it all fits together to create a working system.