Skip to content

Commit

Permalink
Codestyle
Browse files Browse the repository at this point in the history
  • Loading branch information
SmetDenis committed Nov 13, 2021
1 parent c05585a commit 38b1dc3
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 70 deletions.
8 changes: 4 additions & 4 deletions src/CliApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function registerCommandsByPath(
string $gloabalNamespace,
bool $strictMode = true
): bool {
if ($strictMode && !is_dir($commandsDir)) {
if ($strictMode && !\is_dir($commandsDir)) {
throw new Exception('First argument is not directory!');
}

Expand All @@ -57,16 +57,16 @@ public function registerCommandsByPath(
}

foreach ($files as $file) {
if (!file_exists($file)) {
if (!\file_exists($file)) {
continue;
}

require_once $file;

$taskNamespace = trim(str_replace('/', '\\', (string)strstr(\dirname($file), 'Commands')));
$taskNamespace = \trim(\str_replace('/', '\\', (string)\strstr(\dirname($file), 'Commands')));
$commandClassName = "{$gloabalNamespace}\\{$taskNamespace}\\" . FS::filename($file);

if (class_exists($commandClassName)) {
if (\class_exists($commandClassName)) {
$reflection = new \ReflectionClass($commandClassName);
} else {
throw new Exception("Command/Class \"{$commandClassName}\" can'be loaded from the file \"{$file}\"");
Expand Down
8 changes: 4 additions & 4 deletions src/CliCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected function getOpt(string $optionName, bool $canBeArray = true)
{
$value = $this->input->getOption($optionName);

if ($canBeArray && is_array($value)) {
if ($canBeArray && \is_array($value)) {
return Arr::last($value);
}

Expand Down Expand Up @@ -207,8 +207,8 @@ protected static function getStdIn(): ?string

if (null === $result) {
$result = '';
while (!feof(STDIN)) {
$result .= fread(STDIN, 1024);
while (!\feof(\STDIN)) {
$result .= \fread(\STDIN, 1024);
}
}

Expand Down Expand Up @@ -253,7 +253,7 @@ private function showProfiler(): void

[$totalTime, $curMemory, $maxMemory] = $this->helper->getProfileDate();

$this->_(implode('; ', [
$this->_(\implode('; ', [
"Memory Usage/Peak: <green>{$curMemory}</green>/<green>{$maxMemory}</green>",
"Execution Time: <green>{$totalTime} sec</green>"
]));
Expand Down
28 changes: 14 additions & 14 deletions src/CliCommandMultiProc.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ protected function executeMultiProcessAction(): int
$this->afterFinishAllProcesses($this->procPool);

$errorList = $this->getErrorList();
if (count($errorList) > 0) {
throw new Exception(implode("\n" . str_repeat('-', 60) . "\n", $errorList));
if (\count($errorList) > 0) {
throw new Exception(\implode("\n" . \str_repeat('-', 60) . "\n", $errorList));
}

$warningList = $this->getWarningList();
if (count($warningList) > 0) {
$this->_(implode("\n" . str_repeat('-', 60) . "\n", $warningList), 'warn');
if (\count($warningList) > 0) {
$this->_(\implode("\n" . \str_repeat('-', 60) . "\n", $warningList), 'warn');
}

return 0;
Expand Down Expand Up @@ -213,7 +213,7 @@ private function initProcManager(
private function createSubProcess(string $procId): Process
{
// Prepare option list from the parent process
$options = array_filter($this->input->getOptions(), static function ($optionValue): bool {
$options = \array_filter($this->input->getOptions(), static function ($optionValue): bool {
return $optionValue !== false && $optionValue !== '';
});

Expand All @@ -228,7 +228,7 @@ private function createSubProcess(string $procId): Process
$argumentsList = [];

foreach ($arguments as $argKey => $argValue) {
if (is_array($argValue)) {
if (\is_array($argValue)) {
continue;
}

Expand All @@ -241,19 +241,19 @@ private function createSubProcess(string $procId): Process

// Build full command line
$process = Process::fromShellCommandline(
Cli::build(implode(' ', [
Cli::build(\implode(' ', [
Sys::getBinary(),
Helper::getBinPath(),
$this->getName(),
implode(" ", $argumentsList)
\implode(" ", $argumentsList)
]), $options),
Helper::getRootPath(),
null,
null,
$this->getMaxTimeout()
);

$this->procPool[spl_object_id($process)] = [
$this->procPool[\spl_object_id($process)] = [
'command' => $process->getCommandLine(),
'proc_id' => $procId,
'exit_code' => null,
Expand All @@ -272,15 +272,15 @@ private function createSubProcess(string $procId): Process
*/
private function getErrorList(): array
{
return array_reduce($this->procPool, function (array $acc, array $procInfo): array {
return \array_reduce($this->procPool, function (array $acc, array $procInfo): array {
if ($procInfo['reached_timeout']) {
$acc[] = implode("\n", [
$acc[] = \implode("\n", [
"Command : {$procInfo['command']}",
"Error : The process with ID \"{$procInfo['proc_id']}\""
. " exceeded the timeout of {$this->getMaxTimeout()} seconds.",
]);
} elseif ($procInfo['err_out'] && $procInfo['exit_code'] > 0) {
$acc[] = implode("\n", [
$acc[] = \implode("\n", [
"Command : {$procInfo['command']}",
"Code : {$procInfo['exit_code']}",
"Error : {$procInfo['err_out']}",
Expand All @@ -297,9 +297,9 @@ private function getErrorList(): array
*/
private function getWarningList(): array
{
return array_reduce($this->procPool, static function (array $acc, array $procInfo): array {
return \array_reduce($this->procPool, static function (array $acc, array $procInfo): array {
if ($procInfo['err_out'] && $procInfo['exit_code'] === 0) {
$acc[] = implode("\n", [
$acc[] = \implode("\n", [
"Command : {$procInfo['command']}",
"Warning : {$procInfo['err_out']}",
"StdOut : {$procInfo['std_out']}",
Expand Down
28 changes: 14 additions & 14 deletions src/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Helper
*/
public function __construct(InputInterface $input, OutputInterface $output)
{
$this->startTimer = microtime(true);
$this->startTimer = \microtime(true);
$this->input = $input;
$this->output = self::addOutputStyles($output);

Expand Down Expand Up @@ -123,7 +123,7 @@ public function getErrOutput(): OutputInterface
*/
public static function getRootPath(): string
{
$rootPath = defined('JBZOO_PATH_ROOT') ? (string)JBZOO_PATH_ROOT : null;
$rootPath = \defined('JBZOO_PATH_ROOT') ? (string)\JBZOO_PATH_ROOT : null;
if (!$rootPath) {
return Env::string('JBZOO_PATH_ROOT');
}
Expand All @@ -136,7 +136,7 @@ public static function getRootPath(): string
*/
public static function getBinPath(): string
{
$binPath = defined('JBZOO_PATH_BIN') ? (string)JBZOO_PATH_BIN : null;
$binPath = \defined('JBZOO_PATH_BIN') ? (string)\JBZOO_PATH_BIN : null;
if (!$binPath) {
return Env::string('JBZOO_PATH_BIN');
}
Expand Down Expand Up @@ -171,9 +171,9 @@ public static function addOutputStyles(OutputInterface $output): OutputInterface
public function getProfileDate(): array
{
return [
number_format(microtime(true) - $this->startTimer, 3),
FS::format(memory_get_usage(false)),
FS::format(memory_get_peak_usage(false)),
\number_format(\microtime(true) - $this->startTimer, 3),
FS::format(\memory_get_usage(false)),
FS::format(\memory_get_peak_usage(false)),
];
}

Expand All @@ -190,7 +190,7 @@ public function _($messages, string $verboseLevel = ''): void
{
$verboseLevel = \strtolower(\trim($verboseLevel));

if (is_array($messages)) {
if (\is_array($messages)) {
foreach ($messages as $message) {
$this->_($message, $verboseLevel);
}
Expand Down Expand Up @@ -254,7 +254,7 @@ public static function findMaxLength(array $items): int
{
$result = 0;
foreach ($items as $item) {
$tmpMax = strlen($item);
$tmpMax = \strlen($item);
if ($result < $tmpMax) {
$result = $tmpMax;
}
Expand All @@ -269,19 +269,19 @@ public static function findMaxLength(array $items): int
*/
public static function renderList(array $metrics): string
{
$maxLength = self::findMaxLength(array_keys($metrics));
$maxLength = self::findMaxLength(\array_keys($metrics));
$lines = [];

foreach ($metrics as $metricKey => $metricTmpl) {
$currentLength = strlen($metricKey);
$lines[] = implode('', [
$currentLength = \strlen((string)$metricKey);
$lines[] = \implode('', [
$metricKey,
str_repeat(' ', $maxLength - $currentLength),
\str_repeat(' ', $maxLength - $currentLength),
': ',
implode('; ', (array)$metricTmpl)
\implode('; ', (array)$metricTmpl)
]);
}

return implode("\n", array_filter($lines)) . "\n";
return \implode("\n", \array_filter($lines)) . "\n";
}
}
2 changes: 1 addition & 1 deletion src/Icons.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public static function getRandomIcon(string $group, bool $isDecorated): string
}

$icons = self::$icons[$group];
shuffle($icons);
\shuffle($icons);

return $icons[0];
}
Expand Down
Loading

0 comments on commit 38b1dc3

Please sign in to comment.