diff --git a/src/Events/php_exporter.php b/src/Events/php_exporter.php index 500e20b..24e3e03 100644 --- a/src/Events/php_exporter.php +++ b/src/Events/php_exporter.php @@ -196,7 +196,6 @@ public function get_event_name($event_line, $is_dispatch) if (isset($match[2])) { - $this->output->inMaxPogress(1); $this->output->addMessage(Output::ERROR, sprintf('Event names should be all lowercase in %s for event %s', $this->current_file, $match[2])); } else diff --git a/src/Files/FileLoader.php b/src/Files/FileLoader.php index 306f45e..063036b 100644 --- a/src/Files/FileLoader.php +++ b/src/Files/FileLoader.php @@ -63,11 +63,7 @@ public function loadFile($fileName) // Otherwise add notice. if (strtolower($fileName) !== 'readme') { - $this->output->addMessage(Output::NOTICE, sprintf("The file %s has no valid extension.", basename($fileName)), null, true); - } - else - { - $this->output->printErrorLevel(); + $this->output->addMessage(Output::NOTICE, sprintf("The file %s has no valid extension.", basename($fileName))); } $file = new PlainFile($this->debug, $fileName); } @@ -94,7 +90,7 @@ public function loadFile($fileName) else if ($size >= 4) // Files with 3 ore more dots should not happen. { $error = true; - $this->output->addMessage(Output::ERROR, sprintf("File (%s) seems to have too many dots. Using the last part as extension.", $fileName), null, true); + $this->output->addMessage(Output::ERROR, sprintf("File (%s) seems to have too many dots. Using the last part as extension.", $fileName)); $file = self::tryLoadFile($fileName, $split[sizeof($split) - 1]); @@ -197,11 +193,11 @@ private function tryLoadFile($fileName, $extension, $returnNull = false) return new ImageFile($this->debug, $fileName); case 'swf': - $this->output->addMessage(Output::NOTICE, sprintf("Found an SWF file (%s), please make sure to include the source files for it, as required by the GPL.", basename($fileName)), null, true); + $this->output->addMessage(Output::NOTICE, sprintf("Found an SWF file (%s), please make sure to include the source files for it, as required by the GPL.", basename($fileName))); return new BinaryFile($this->debug, $fileName); case 'ds_store': - $this->output->addMessage(Output::ERROR, sprintf("Found an OS X specific file at %s, please make sure to remove it prior to submission.", $fileName), null, true); + $this->output->addMessage(Output::ERROR, sprintf("Found an OS X specific file at %s, please make sure to remove it prior to submission.", $fileName)); return new BinaryFile($this->debug, $fileName); diff --git a/src/Output/Output.php b/src/Output/Output.php index afb8b35..7d90e4d 100644 --- a/src/Output/Output.php +++ b/src/Output/Output.php @@ -160,14 +160,9 @@ public function writelnIfDebug($message) * @param $type int message type * @param $message string message * @param \Phpbb\Epv\Files\FileInterface $file File the error happened in. When provided, this is displayed to the user - * @param bool $skipError skip the printErrorLevel call (Default false) */ - public function addMessage($type, $message, FileInterface $file = null, $skipError = false) + public function addMessage($type, $message, FileInterface $file = null) { - if (!$skipError) - { - $this->printErrorLevel($type); - } switch ($type) { case Output::FATAL: @@ -224,68 +219,16 @@ public function getFatalCount() */ public function getMessageCount($type) { - switch ($type) - { - case Output::FATAL: - return $this->fatal; - case Output::ERROR: - return $this->error; - case Output::WARNING: - return $this->warning; - case Output::NOTICE: - return $this->notice; - } - } - /** - * @param int $maxProgress - */ - public function setMaxProgress($maxProgress) - { - $this->maxProgress = $maxProgress; - } - - /** - * Increase the max progress during the run. - * - * @param $inc - */ - public function inMaxPogress($inc) - { - $this->setMaxProgress($this->maxProgress + $inc); - } - - /** - * @param $result the result of this specific test. - */ - public function printErrorLevel($result = null) - { - if ($result == Output::FATAL) - { - $this->output->write("F"); - } - else if ($result == Output::ERROR) - { - $this->output->write("E"); - } - else if ($result == Output::WARNING) - { - $this->output->write("W"); - } - else if ($result == Output::NOTICE) - { - $this->output->write("N"); - } - else - { - $this->output->write("."); - } - $this->progress++; - - if ($this->progress % 85 == 0) - { - $this->output->write(' ' . sprintf('%' . strlen($this->maxProgress) . 's', $this->progress)); - $this->output->write(' / ' . $this->maxProgress); - $this->output->writeln(' (' . sprintf('%3s', floor(100 * ($this->progress / $this->maxProgress))) . '%)'); - } + switch ($type) + { + case Output::FATAL: + return $this->fatal; + case Output::ERROR: + return $this->error; + case Output::WARNING: + return $this->warning; + case Output::NOTICE: + return $this->notice; + } } } diff --git a/src/Output/OutputInterface.php b/src/Output/OutputInterface.php index 60fa4c9..3c02e44 100644 --- a/src/Output/OutputInterface.php +++ b/src/Output/OutputInterface.php @@ -34,10 +34,9 @@ public function writelnIfDebug($message); * @param $type int message type * @param $message string message * @param \Phpbb\Epv\Files\FileInterface $file File the error happened in. When provided, this is displayed to the user - * @param bool $skipError * @return */ - public function addMessage($type, $message, FileInterface $file = null, $skipError = false); + public function addMessage($type, $message, FileInterface $file = null); /** * Get all messages saved into the message queue. @@ -57,26 +56,4 @@ public function getFatalCount(); * @return mixed */ public function getMessageCount($type); - - /** - * Set the max progress (Number of tests) for this run. - * - * - * @param $maxProgress int - */ - public function setMaxProgress($maxProgress); - - /** - * Increase the max progress during the run. - * - * @param $inc - */ - public function inMaxPogress($inc); - - /** - * Print the status of this specific test. - * - * @param $result The result for this specific test. - */ - public function printErrorLevel($result = null); } diff --git a/src/Tests/BaseTest.php b/src/Tests/BaseTest.php index 5d77d20..716f8a0 100644 --- a/src/Tests/BaseTest.php +++ b/src/Tests/BaseTest.php @@ -25,10 +25,6 @@ abstract class BaseTest implements TestInterface /** @var \Phpbb\Epv\Files\FileInterface * */ protected $file; - protected $totalLineTests = 0; - protected $totalFileTests = 0; - protected $totalDirectoryTests = 0; - /** * If this is set to true, tests are run on full directory listings. * @var bool @@ -121,30 +117,6 @@ public function doValidateDirectory() return $this->directory; } - /** - * @return mixed - */ - public function getTotalDirectoryTests() - { - return $this->totalDirectoryTests; - } - - /** - * @return mixed - */ - public function getTotalFileTests() - { - return $this->totalFileTests; - } - - /** - * @return mixed - */ - public function getTotalLineTests() - { - return $this->totalLineTests; - } - /** * Convert a boolean to Yes or No. * diff --git a/src/Tests/TestInterface.php b/src/Tests/TestInterface.php index d38d264..dffefb5 100644 --- a/src/Tests/TestInterface.php +++ b/src/Tests/TestInterface.php @@ -65,18 +65,4 @@ public function doValidateFile($type); */ public function testName(); - /** - * @return int - */ - public function getTotalDirectoryTests(); - - /** - * @return int - */ - public function getTotalFileTests(); - - /** - * @return int - */ - public function getTotalLineTests(); } diff --git a/src/Tests/TestRunner.php b/src/Tests/TestRunner.php index dd46f45..0749e27 100644 --- a/src/Tests/TestRunner.php +++ b/src/Tests/TestRunner.php @@ -10,6 +10,7 @@ namespace Phpbb\Epv\Tests; +use Phpbb\Epv\Files\FileInterface; use Phpbb\Epv\Files\FileLoader; use Phpbb\Epv\Files\Line; use Phpbb\Epv\Output\Output; @@ -65,42 +66,9 @@ public function runTests() } $this->output->writeln("Running tests."); - // We start with calculating the total number of tests we are doing. - $maxProgress = 0; - - foreach ($this->tests as $test) - { - /** @var \Phpbb\Epv\Tests\TestInterface $test */ - if ($test->doValidateDirectory()) - { - $maxProgress += ($test->getTotalDirectoryTests()); - } - } - - foreach ($this->files as $file) - { - /** @var \Phpbb\Epv\Files\FileInterface $file */ - // Get the number of lines; - $lines = sizeof($file->getLines()); - - foreach ($this->tests as $test) - { - /** @var \Phpbb\Epv\Tests\TestInterface $test */ - if ($test->doValidateFile($file->getFileType())) - { - $maxProgress += ($test->getTotalFileTests()); - } - if ($test->doValidateLine($file->getFileType())) - { - $maxProgress += ($test->getTotalLineTests() * $lines); - } - } - } - - $this->output->setMaxProgress($maxProgress); - // Now, we basicly do the same as above, but we do really run the tests. // All other tests are specific to files. + /** @var \Phpbb\Epv\Tests\TestInterface $test */ foreach ($this->tests as $test) { if ($test->doValidateDirectory()) @@ -113,10 +81,12 @@ public function runTests() // And over the tests that are available. // First do the full file check. // After that loop over each line and test per line. + /** @var FileInterface $file */ foreach ($this->files as $file) { $linetest = array(); + /** @var \Phpbb\Epv\Tests\TestInterface $test */ foreach ($this->tests as $test) { if ($test->doValidateFile($file->getFileType())) diff --git a/src/Tests/TestStartup.php b/src/Tests/TestStartup.php index 1e9fd13..e54f01e 100644 --- a/src/Tests/TestStartup.php +++ b/src/Tests/TestStartup.php @@ -36,7 +36,7 @@ class TestStartup * @param $type int Type what the location is * @param $location string Location where the extension is * @param $debug boolean if debug is enabled - * @param string $branch When using GIT and GITHUB you can provide a brachname. When empty, defaults to master + * @param string $branch When using GIT and GITHUB you can provide a branch name. When empty, defaults to master */ public function __construct(OutputInterface $output, $type, $location, $debug, $branch = '') { diff --git a/src/Tests/Tests/epv_test_validate_composer.php b/src/Tests/Tests/epv_test_validate_composer.php index 395d4b6..55933f2 100644 --- a/src/Tests/Tests/epv_test_validate_composer.php +++ b/src/Tests/Tests/epv_test_validate_composer.php @@ -25,7 +25,6 @@ public function __construct($debug, OutputInterface $output, $basedir, $namespac parent::__construct($debug, $output, $basedir, $namespace, $titania); $this->fileTypeFull = Type::TYPE_COMPOSER; - $this->totalFileTests = 2; } /** @@ -61,10 +60,6 @@ private function addMessageIfBooleanTrue($addMessage, $type, $message) { $this->output->addMessage($type, $message, $this->file); } - else - { - $this->output->printErrorLevel(); - } } public function testName() diff --git a/src/Tests/Tests/epv_test_validate_directory_structure.php b/src/Tests/Tests/epv_test_validate_directory_structure.php index 1252dbc..80dbb66 100644 --- a/src/Tests/Tests/epv_test_validate_directory_structure.php +++ b/src/Tests/Tests/epv_test_validate_directory_structure.php @@ -14,7 +14,6 @@ use Phpbb\Epv\Tests\BaseTest; class epv_test_validate_directory_structure extends BaseTest{ - // $this->totalDirectoryTests is sizeof this. private $requiredFiles; public function __construct($debug, OutputInterface $output, $basedir, $namespace, $titania) @@ -26,7 +25,7 @@ public function __construct($debug, OutputInterface $output, $basedir, $namespac if (!$titania) { $ns = ''; // Skip checking full directory structure on EPV. - $this->output->addMessage(Output::NOTICE, "Important: The full directory structure is not tested. See the extension validation guidelines for the full directory structure.", null, true); + $this->output->addMessage(Output::NOTICE, "Important: The full directory structure is not tested. See the extension validation guidelines for the full directory structure."); } else { @@ -37,8 +36,6 @@ public function __construct($debug, OutputInterface $output, $basedir, $namespac 'license.txt' => Output::ERROR, $ns . 'composer.json' => Output::FATAL, ); - - $this->totalDirectoryTests = sizeof($this->requiredFiles); } public function validateDirectory(array $dirList) @@ -77,10 +74,6 @@ public function validateDirectory(array $dirList) $this->output->addMessage($type, sprintf("The required file %s is missing from the extension package.", $file)); } } - else - { - $this->output->printErrorLevel(); - } } } diff --git a/src/Tests/Tests/epv_test_validate_event_names.php b/src/Tests/Tests/epv_test_validate_event_names.php index 4443cff..75dd7f7 100644 --- a/src/Tests/Tests/epv_test_validate_event_names.php +++ b/src/Tests/Tests/epv_test_validate_event_names.php @@ -20,8 +20,6 @@ public function __construct($debug, \Phpbb\Epv\Output\OutputInterface $output, $ parent::__construct($debug, $output, $basedir, $namespace, $titania); $this->directory = true; - - $this->totalDirectoryTests = 0; } public function validateDirectory(array $dirList) @@ -40,13 +38,11 @@ public function validateDirectory(array $dirList) catch (\LogicException $e) { - $this->output->inMaxPogress(1); $this->output->addMessage(Output::FATAL, $e->getMessage()); } } $events = $exporter->get_events(); - $this->output->inMaxPogress(sizeof($events) * 3); $vendor = strtolower(str_replace('/', '.', $this->namespace)); // event names are requierd to be lowercase! foreach ($events as $event) @@ -59,20 +55,12 @@ public function validateDirectory(array $dirList) { $this->output->addMessage(Output::FATAL, sprintf('The core vendorname should not be used in event names in %s. Current event name: %s', $event['file'], $event['event'])); } - else - { - $this->output->printErrorLevel(); - } $substr = substr($event['event'], 0, strlen($vendor)); if ($substr != $vendor) { $this->output->addMessage(Output::NOTICE, sprintf('The event name should start with vendor.namespace (Which is %s) but started with %s in %s', $vendor, $substr, $event['file'])); } - else - { - $this->output->printErrorLevel(); - } } } diff --git a/src/Tests/Tests/epv_test_validate_php_functions.php b/src/Tests/Tests/epv_test_validate_php_functions.php index 5d26b07..9486d7b 100644 --- a/src/Tests/Tests/epv_test_validate_php_functions.php +++ b/src/Tests/Tests/epv_test_validate_php_functions.php @@ -150,10 +150,6 @@ private function validate(PHPFileInterface $file) { $this->checkInPhpBB($stmt); } - else - { - $this->output->printErrorLevel(); - } } catch (PHPParser_Error $e) // Catch PhpParser error. { @@ -208,7 +204,6 @@ private function checkInPhpBB(array $stmt) } else { - $this->output->printErrorLevel(); $this->output->writelnIfDebug(sprintf('Did not find IN_PHPBB, but php file contains a namespace with just classes or is a test file.', $this->file->getFilename())); } } @@ -236,11 +231,6 @@ private function parseNodes(array $nodes) } } - if (!$err) - { - $this->output->printErrorLevel(); - } - $this->parseNode($nodes); return; @@ -253,10 +243,6 @@ private function parseNodes(array $nodes) { $this->addMessage(Output::WARNING, 'Besides the namespace, there should be no other statements'); } - else - { - $this->output->printErrorLevel(); - } } } @@ -328,13 +314,11 @@ private function checkInDefined(PHPParser_Node_Stmt_If $node) if ($cond instanceof \PHPParser_Node_Expr_BooleanNot && $cond->expr instanceof PHPParser_Node_Expr_FuncCall && $cond->expr->name == 'defined' && $cond->expr->args[0]->value->value == 'IN_PHPBB') { - $this->output->inMaxPogress(2); if ($node->stmts[0] instanceof PHPParser_Node_Expr_Exit) { // Found IN_PHPBB $this->in_phpbb = true; - $this->output->printErrorLevel(); } else { @@ -349,10 +333,6 @@ private function checkInDefined(PHPParser_Node_Stmt_If $node) unset($node->stmts[0]); $this->parseNode($node->stmts); } - else - { - $this->output->printErrorLevel(); - } } } @@ -396,8 +376,6 @@ private function validateFunctionNames(PHPParser_Node $node) */ private function validateDeprecated($name, PHPParser_Node $node) { - $this->output->inMaxPogress(1); - foreach ($this->deprecated as $depName => $dep) { if ($name == $depName) @@ -413,7 +391,6 @@ private function validateDeprecated($name, PHPParser_Node $node) return; } } - $this->output->printErrorLevel(); } /** @@ -423,9 +400,7 @@ private function validateDeprecated($name, PHPParser_Node $node) */ private function validateDbal($name, PHPParser_Node $node) { - $this->output->inMaxPogress(1); - - foreach ($this->dbal as $dbal) + foreach ($this->dbal as $dbal) { $length = strlen($dbal); @@ -441,7 +416,6 @@ private function validateDbal($name, PHPParser_Node $node) return; } } - $this->output->printErrorLevel(); } /** @@ -451,15 +425,10 @@ private function validateDbal($name, PHPParser_Node $node) */ private function validateExit(PHPParser_Node $node) { - $this->output->inMaxPogress(1); if ($node instanceof PHPParser_Node_Expr_Exit) { $this->addMessage(Output::WARNING, sprintf('Using exit on line %s', $node->getAttribute("startLine"))); } - else - { - $this->output->printErrorLevel(); - } } /** @@ -469,15 +438,10 @@ private function validateExit(PHPParser_Node $node) */ private function validatePrint(PHPParser_Node $node) { - $this->output->inMaxPogress(1); if ($node instanceof PHPParser_Node_Expr_Print || $node instanceof PHPParser_Node_Stmt_Echo) { $this->addMessage(Output::ERROR, sprintf('The template system should be used instead of echo or print on line %s', $node->getAttribute('startLine'))); } - else - { - $this->output->printErrorLevel(); - } } /** @@ -515,7 +479,6 @@ private function validateFunctions($name, PHPParser_Node $node) return; } } - $this->output->printErrorLevel(); } /** diff --git a/src/Tests/Tests/epv_test_validate_routing.php b/src/Tests/Tests/epv_test_validate_routing.php index 2da6ade..cdb20b0 100644 --- a/src/Tests/Tests/epv_test_validate_routing.php +++ b/src/Tests/Tests/epv_test_validate_routing.php @@ -27,7 +27,6 @@ public function __construct($debug, OutputInterface $output, $basedir, $namespac parent::__construct($debug, $output, $basedir, $namespace, $titania); $this->fileTypeFull = Type::TYPE_ROUTING; - $this->totalFileTests = 0; } public function validateFile(FileInterface $file) @@ -50,8 +49,6 @@ private function validate(RoutingFileInterface $file) if (is_array($yml)) { - $this->output->inMaxPogress(sizeof($yml) * 2); - foreach ($yml as $key => $route) { $this->validateRoutingName($key, $file); @@ -77,18 +74,10 @@ private function validateRoutingName($route, RoutingFileInterface $file) { $this->output->addMessage(Output::FATAL, sprintf('The core vendorname should not be used in route names in %s. Current route name: %s', $file->getFilename(), $route)); } - else - { - $this->output->printErrorLevel(); - } if (substr($route, 0, strlen($vendor)) != $vendor) { $this->output->addMessage(Output::WARNING, sprintf('The route name should start with vendor_namespace (which is %s) but started with %s in %s', $vendor, $route, $file->getFilename())); } - else - { - $this->output->printErrorLevel(); - } } /** diff --git a/src/Tests/Tests/epv_test_validate_service.php b/src/Tests/Tests/epv_test_validate_service.php index 3069df8..6f15c05 100644 --- a/src/Tests/Tests/epv_test_validate_service.php +++ b/src/Tests/Tests/epv_test_validate_service.php @@ -26,7 +26,6 @@ public function __construct($debug, OutputInterface $output, $basedir, $namespac parent::__construct($debug, $output, $basedir, $namespace, $titania); $this->fileTypeFull = Type::TYPE_SERVICE; - $this->totalFileTests = 1; } public function validateFile(FileInterface $file) @@ -50,15 +49,9 @@ private function validate(ServiceFileInterface $file) { $this->output->addMessage(Output::WARNING, "Service does not contain a 'services' key."); } - else - { - $this->output->printErrorLevel(); - } if (is_array($yml['services'])) { - $this->output->inMaxPogress(sizeof($yml['services']) * 2); - foreach ($yml['services'] as $key => $service) { $this->validateServiceName($key, $file); @@ -84,18 +77,10 @@ private function validateServiceName($service, ServiceFileInterface $file) { $this->output->addMessage(Output::FATAL, sprintf('The core vendorname should not be used in event names in %s. Current event name: %s', $file->getFilename(), $service)); } - else - { - $this->output->printErrorLevel(); - } if (substr($service, 0, strlen($vendor)) != $vendor) { $this->output->addMessage(Output::WARNING, sprintf('The service name should start with vendor.namespace (which is %s) but started with %s in %s', $vendor, $service, $file->getFilename())); } - else - { - $this->output->printErrorLevel(); - } } /**