class Phpstan < Formula desc "PHP Static Analysis Tool" homepage "https://github.com/phpstan/phpstan" url "https://github.com/phpstan/phpstan/releases/download/1.9.7/phpstan.phar" sha256 "08730534eca3e270aac6d6d134e889d6abc447f2febc6c1f81fbdf7ee5fe756e" license "MIT" bottle do sha256 cellar: :any_skip_relocation, arm64_ventura: "aa5f853498cee5de5e28e7d2c02f7ea4aceb7db8f8c16a0ff8a0ee1b88d320c0" sha256 cellar: :any_skip_relocation, arm64_monterey: "aa5f853498cee5de5e28e7d2c02f7ea4aceb7db8f8c16a0ff8a0ee1b88d320c0" sha256 cellar: :any_skip_relocation, arm64_big_sur: "aa5f853498cee5de5e28e7d2c02f7ea4aceb7db8f8c16a0ff8a0ee1b88d320c0" sha256 cellar: :any_skip_relocation, ventura: "5921c450bb0c721944160d9ab2b313f0f6aedd54b9460700e86896ebe18319ea" sha256 cellar: :any_skip_relocation, monterey: "5921c450bb0c721944160d9ab2b313f0f6aedd54b9460700e86896ebe18319ea" sha256 cellar: :any_skip_relocation, big_sur: "5921c450bb0c721944160d9ab2b313f0f6aedd54b9460700e86896ebe18319ea" sha256 cellar: :any_skip_relocation, x86_64_linux: "aa5f853498cee5de5e28e7d2c02f7ea4aceb7db8f8c16a0ff8a0ee1b88d320c0" end depends_on "php" => :test # Keg-relocation breaks the formula when it replaces `/usr/local` with a non-default prefix on_macos do on_intel do pour_bottle? only_if: :default_prefix end end 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 \[OK\] No errors/, shell_output("#{bin}/phpstan analyse --level max --autoload-file src/autoload.php src/Email.php")) end end