Skip to content

Add some improvements #338

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
36 changes: 17 additions & 19 deletions src/PHPJasper.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class PHPJasper
/**
* @var bool
*/
protected $windows;
protected $isWindows;

/**
* @var array
Expand Down Expand Up @@ -76,15 +76,15 @@ public function __construct()
{
$this->executable = 'jasperstarter';
$this->pathExecutable = __DIR__ . '/../bin/jasperstarter/bin';
$this->windows = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? true : false;
$this->isWindows = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
}

/**
* @return string
*/
private function checkServer()
{
return $this->command = $this->windows ? $this->executable : './' . $this->executable;
return $this->command = $this->isWindows ? $this->executable : './' . $this->executable;
}

/**
Expand Down Expand Up @@ -199,14 +199,11 @@ protected function parseProcessOptions(array $options)
*/
protected function validateFormat($format)
{
if (!is_array($format)) {
$format = [$format];
}
$formatsToValidate = is_array($format) ? $format : [$format];
$invalidFormats = array_diff($formatsToValidate, $this->formats);

foreach ($format as $value) {
if (!in_array($value, $this->formats)) {
throw new Exception\InvalidFormat();
}
if (!empty($invalidFormats)) {
throw new Exception\InvalidFormat();
}
}

Expand All @@ -229,16 +226,19 @@ public function listParameters(string $input)
}

/**
* @param bool $user
* @param string|null $user
* @return mixed
* @throws Exception\InvalidCommandExecutable
* @throws Exception\InvalidResourceDirectory
* @throws Exception\ErrorCommandExecutable
*/
public function execute($user = false)
public function execute(?string $user = null)
{
$this->validateExecute();
$this->addUserToCommand($user);

if (!is_null($user) && !$this->isWindows) {
$this->addUserToCommand($user);
}

$output = [];
$returnVar = 0;
Expand Down Expand Up @@ -268,17 +268,15 @@ public function output()
*/
public function printOutput()
{
print $this->command . "\n";
print $this->command . PHP_EOL;
}

/**
* @param $user
* @param string $user
*/
protected function addUserToCommand($user)
protected function addUserToCommand(string $user)
{
if ($user && !$this->windows) {
$this->command = 'su -u ' . $user . " -c \"" . $this->command . "\"";
}
$this->command = 'su -u ' . $user . " -c \"" . $this->command . "\"";
}

/**
Expand Down