class Phpstan < Formula desc "PHP Static Analysis Tool" homepage "https://github.com/phpstan/phpstan" url "https://github.com/phpstan/phpstan/releases/download/0.11.16/phpstan.phar" sha256 "fa7b4db67d132c023e1f5ac22320e40dfc1adee1d405e57f7076c8c9e7094430" bottle :unneeded depends_on "php" => :test def install bin.install "phpstan.phar" => "phpstan" end test do (testpath/"src/autoload.php").write <<~EOS '/Email.php' ); } $cn = strtolower($class); if (isset($classes[$cn])) { require __DIR__ . $classes[$cn]; } }, true, false ); EOS (testpath/"src/Email.php").write <<~EOS ensureIsValidEmail($email); $this->email = $email; } public static function fromString(string $email): self { return new self($email); } public function __toString(): string { return $this->email; } private function ensureIsValidEmail(string $email): void { if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { throw new InvalidArgumentException( sprintf( '"%s" is not a valid email address', $email ) ); } } } EOS assert_match /^\n\n \[OK\] No errors/, shell_output("#{bin}/phpstan analyse --level max --autoload-file src/autoload.php src/Email.php") end end