Skip to content

Commit

Permalink
introduce phpstan (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
akondas authored Jun 1, 2024
1 parent 44b7b5f commit 7423fab
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
/.gitattributes export-ignore
/.gitignore export-ignore
/.php_cs.dist export-ignore
/buddy.yml export-ignore
/phpstan.neon export-ignore
/phpunit.xml.dist export-ignore
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"phpunit/phpunit": "^9.5",
"symfony/browser-kit": "^5.2",
"symfony/framework-bundle": "^5.2",
"symfony/stopwatch": "^5.2"
"symfony/stopwatch": "^5.2",
"phpstan/phpstan": "^1.11"
},
"autoload": {
"psr-4": {
Expand All @@ -45,6 +46,7 @@
"scripts": {
"build": [
"@check-cs",
"@phpstan",
"@phpunit"
],
"check-cs": [
Expand All @@ -55,6 +57,9 @@
],
"phpunit": [
"phpunit"
],
"phpstan": [
"phpstan analyse -c phpstan.neon"
]
}
}
60 changes: 59 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
includes:
- vendor/phpstan/phpstan/conf/bleedingEdge.neon
parameters:
phpVersion: 80100
level: max
paths:
- src
- tests
3 changes: 1 addition & 2 deletions src/Assault/ExceptionAssault.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public function isActive(): bool

public function attack(): void
{
$exceptionClass = $this->settings->exceptionClass();
throw new $exceptionClass();
throw new ($this->settings->exceptionClass())();
}
}
8 changes: 8 additions & 0 deletions src/Assault/MemoryAssault.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ public function attack(): void
}
}

/**
* @return mixed[]
*/
public function memoryVector(): array
{
return $this->memoryVector;
}

private function fillFraction(): float
{
return memory_get_usage(true) / $this->totalMemory;
Expand Down
3 changes: 3 additions & 0 deletions src/ChaosMonkey.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ class ChaosMonkey

private Settings $settings;

/**
* @param iterable<Assault> $assaults
*/
public function __construct(iterable $assaults, Settings $settings)
{
foreach ($assaults as $assault) {
Expand Down
9 changes: 9 additions & 0 deletions src/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class Settings
private int $latencyMaxMs;

private bool $exceptionActive;
/**
* @var class-string<\Throwable>
*/
private string $exceptionClass;

private bool $killAppActive;
Expand Down Expand Up @@ -76,6 +79,9 @@ public function setExceptionActive(bool $exceptionActive): void
$this->exceptionActive = $exceptionActive;
}

/**
* @param class-string<\Throwable> $exceptionClass
*/
public function setExceptionClass(string $exceptionClass): void
{
$this->exceptionClass = $exceptionClass;
Expand Down Expand Up @@ -126,6 +132,9 @@ public function exceptionActive(): bool
return $this->exceptionActive;
}

/**
* @return class-string<\Throwable>
*/
public function exceptionClass(): string
{
return $this->exceptionClass;
Expand Down
3 changes: 3 additions & 0 deletions tests/MotherObject/SettingsMother.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public static function withActiveLatency(int $minMs, int $maxMs): Settings
return $settings;
}

/**
* @param class-string<\Throwable> $exceptionClass
*/
public static function withExceptionActive(string $exceptionClass): Settings
{
$settings = new Settings();
Expand Down

0 comments on commit 7423fab

Please sign in to comment.