Skip to content

Commit

Permalink
Dev: Work on Psalm checker
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Apr 18, 2018
1 parent a5e1df5 commit 98f83c1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
1 change: 1 addition & 0 deletions tests/phpstan/phpstan_bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
Yii::import('application.core.*', true);
Yii::import('application.helpers.common_helper', true);
Yii::import('application.helpers.globalsettings_helper', true);
Yii::import('application.helpers.expressions.em_core_helper', true);
Yii::import('application.libraries.PluginManager.PluginManager', true);
Yii::import('application.libraries.MenuObjects.*', true);
Yii::import('application.third_party.Twig.TemplateInterface', true);
Expand Down
46 changes: 35 additions & 11 deletions tests/rulesets/run_checkers.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

/**
* Run this command to check a file for problems.
* Run this command to check a folder for errors and style.
* If this file doesn't work or the listed errors are weird, please
* contact author.
*
* Usage:
* php tests/rulesets/run_checkers.php <file to check>
* php tests/rulesets/run_checkers.php <folder with php files>
*
* Before running this file, you need to install phpmd, phpcs and psalm (composer install
* should be enough for psalm). TODO: More instructions.
Expand All @@ -16,20 +16,44 @@
*/

if (empty($argv[1])) {
die('No filename');
die('No extension folder name');
}

$phpmd_output = [];
exec(sprintf('phpmd %s text tests/rulesets/phpmd_ruleset.xml', $argv[1]), $phpmd_output);
if (!is_dir($argv[1])) {
die($argv[1] . ' is not a folder');
}

function checkFile($file)
{
$phpmd_output = [];
exec(sprintf('phpmd %s text tests/rulesets/phpmd_ruleset.xml', $file), $phpmd_output);

$phpcs_output = [];
exec(sprintf('phpcs --report=emacs --standard=tests/rulesets/phpcs_ruleset.xml %s', $argv[1]), $phpcs_output);
$phpcs_output = [];
exec(sprintf('phpcs --report=emacs --standard=tests/rulesets/phpcs_ruleset.xml %s', $file), $phpcs_output);

$psalm_output = [];
exec(sprintf('./third_party/bin/psalm -m --output-format=emacs %s', $argv[1]), $psalm_output);
$psalm_output = [];
exec(sprintf('./third_party/bin/psalm -m --output-format=emacs %s', $file), $psalm_output);

$output = array_merge($phpmd_output, $phpcs_output, $psalm_output);
$output = array_merge($phpmd_output, $phpcs_output, $psalm_output);

echo implode(PHP_EOL, $output);
echo implode(PHP_EOL, $output);
}

// TODO: Loop all PHP files in folder.
function checkDir($dirname)
{
$dir = dir($dirname);
while (false !== $entry = $dir->read()) {
// Skip pointers
if ($entry == '.' || $entry == '..') {
continue;
}

// Recurse
checkDir($dirname.DIRECTORY_SEPARATOR.$entry);
}
// Clean up
$dir->close();
}

exit (count($output) == 0 ? 0 : 1);

0 comments on commit 98f83c1

Please sign in to comment.