diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 276e466..82b57cb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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: diff --git a/code-checker.php b/code-checker.php index 96eef7d..7a02154 100644 --- a/code-checker.php +++ b/code-checker.php @@ -1,8 +1,13 @@ 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); }; diff --git a/composer.json b/composer.json index b6289ca..742667c 100644 --- a/composer.json +++ b/composer.json @@ -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" } } diff --git a/readme.md b/readme.md index 88b031a..185cb3c 100644 --- a/readme.md +++ b/readme.md @@ -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: diff --git a/src/CommandProcessor.php b/src/CommandProcessor.php index 83372b3..7f57e4c 100644 --- a/src/CommandProcessor.php +++ b/src/CommandProcessor.php @@ -39,7 +39,7 @@ public function __construct($mode = self::MODE_DETECT) * @param array|NULL $env * @return string */ - public function process($app, array $args, array $env = NULL) + public function process($app, array $args, ?array $env = NULL) { $cmd = []; diff --git a/src/Git.php b/src/Git.php index d4d562d..e23a192 100644 --- a/src/Git.php +++ b/src/Git.php @@ -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; } @@ -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."); @@ -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."); @@ -115,7 +115,7 @@ public function cloneRepository($url, $directory = NULL, array $params = NULL) * @param array|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', @@ -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); diff --git a/src/GitRepository.php b/src/GitRepository.php index cd8d5fa..9855007 100644 --- a/src/GitRepository.php +++ b/src/GitRepository.php @@ -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); @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -590,10 +590,11 @@ public function run(...$args) /** * @param array $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(); diff --git a/src/IRunner.php b/src/IRunner.php index 453ff68..3323838 100644 --- a/src/IRunner.php +++ b/src/IRunner.php @@ -11,7 +11,7 @@ interface IRunner * @param array|NULL $env * @return RunnerResult */ - function run($cwd, array $args, array $env = NULL); + function run($cwd, array $args, ?array $env = NULL); /** diff --git a/src/Runners/CliRunner.php b/src/Runners/CliRunner.php index 462e61c..63c9da6 100644 --- a/src/Runners/CliRunner.php +++ b/src/Runners/CliRunner.php @@ -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"); @@ -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); diff --git a/src/Runners/MemoryRunner.php b/src/Runners/MemoryRunner.php index 4982c9c..fb28523 100644 --- a/src/Runners/MemoryRunner.php +++ b/src/Runners/MemoryRunner.php @@ -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); diff --git a/src/Runners/OldGitRunner.php b/src/Runners/OldGitRunner.php index cb07136..ac85057 100644 --- a/src/Runners/OldGitRunner.php +++ b/src/Runners/OldGitRunner.php @@ -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]); diff --git a/src/exceptions.php b/src/exceptions.php index b79bd39..1eac0d4 100644 --- a/src/exceptions.php +++ b/src/exceptions.php @@ -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; diff --git a/tests/libs/AssertRunner.php b/tests/libs/AssertRunner.php index db7d1e2..5538eb0 100644 --- a/tests/libs/AssertRunner.php +++ b/tests/libs/AssertRunner.php @@ -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().');