Adding Psalm analysis

This commit is contained in:
Jens True 2023-08-03 14:26:00 +00:00
parent 3e42b48003
commit 0e1947ca3a
6 changed files with 1975 additions and 18 deletions

@ -10,7 +10,8 @@
"rector/rector": "^0.17", "rector/rector": "^0.17",
"phpstan/phpstan": "^1", "phpstan/phpstan": "^1",
"laravel/pint": "^1", "laravel/pint": "^1",
"squizlabs/php_codesniffer": "*" "squizlabs/php_codesniffer": "*",
"vimeo/psalm": "^5.14"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
@ -27,9 +28,11 @@
"test-coverage": "vendor/bin/phpunit tests --testdox --coverage-filter src --coverage-html output/coverage --coverage-text --path-coverage --testdox-html output/test.html --log-junit output/test.xml ", "test-coverage": "vendor/bin/phpunit tests --testdox --coverage-filter src --coverage-html output/coverage --coverage-text --path-coverage --testdox-html output/test.html --log-junit output/test.xml ",
"analyze": [ "analyze": [
"@analyze-phpstan", "@analyze-phpstan",
"@analyze-phpcs" "@analyze-phpcs",
"@analyze-psalm"
], ],
"analyze-phpstan":"vendor/bin/phpstan analyze --level=8 --error-format=raw src/", "analyze-phpstan":"vendor/bin/phpstan analyze --error-format=raw src/",
"analyze-phpcs": "vendor/bin/phpcs --report=emacs --standard=PSR12 --exclude=Generic.Files.LineLength src" "analyze-phpcs": "vendor/bin/phpcs --report=emacs --standard=PSR12 --exclude=Generic.Files.LineLength src",
"analyze-psalm": "vendor/bin/psalm"
} }
} }

1946
composer.lock generated

File diff suppressed because it is too large Load Diff

17
psalm.xml Normal file

@ -0,0 +1,17 @@
<?xml version="1.0"?>
<psalm
errorLevel="7"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
findUnusedBaselineEntry="true"
findUnusedCode="true"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>

@ -11,11 +11,9 @@ class ScheduleLoop extends Schedule
public function visit(int $depth = -1, int $maxDepth = 0): float public function visit(int $depth = -1, int $maxDepth = 0): float
{ {
$totalIterations = 1;
$delta = $this->scheduleToLoop->visit($depth + 1, $maxDepth); $delta = $this->scheduleToLoop->visit($depth + 1, $maxDepth);
while ($delta > $this->maxDelta) { while ($delta > $this->maxDelta) {
$delta = $this->scheduleToLoop->visit($depth + 1, $maxDepth); $delta = $this->scheduleToLoop->visit($depth + 1, $maxDepth);
$totalIterations++;
} }
return $delta; return $delta;

@ -13,10 +13,10 @@ class BasicMath
/** /**
* Squares the input (x^2 = x * x) * Squares the input (x^2 = x * x)
* *
* @param number $x Value to square (x) * @param float $x Value to square (x)
* @return number The squared value (x^2) * @return float The squared value (x^2)
*/ */
public static function square($x): float|int public static function square($x): float
{ {
return $x * $x; return $x * $x;
} }
@ -26,9 +26,9 @@ class BasicMath
* *
* @param mixed[] $itemsToSum The items to sum, * @param mixed[] $itemsToSum The items to sum,
* @param \Closure $callback The function to apply to each array element before summing. * @param \Closure $callback The function to apply to each array element before summing.
* @return number The sum. * @return float The sum.
*/ */
public static function sum(array $itemsToSum, \Closure $callback): float|int public static function sum(array $itemsToSum, \Closure $callback): float
{ {
$mappedItems = array_map($callback, $itemsToSum); $mappedItems = array_map($callback, $itemsToSum);

@ -25,15 +25,10 @@ class GaussianGreaterThanFactor extends GaussianFactor
public function getLogNormalization(): float public function getLogNormalization(): float
{ {
/**
* @var Variable[] $vars
*/
$vars = $this->getVariables(); $vars = $this->getVariables();
$marginal = $vars[0]->getValue(); $marginal = $vars[0]->getValue();
/**
* @var Message[] $messages
*/
$messages = $this->getMessages(); $messages = $this->getMessages();
$message = $messages[0]->getValue(); $message = $messages[0]->getValue();
$messageFromVariable = GaussianDistribution::divide($marginal, $message); $messageFromVariable = GaussianDistribution::divide($marginal, $message);