Skip to content

Commit

Permalink
Merge pull request #165 from matteosister/hotfixes-4.1.0
Browse files Browse the repository at this point in the history
Hotfixes 4.1.0
  • Loading branch information
imunhatep authored Mar 23, 2020
2 parents 9c2be09 + 5c28c99 commit ab9f70b
Show file tree
Hide file tree
Showing 94 changed files with 817 additions and 639 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"description": "An abstraction layer for git written in PHP",
"scripts": {
"tests": "./vendor/bin/phpunit",
"check-cs": "./vendor/bin/phpcs --exclude=Generic.Files.LineLength --standard=PSR2 src tests",
"fix-cs": "./vendor/bin/phpcbf --standard=PSR2 src tests"
"check-cs": "./vendor/bin/ecs check",
"fix-cs": "./vendor/bin/ecs check --fix"
},
"keywords": [
"git"
Expand All @@ -30,7 +30,7 @@
"mockery/mockery": "~1.1",
"symfony/var-dumper": "~3.0|~4.0|~5.0",
"rector/rector": "^0.7.6",
"squizlabs/php_codesniffer": "^3.5.4"
"symplify/easy-coding-standard": "^v7.2.5"
},
"minimum-stability": "stable",
"autoload": {
Expand Down
24 changes: 24 additions & 0 deletions ecs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# ecs.yml
parameters:
sets:
- 'clean-code'
- 'psr2'
- 'psr12'
paths:
- 'src'
- 'tests'

# Skip two possible bugs in SlevomatCodingStandard\Sniffs\Variables\UnusedVariableSniff.UnusedVariable
skip:
'Unused variable $deleted.':
- 'src/GitElephant/Objects/Diff/DiffChunk.php'
'Unused variable $new.':
- 'src/GitElephant/Objects/Diff/DiffChunk.php'

services:
PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer:
syntax: short
Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer:
max_line_length: 100 # default: 120
break_long_lines: true # default: true
inline_short_lines: false # default: true
38 changes: 24 additions & 14 deletions src/GitElephant/Command/BaseCommand.php
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* GitElephant - An abstraction layer for git written in PHP
* Copyright (C) 2013 Matteo Giachino
Expand All @@ -19,8 +20,8 @@

namespace GitElephant\Command;

use \GitElephant\Repository;
use \PhpCollection\Map;
use GitElephant\Repository;
use PhpCollection\Map;

/**
* BaseCommand
Expand All @@ -43,35 +44,35 @@ class BaseCommand
*
* @var array
*/
private $configs = array();
private $configs = [];

/**
* global configs
*
* @var array
*/
private $globalConfigs = array();
private $globalConfigs = [];

/**
* global options
*
* @var array
*/
private $globalOptions = array();
private $globalOptions = [];

/**
* the command arguments
*
* @var array
*/
private $commandArguments = array();
private $commandArguments = [];

/**
* the global command arguments
*
* @var array
*/
private $globalCommandArguments = array();
private $globalCommandArguments = [];

/**
* the command subject
Expand Down Expand Up @@ -134,8 +135,8 @@ public function __construct(Repository $repo = null)
public function clearAll(): void
{
$this->commandName = null;
$this->configs = array();
$this->commandArguments = array();
$this->configs = [];
$this->commandArguments = [];
$this->commandSubject = null;
$this->commandSubject2 = null;
$this->path = null;
Expand Down Expand Up @@ -246,7 +247,7 @@ protected function addGlobalCommandArgument($commandArgument): void
*/
protected function getCommandArguments(): array
{
return ($this->commandArguments !== []) ? $this->commandArguments : array();
return $this->commandArguments !== [] ? $this->commandArguments : [];
}

/**
Expand Down Expand Up @@ -290,9 +291,12 @@ protected function addPath($path): void
*
* @return array Associative array of valid, normalized command options
*/
public function normalizeOptions(array $options = array(), array $switchOptions = array(), $valueOptions = array()): array
{
$normalizedOptions = array();
public function normalizeOptions(
array $options = [],
array $switchOptions = [],
$valueOptions = []
): array {
$normalizedOptions = [];

foreach ($options as $option) {
if (array_key_exists($option, $switchOptions)) {
Expand All @@ -302,7 +306,7 @@ public function normalizeOptions(array $options = array(), array $switchOptions
if ((is_countable($parts) ? count($parts) : 0) > 0) {
$optionName = $parts[0];
if (in_array($optionName, $valueOptions)) {
$value = ($parts[1] === '=') ? $option : array($parts[0], $parts[2]);
$value = $parts[1] === '=' ? $option : [$parts[0], $parts[2]];
$normalizedOptions[$optionName] = $value;
}
}
Expand Down Expand Up @@ -349,6 +353,7 @@ private function getCLICommandArguments(): string
if (count($combinedArguments) > 0) {
$command .= ' ' . implode(' ', array_map('escapeshellarg', $combinedArguments));
}

return $command;
}

Expand Down Expand Up @@ -381,6 +386,7 @@ private function getCLIConfigs(): string
);
}
}

return $command;
}

Expand All @@ -397,6 +403,7 @@ private function getCLIGlobalOptions(): string
$command .= sprintf(' %s=%s', escapeshellarg($name), escapeshellarg($value));
}
}

