Shell: Add more types

Change-Id: I315f0bb2746ccf7249b8d622a153162dd634ff2e
This commit is contained in:
Max Semenik 2019-10-28 21:48:29 -07:00 committed by Jforrester
parent b73b4bc550
commit 3f94708eff
4 changed files with 19 additions and 17 deletions

View file

@ -185,7 +185,7 @@ class Command {
* @param string $method
* @return $this
*/
public function profileMethod( $method ): Command {
public function profileMethod( string $method ): Command {
$this->method = $method;
return $this;
@ -197,7 +197,7 @@ class Command {
* @param string|null $inputString
* @return $this
*/
public function input( $inputString ): Command {
public function input( ?string $inputString ): Command {
$this->inputString = is_null( $inputString ) ? null : (string)$inputString;
return $this;
@ -210,7 +210,7 @@ class Command {
* @param bool $yesno
* @return $this
*/
public function includeStderr( $yesno = true ): Command {
public function includeStderr( bool $yesno = true ): Command {
$this->doIncludeStderr = $yesno;
return $this;
@ -222,7 +222,7 @@ class Command {
* @param bool $yesno
* @return $this
*/
public function logStderr( $yesno = true ): Command {
public function logStderr( bool $yesno = true ): Command {
$this->doLogStderr = $yesno;
return $this;
@ -247,7 +247,7 @@ class Command {
* @param int $restrictions
* @return $this
*/
public function restrict( $restrictions ): Command {
public function restrict( int $restrictions ): Command {
$this->restrictions |= $restrictions;
return $this;
@ -260,7 +260,7 @@ class Command {
*
* @return bool
*/
protected function hasRestriction( $restriction ) {
protected function hasRestriction( int $restriction ): bool {
return ( $this->restrictions & $restriction ) === $restriction;
}
@ -286,7 +286,7 @@ class Command {
* @param string $command Already-escaped command to run
* @return array [ command, whether to use log pipe ]
*/
protected function buildFinalCommand( $command ) {
protected function buildFinalCommand( string $command ): array {
$envcmd = '';
foreach ( $this->env as $k => $v ) {
if ( wfIsWindows() ) {
@ -345,7 +345,7 @@ class Command {
* @throws ProcOpenError
* @throws ShellDisabledError
*/
public function execute() {
public function execute(): Result {
$this->everExecuted = true;
$profileMethod = $this->method ?: wfGetCaller();
@ -553,7 +553,7 @@ class Command {
*
* @return string
*/
public function __toString() {
public function __toString(): string {
return "#Command: {$this->command}";
}
}

View file

@ -63,7 +63,7 @@ class CommandFactory {
$this->cgroup = $cgroup;
if ( $restrictionMethod === 'autodetect' ) {
// On Linux systems check for firejail
if ( PHP_OS === 'Linux' && $this->findFirejail() !== false ) {
if ( PHP_OS === 'Linux' && $this->findFirejail() !== null ) {
$this->restrictionMethod = 'firejail';
} else {
$this->restrictionMethod = false;
@ -74,7 +74,7 @@ class CommandFactory {
$this->setLogger( new NullLogger() );
}
private function findFirejail() {
private function findFirejail(): ?string {
if ( $this->firejail === null ) {
$this->firejail = ExecutableFinder::findInDefaultPaths( 'firejail' );
}
@ -88,7 +88,7 @@ class CommandFactory {
* @param bool $yesno
* @see Command::logStderr
*/
public function logStderr( $yesno = true ) {
public function logStderr( bool $yesno = true ): void {
$this->doLogStderr = $yesno;
}

View file

@ -43,7 +43,7 @@ class FirejailCommand extends Command {
/**
* @param string $firejail Path to firejail
*/
public function __construct( $firejail ) {
public function __construct( string $firejail ) {
parent::__construct();
$this->firejail = $firejail;
}
@ -59,7 +59,7 @@ class FirejailCommand extends Command {
/**
* @inheritDoc
*/
protected function buildFinalCommand( $command ) {
protected function buildFinalCommand( string $command ): array {
// If there are no restrictions, don't use firejail
if ( $this->restrictions === 0 ) {
$splitCommand = explode( ' ', $command, 2 );

View file

@ -134,7 +134,7 @@ class Shell {
*
* @return bool
*/
public static function isDisabled() {
public static function isDisabled(): bool {
static $disabled = null;
if ( is_null( $disabled ) ) {
@ -160,7 +160,7 @@ class Shell {
* array of strings parameter. Null values are ignored.
* @return string
*/
public static function escape( ...$args ) {
public static function escape( ...$args ): string {
if ( count( $args ) === 1 && is_array( reset( $args ) ) ) {
// If only one argument has been passed, and that argument is an array,
// treat it as a list of arguments
@ -233,7 +233,9 @@ class Shell {
* @phan-param array{php?:string,wrapper?:string} $options
* @return Command
*/
public static function makeScriptCommand( $script, $parameters, $options = [] ): Command {
public static function makeScriptCommand(
string $script, array $parameters, $options = []
): Command {
global $wgPhpCli;
// Give site config file a chance to run the script in a wrapper.
// The caller may likely want to call wfBasename() on $script.