Skip to content

Commit 0b407a4

Browse files
committed
Application::run method returns application return code
1 parent 6d488c7 commit 0b407a4

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

parallel-lint

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ either expressed or implied, of the FreeBSD Project.
3131
*/
3232

3333
if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50400) {
34-
echo "PHP Parallel Lint require PHP 5.4.0 or newer.", PHP_EOL;
35-
die(254);
34+
fwrite(STDERR, "PHP Parallel Lint require PHP 5.4.0 or newer." . PHP_EOL);
35+
exit(254);
3636
}
3737

3838
$autoloadLocations = [
@@ -60,4 +60,4 @@ if (!$loaded) {
6060
}
6161

6262
$app = new JakubOnderka\PhpParallelLint\Application();
63-
$app->run();
63+
exit($app->run());

src/Application.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,49 +13,58 @@ class Application
1313

1414
/**
1515
* Run the application
16+
* @return int Return code
1617
*/
1718
public function run()
1819
{
1920
if (in_array('proc_open', explode(',', ini_get('disable_functions')))) {
2021
echo "Function 'proc_open' is required, but it is disabled by disable_functions setting.", PHP_EOL;
21-
die(self::FAILED);
22+
return self::FAILED;
2223
}
24+
2325
if (in_array('-h', $_SERVER['argv']) || in_array('--help', $_SERVER['argv'])) {
2426
$this->showUsage();
27+
return self::SUCCESS;
2528
}
29+
2630
if (in_array('-V', $_SERVER['argv']) || in_array('--version', $_SERVER['argv'])) {
2731
$this->showVersion();
28-
die();
32+
return self::SUCCESS;
2933
}
34+
3035
try {
3136
$settings = Settings::parseArguments($_SERVER['argv']);
3237
if ($settings->stdin) {
3338
$settings->addPaths(Settings::getPathsFromStdIn());
3439
}
3540
if (empty($settings->paths)) {
3641
$this->showUsage();
42+
return self::FAILED;
3743
}
3844
$manager = new Manager;
3945
$result = $manager->run($settings);
4046
if ($settings->ignoreFails) {
41-
die($result->hasSyntaxError() ? self::WITH_ERRORS : self::SUCCESS);
47+
return $result->hasSyntaxError() ? self::WITH_ERRORS : self::SUCCESS;
4248
} else {
43-
die($result->hasError() ? self::WITH_ERRORS : self::SUCCESS);
49+
return $result->hasError() ? self::WITH_ERRORS : self::SUCCESS;
4450
}
51+
4552
} catch (InvalidArgumentException $e) {
4653
echo "Invalid option {$e->getArgument()}", PHP_EOL, PHP_EOL;
4754
$this->showOptions();
48-
die(self::FAILED);
55+
return self::FAILED;
56+
4957
} catch (Exception $e) {
5058
if (isset($settings) && $settings->format === Settings::FORMAT_JSON) {
5159
echo json_encode($e);
5260
} else {
5361
echo $e->getMessage(), PHP_EOL;
5462
}
55-
die(self::FAILED);
56-
} catch (Exception $e) {
63+
return self::FAILED;
64+
65+
} catch (\Exception $e) {
5766
echo $e->getMessage(), PHP_EOL;
58-
die(self::FAILED);
67+
return self::FAILED;
5968
}
6069
}
6170

@@ -110,6 +119,5 @@ private function showUsage()
110119
111120
USAGE;
112121
$this->showOptions();
113-
die();
114122
}
115123
}

src/Manager.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class Manager
1212
/**
1313
* @param null|Settings $settings
1414
* @return Result
15+
* @throws Exception
1516
* @throws \Exception
1617
*/
1718
public function run(Settings $settings = null)

0 commit comments

Comments
 (0)