homebrew-core/Formula/phpstan.rb
Sean Molenaar e2e026d3ae
phpstan 0.11.8
Closes #40464.

Signed-off-by: Chongyu Zhu <i@lembacon.com>
2019-05-30 06:47:44 +08:00

76 lines
2 KiB
Ruby

class Phpstan < Formula
desc "PHP Static Analysis Tool"
homepage "https://github.com/phpstan/phpstan"
url "https://github.com/phpstan/phpstan/releases/download/0.11.8/phpstan.phar"
sha256 "9604e84b47a515f860f8dd96d94dc0527636da7b4e6ccf9bd1785d59f004ae75"
bottle :unneeded
depends_on "php" => :test
def install
bin.install "phpstan.phar" => "phpstan"
end
test do
(testpath/"src/autoload.php").write <<~EOS
<?php
spl_autoload_register(
function($class) {
static $classes = null;
if ($classes === null) {
$classes = array(
'email' => '/Email.php'
);
}
$cn = strtolower($class);
if (isset($classes[$cn])) {
require __DIR__ . $classes[$cn];
}
},
true,
false
);
EOS
(testpath/"src/Email.php").write <<~EOS
<?php
declare(strict_types=1);
final class Email
{
private $email;
private function __construct(string $email)
{
$this->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