Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
tests:
uses: janpecha/actions/.github/workflows/nette-tester-library.yml@master
with:
phpVersions: '["5.6", "7.0", "7.1", "7.2", "7.3", "7.4", "8.0", "8.1", "8.2", "8.3"]'
phpVersions: '["7.4", "8.0", "8.1", "8.2", "8.3", "8.4"]'
lowestDependencies: true

coding-style:
Expand Down
7 changes: 6 additions & 1 deletion code-checker.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
<?php

return function (JP\CodeChecker\CheckerConfig $config) {
$config->setPhpVersion(new JP\CodeChecker\Version('5.6.0'));
$config->setPhpVersion(new JP\CodeChecker\Version('7.4.0'));
$config->addPath('./src');
$config->addPath('./tests');
$config->setParameters([
'php' => [
'strictTypes' => FALSE,
],
]);
JP\CodeChecker\Sets\CzProjectMinimum::configure($config);
};
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
{"type": "other", "url": "https://www.janpecha.cz/donate/git-php/"}
],
"require": {
"php": ">=5.6.0"
"php": ">=7.4.0"
},
"autoload": {
"classmap": ["src/"]
},
"require-dev": {
"nette/tester": "^2.0"
"nette/tester": "^2.4"
}
}
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Installation
composer require czproject/git-php
```

Library requires PHP 5.6 or later and `git` client (path to Git must be in system variable `PATH`).
Library requires PHP 7.4 or later and `git` client (path to Git must be in system variable `PATH`).

Git installers:

Expand Down
2 changes: 1 addition & 1 deletion src/CommandProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct($mode = self::MODE_DETECT)
* @param array<string, scalar>|NULL $env
* @return string
*/
public function process($app, array $args, array $env = NULL)
public function process($app, array $args, ?array $env = NULL)
{
$cmd = [];

Expand Down
10 changes: 5 additions & 5 deletions src/Git.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Git
protected $runner;


public function __construct(IRunner $runner = NULL)
public function __construct(?IRunner $runner = NULL)
{
$this->runner = $runner !== NULL ? $runner : new Runners\CliRunner;
}
Expand All @@ -32,7 +32,7 @@ public function open($directory)
* @return GitRepository
* @throws GitException
*/
public function init($directory, array $params = NULL)
public function init($directory, ?array $params = NULL)
{
if (is_dir("$directory/.git")) {
throw new GitException("Repo already exists in $directory.");
Expand Down Expand Up @@ -66,7 +66,7 @@ public function init($directory, array $params = NULL)
* @return GitRepository
* @throws GitException
*/
public function cloneRepository($url, $directory = NULL, array $params = NULL)
public function cloneRepository($url, $directory = NULL, ?array $params = NULL)
{
if ($directory !== NULL && is_dir("$directory/.git")) {
throw new GitException("Repo already exists in $directory.");
Expand Down Expand Up @@ -115,7 +115,7 @@ public function cloneRepository($url, $directory = NULL, array $params = NULL)
* @param array<string>|NULL $refs
* @return bool
*/
public function isRemoteUrlReadable($url, array $refs = NULL)
public function isRemoteUrlReadable($url, ?array $refs = NULL)
{
$result = $this->runner->run($this->runner->getCwd(), [
'ls-remote',
Expand All @@ -139,7 +139,7 @@ public function isRemoteUrlReadable($url, array $refs = NULL)
* @return RunnerResult
* @throws GitException
*/
private function run($cwd, array $args, array $env = NULL)
private function run($cwd, array $args, ?array $env = NULL)
{
$result = $this->runner->run($cwd, $args, $env);

Expand Down
15 changes: 8 additions & 7 deletions src/GitRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class GitRepository
* @param string $repository
* @throws GitException
*/
public function __construct($repository, IRunner $runner = NULL)
public function __construct($repository, ?IRunner $runner = NULL)
{
if (basename($repository) === '.git') {
$repository = dirname($repository);
Expand Down Expand Up @@ -466,7 +466,7 @@ public function hasChanges()
* @return static
* @throws GitException
*/
public function pull($remote = NULL, array $options = NULL)
public function pull($remote = NULL, ?array $options = NULL)
{
$this->run('pull', $options, '--end-of-options', $remote);
return $this;
Expand All @@ -480,7 +480,7 @@ public function pull($remote = NULL, array $options = NULL)
* @return static
* @throws GitException
*/
public function push($remote = NULL, array $options = NULL)
public function push($remote = NULL, ?array $options = NULL)
{
$this->run('push', $options, '--end-of-options', $remote);
return $this;
Expand All @@ -494,7 +494,7 @@ public function push($remote = NULL, array $options = NULL)
* @return static
* @throws GitException
*/
public function fetch($remote = NULL, array $options = NULL)
public function fetch($remote = NULL, ?array $options = NULL)
{
$this->run('fetch', $options, '--end-of-options', $remote);
return $this;
Expand All @@ -509,7 +509,7 @@ public function fetch($remote = NULL, array $options = NULL)
* @return static
* @throws GitException
*/
public function addRemote($name, $url, array $options = NULL)
public function addRemote($name, $url, ?array $options = NULL)
{
$this->run('remote', 'add', $options, '--end-of-options', $name, $url);
return $this;
Expand Down Expand Up @@ -551,7 +551,7 @@ public function removeRemote($name)
* @return static
* @throws GitException
*/
public function setRemoteUrl($name, $url, array $options = NULL)
public function setRemoteUrl($name, $url, ?array $options = NULL)
{
$this->run('remote', 'set-url', $options, '--end-of-options', $name, $url);
return $this;
Expand Down Expand Up @@ -590,10 +590,11 @@ public function run(...$args)

/**
* @param array<mixed> $args
* @param (callable(string $value): (string|FALSE))|NULL $filter
* @return string[]|NULL
* @throws GitException
*/
protected function extractFromCommand(array $args, callable $filter = NULL)
protected function extractFromCommand(array $args, ?callable $filter = NULL)
{
$result = $this->run(...$args);
$output = $result->getOutput();
Expand Down
2 changes: 1 addition & 1 deletion src/IRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface IRunner
* @param array<string, scalar>|NULL $env
* @return RunnerResult
*/
function run($cwd, array $args, array $env = NULL);
function run($cwd, array $args, ?array $env = NULL);


/**
Expand Down
11 changes: 10 additions & 1 deletion src/Runners/CliRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct($gitBinary = 'git')
/**
* @return RunnerResult
*/
public function run($cwd, array $args, array $env = NULL)
public function run($cwd, array $args, ?array $env = NULL)
{
if (!is_dir($cwd)) {
throw new GitException("Directory '$cwd' not found");
Expand All @@ -52,6 +52,15 @@ public function run($cwd, array $args, array $env = NULL)
throw new GitException("Executing of command '$command' failed (directory $cwd).");
}

if (!(is_array($pipes)
&& isset($pipes[0], $pipes[1], $pipes[2])
&& is_resource($pipes[0])
&& is_resource($pipes[1])
&& is_resource($pipes[2])
)) {
throw new GitException("Invalid pipes for command '$command' failed (directory $cwd).");
}

// Reset output and error
stream_set_blocking($pipes[1], FALSE);
stream_set_blocking($pipes[2], FALSE);
Expand Down
2 changes: 1 addition & 1 deletion src/Runners/MemoryRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function setResult(array $args, array $env, $output, $errorOutput = [], $
/**
* @return RunnerResult
*/
public function run($cwd, array $args, array $env = NULL)
public function run($cwd, array $args, ?array $env = NULL)
{
$cmd = $this->commandProcessor->process('git', $args, $env);

Expand Down
4 changes: 2 additions & 2 deletions src/Runners/OldGitRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ class OldGitRunner implements IRunner
private $runner;


public function __construct(IRunner $runner = NULL)
public function __construct(?IRunner $runner = NULL)
{
$this->runner = $runner !== NULL ? $runner : new CliRunner;
}


public function run($cwd, array $args, array $env = NULL)
public function run($cwd, array $args, ?array $env = NULL)
{
if (($key = array_search('--end-of-options', $args)) !== FALSE) {
unset($args[$key]);
Expand Down
2 changes: 1 addition & 1 deletion src/exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class GitException extends Exception
* @param string $message
* @param int $code
*/
public function __construct($message, $code = 0, \Exception $previous = NULL, RunnerResult $runnerResult = NULL)
public function __construct($message, $code = 0, ?\Exception $previous = NULL, ?RunnerResult $runnerResult = NULL)
{
parent::__construct($message, $code, $previous);
$this->runnerResult = $runnerResult;
Expand Down
2 changes: 1 addition & 1 deletion tests/libs/AssertRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function resetAsserts()
/**
* @return RunnerResult
*/
public function run($cwd, array $args, array $env = NULL)
public function run($cwd, array $args, ?array $env = NULL)
{
if (empty($this->asserts)) {
throw new \CzProject\GitPhp\InvalidStateException('Missing asserts, use $runner->assert().');
Expand Down