Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not stop at the first PHP error/warning in files:scan #37944

Merged
merged 3 commits into from
May 9, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions apps/files/lib/Command/Scan.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
return 1;
}

$this->initTools();
$this->initTools($output);

$user_count = 0;
foreach ($users as $user) {
Expand Down Expand Up @@ -236,31 +236,35 @@ protected function execute(InputInterface $input, OutputInterface $output): int
/**
* Initialises some useful tools for the Command
*/
protected function initTools() {
protected function initTools(OutputInterface $output) {

Check notice

Code scanning / Psalm

MissingReturnType

Method OCA\Files\Command\Scan::initTools does not have a return type, expecting void
// Start the timer
$this->execTime = -microtime(true);
// Convert PHP errors to exceptions
set_error_handler([$this, 'exceptionErrorHandler'], E_ALL);
set_error_handler(
fn (int $severity, string $message, string $file, int $line): bool =>
$this->exceptionErrorHandler($output, $severity, $message, $file, $line),
E_ALL
);
}

/**
* Processes PHP errors as exceptions in order to be able to keep track of problems
* Processes PHP errors in order to be able to show them in the output
*
* @see https://www.php.net/manual/en/function.set-error-handler.php
*
* @param int $severity the level of the error raised
* @param string $message
* @param string $file the filename that the error was raised in
* @param int $line the line number the error was raised
*
* @throws \ErrorException
*/
public function exceptionErrorHandler($severity, $message, $file, $line) {
if (!(error_reporting() & $severity)) {
// This error code is not included in error_reporting
return;
public function exceptionErrorHandler(OutputInterface $output, int $severity, string $message, string $file, int $line): bool {
if (($severity === E_DEPRECATED) || ($severity === E_USER_DEPRECATED)) {
// Do not show deprecation warnings
return false;
}
throw new \ErrorException($message, 0, $severity, $file, $line);
$e = new \ErrorException($message, 0, $severity, $file, $line);
$output->writeln("\t<error>$e</error>");
return true;
}

/**
Expand Down