return $command;
}

Expand All @@ -411,6 +418,7 @@ private function getCLIPath(): string
if (!is_null($this->path)) {
$command .= sprintf(' -- %s', escapeshellarg($this->path));
}

return $command;
}

Expand Down Expand Up @@ -443,6 +451,7 @@ private function getCLISubjects(): string
$command .= escapeshellarg($this->commandSubject2);
}
}

return $command;
}

Expand All @@ -454,6 +463,7 @@ public function getBinaryVersion(): string
if (is_null($this->binaryVersion)) {
$this->binaryVersion = $this->repo->getCaller()->getBinaryVersion();
}

return $this->binaryVersion;
}
}
19 changes: 10 additions & 9 deletions src/GitElephant/Command/BranchCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* GitElephant - An abstraction layer for git written in PHP
* Copyright (C) 2013 Matteo Giachino
Expand All @@ -19,7 +20,7 @@

namespace GitElephant\Command;

use \GitElephant\Repository;
use GitElephant\Repository;

/**
* Branch command generator
Expand All @@ -28,7 +29,7 @@
*/
class BranchCommand extends BaseCommand
{
const BRANCH_COMMAND = 'branch';
public const BRANCH_COMMAND = 'branch';

/**
* constructor
Expand All @@ -49,7 +50,7 @@ public function __construct(Repository $repo = null)
* @throws \RuntimeException
* @return string the command
*/
public function contains($reference): string
public function contains(string $reference): string
{
$this->clearAll();
$this->addCommandName(self::BRANCH_COMMAND);
Expand All @@ -68,7 +69,7 @@ public function contains($reference): string
* @throws \RuntimeException
* @return string the command
*/
public function create($name, $startPoint = null): string
public function create(string $name, string $startPoint = null): string
{
$this->clearAll();
$this->addCommandName(self::BRANCH_COMMAND);
Expand All @@ -89,7 +90,7 @@ public function create($name, $startPoint = null): string
* @throws \RuntimeException
* @return string the command
*/
public function listBranches($all = false, $simple = false): string
public function listBranches(bool $all = false, bool $simple = false): string
{
$this->clearAll();
$this->addCommandName(self::BRANCH_COMMAND);
Expand Down Expand Up @@ -118,7 +119,7 @@ public function listBranches($all = false, $simple = false): string
* @throws \RuntimeException
* @return string the command
*/
public function lists($all = false, $simple = false): string
public function lists($all = false, bool $simple = false): string
{
return $this->listBranches($all, $simple);
}
Expand All @@ -134,7 +135,7 @@ public function lists($all = false, $simple = false): string
* @throws \RuntimeException
* @return string
*/
public function singleInfo($name, $all = false, $simple = false, $verbose = false): string
public function singleInfo(string $name, bool $all = false, bool $simple = false, bool $verbose = false): string
{
$this->clearAll();
$this->addCommandName(self::BRANCH_COMMAND);
Expand Down Expand Up @@ -164,9 +165,9 @@ public function singleInfo($name, $all = false, $simple = false, $verbose = fals
* @throws \RuntimeException
* @return string the command
*/
public function delete($name, $force = false): string
public function delete(string $name, bool $force = false): string
{
$arg = ($force) ? '-D' : '-d';
$arg = $force ? '-D' : '-d';
$this->clearAll();
$this->addCommandName(self::BRANCH_COMMAND);
$this->addCommandArgument($arg);
Expand Down
7 changes: 4 additions & 3 deletions src/GitElephant/Command/Caller/AbstractCaller.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* GitElephant - An abstraction layer for git written in PHP
* Copyright (C) 2013 Matteo Giachino
Expand Down Expand Up @@ -45,7 +46,7 @@ abstract class AbstractCaller implements CallerInterface
*
* @var array
*/
protected $outputLines = array();
protected $outputLines = [];

/**
* @inheritdoc
Expand Down Expand Up @@ -101,10 +102,10 @@ public function getOutput(): string
*
* @return array
*/
public function getOutputLines($stripBlankLines = false): array
public function getOutputLines(bool $stripBlankLines = false): array
{
if ($stripBlankLines) {
$output = array();
$output = [];
foreach ($this->outputLines as $line) {
if ('' !== $line) {
$output[] = $line;
Expand Down
29 changes: 19 additions & 10 deletions src/GitElephant/Command/Caller/Caller.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
namespace GitElephant\Command\Caller;

use GitElephant\Exception\InvalidRepositoryPathException;
use \Symfony\Component\Process\Process;
use Symfony\Component\Process\Process;

/**
* Caller
Expand Down Expand Up @@ -58,11 +58,9 @@ public function __construct($gitPath, $repositoryPath)
$gitPath = exec('which git');
}
$this->setBinaryPath($gitPath);

if (!is_dir($repositoryPath)) {
throw new InvalidRepositoryPathException($repositoryPath);
}

$this->repositoryPath = $repositoryPath;
}

Expand All @@ -71,7 +69,7 @@ public function __construct($gitPath, $repositoryPath)
*
* @param string $cmd the command to execute
* @param bool $git if the command is git or a generic command
* @param null $cwd the directory where the command must be executed
* @param string $cwd the directory where the command must be executed
* @param array $acceptedExitCodes exit codes accepted to consider the command execution successful
*
* @throws \RuntimeException
Expand All @@ -81,8 +79,12 @@ public function __construct($gitPath, $repositoryPath)
* @throws \Symfony\Component\Process\Exception\LogicException
* @return Caller
*/
public function execute($cmd, $git = true, $cwd = null, $acceptedExitCodes = array(0)): \GitElephant\Command\Caller\CallerInterface
{
public function execute(
string $cmd,
bool $git = true,
string $cwd = null,
array $acceptedExitCodes = [0]
): CallerInterface {
if ($git) {
$cmd = $this->getBinaryPath() . ' ' . $cmd;
}
Expand All @@ -95,7 +97,14 @@ public function execute($cmd, $git = true, $cwd = null, $acceptedExitCodes = arr
if (is_null($cwd) || !is_dir($cwd)) {
$cwd = $this->repositoryPath;
}
$process = Process::fromShellCommandline($cmd, $cwd);

if (method_exists(Process::class, 'fromShellCommandline')) {
$process = Process::fromShellCommandline($cmd, $cwd);
} else {
// compatibility fix required for symfony/process versions prior to v4.2.
$process = new Process($cmd, $cwd);
}

$process->setTimeout(15000);
$process->run();
if (!in_array($process->getExitCode(), $acceptedExitCodes)) {
Expand All @@ -105,8 +114,8 @@ public function execute($cmd, $git = true, $cwd = null, $acceptedExitCodes = arr
$text .= "\n" . $process->getOutput();
throw new \RuntimeException($text);
}

$this->rawOutput = $process->getOutput();

// rtrim values
$values = array_map('rtrim', explode(PHP_EOL, $process->getOutput()));
$this->outputLines = $values;
Expand All @@ -131,10 +140,10 @@ public function getOutput(): string
*
* @return array
*/
public function getOutputLines($stripBlankLines = false): array
public function getOutputLines(bool $stripBlankLines = false): array
{
if ($stripBlankLines) {
$output = array();
$output = [];
foreach ($this->outputLines as $line) {
if ('' !== $line) {
$output[] = $line;
Expand Down
Loading

0 comments on commit ab9f70b

Please sign in to comment.