From b214a4a1c6fe8d411b0e2d7750651fcebd44b920 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20H=C3=A4u=C3=9Fler?= Date: Tue, 26 Nov 2024 08:40:14 +0100 Subject: [PATCH 1/5] Avoid implicit nullable types (PHP 8.4 compatibility) --- src/GitElephant/Command/BaseCommand.php | 4 +-- src/GitElephant/Command/BranchCommand.php | 4 +-- src/GitElephant/Command/Caller/Caller.php | 4 +-- .../Command/Caller/CallerInterface.php | 2 +- src/GitElephant/Command/CatFileCommand.php | 2 +- src/GitElephant/Command/CloneCommand.php | 10 +++---- src/GitElephant/Command/DiffCommand.php | 2 +- src/GitElephant/Command/DiffTreeCommand.php | 2 +- src/GitElephant/Command/FetchCommand.php | 4 +-- src/GitElephant/Command/LogCommand.php | 8 +++--- src/GitElephant/Command/LogRangeCommand.php | 4 +-- src/GitElephant/Command/LsTreeCommand.php | 2 +- src/GitElephant/Command/MainCommand.php | 6 ++--- src/GitElephant/Command/MergeCommand.php | 4 +-- src/GitElephant/Command/MvCommand.php | 2 +- src/GitElephant/Command/PullCommand.php | 2 +- src/GitElephant/Command/PushCommand.php | 6 ++--- .../Command/Remote/AddSubCommand.php | 4 +-- .../Command/Remote/ShowSubCommand.php | 4 +-- src/GitElephant/Command/RemoteCommand.php | 8 +++--- src/GitElephant/Command/ResetCommand.php | 4 +-- src/GitElephant/Command/RevListCommand.php | 2 +- src/GitElephant/Command/RevParseCommand.php | 2 +- src/GitElephant/Command/ShowCommand.php | 4 +-- src/GitElephant/Command/StashCommand.php | 6 ++--- src/GitElephant/Command/SubCommandCommand.php | 2 +- src/GitElephant/Command/SubmoduleCommand.php | 4 +-- src/GitElephant/Command/TagCommand.php | 2 +- .../InvalidRepositoryPathException.php | 2 +- src/GitElephant/Objects/Branch.php | 2 +- src/GitElephant/Objects/Diff/Diff.php | 2 +- src/GitElephant/Objects/Log.php | 6 ++--- src/GitElephant/Objects/Remote.php | 10 +++---- src/GitElephant/Objects/Tag.php | 2 +- src/GitElephant/Objects/Tree.php | 2 +- src/GitElephant/Repository.php | 26 +++++++++---------- src/GitElephant/Status/StatusFile.php | 4 +-- tests/GitElephant/TestCase.php | 8 +++--- 38 files changed, 87 insertions(+), 87 deletions(-) diff --git a/src/GitElephant/Command/BaseCommand.php b/src/GitElephant/Command/BaseCommand.php index f82a5db5..96eca110 100644 --- a/src/GitElephant/Command/BaseCommand.php +++ b/src/GitElephant/Command/BaseCommand.php @@ -112,7 +112,7 @@ class BaseCommand * * @param null|\GitElephant\Repository $repo The repo object to read */ - public function __construct(Repository $repo = null) + public function __construct(?Repository $repo = null) { if (!is_null($repo)) { $this->addGlobalConfigs($repo->getGlobalConfigs()); @@ -148,7 +148,7 @@ public function clearAll(): void * @param Repository $repo * @return static */ - public static function getInstance(Repository $repo = null) + public static function getInstance(?Repository $repo = null) { return new static($repo); } diff --git a/src/GitElephant/Command/BranchCommand.php b/src/GitElephant/Command/BranchCommand.php index 2b8b8d89..5bdde51c 100644 --- a/src/GitElephant/Command/BranchCommand.php +++ b/src/GitElephant/Command/BranchCommand.php @@ -37,7 +37,7 @@ class BranchCommand extends BaseCommand * @param \GitElephant\Repository $repo The repository object this command * will interact with */ - public function __construct(Repository $repo = null) + public function __construct(?Repository $repo = null) { parent::__construct($repo); } @@ -69,7 +69,7 @@ public function contains(string $reference): string * @throws \RuntimeException * @return string the command */ - public function create(string $name, string $startPoint = null): string + public function create(string $name, ?string $startPoint = null): string { $this->clearAll(); $this->addCommandName(self::BRANCH_COMMAND); diff --git a/src/GitElephant/Command/Caller/Caller.php b/src/GitElephant/Command/Caller/Caller.php index 41a8e94f..cb0e476d 100644 --- a/src/GitElephant/Command/Caller/Caller.php +++ b/src/GitElephant/Command/Caller/Caller.php @@ -75,7 +75,7 @@ public function __construct($gitPath, $repositoryPath) public function execute( string $cmd, bool $git = true, - string $cwd = null, + ?string $cwd = null, array $acceptedExitCodes = [0] ): CallerInterface { if ($git) { @@ -107,7 +107,7 @@ public function execute( $text .= "\n" . $process->getOutput(); throw new \RuntimeException($text); } - + $this->rawOutput = $process->getOutput(); // rtrim values $values = array_map('rtrim', explode(PHP_EOL, $process->getOutput())); diff --git a/src/GitElephant/Command/Caller/CallerInterface.php b/src/GitElephant/Command/Caller/CallerInterface.php index 2f1f8d3a..9ebed24b 100644 --- a/src/GitElephant/Command/Caller/CallerInterface.php +++ b/src/GitElephant/Command/Caller/CallerInterface.php @@ -37,7 +37,7 @@ interface CallerInterface public function execute( string $cmd, bool $git = true, - string $cwd = null + ?string $cwd = null ): CallerInterface; /** diff --git a/src/GitElephant/Command/CatFileCommand.php b/src/GitElephant/Command/CatFileCommand.php index 1ac91986..022ea759 100644 --- a/src/GitElephant/Command/CatFileCommand.php +++ b/src/GitElephant/Command/CatFileCommand.php @@ -39,7 +39,7 @@ class CatFileCommand extends BaseCommand * @param \GitElephant\Repository $repo The repository object this command * will interact with */ - public function __construct(Repository $repo = null) + public function __construct(?Repository $repo = null) { parent::__construct($repo); } diff --git a/src/GitElephant/Command/CloneCommand.php b/src/GitElephant/Command/CloneCommand.php index 92164a0c..e45eab4b 100644 --- a/src/GitElephant/Command/CloneCommand.php +++ b/src/GitElephant/Command/CloneCommand.php @@ -38,7 +38,7 @@ class CloneCommand extends BaseCommand * @param \GitElephant\Repository $repo The repository object this command * will interact with */ - public function __construct(Repository $repo = null) + public function __construct(?Repository $repo = null) { parent::__construct($repo); } @@ -57,9 +57,9 @@ public function __construct(Repository $repo = null) */ public function cloneUrl( string $url, - string $to = null, - string $repoReference = null, - int $depth = null, + ?string $to = null, + ?string $repoReference = null, + ?int $depth = null, bool $recursive = false ): string { // get binary version before reset @@ -90,7 +90,7 @@ public function cloneUrl( $this->addCommandArgument('--shallow-submodules'); } } - + if ($recursive) { $this->addCommandArgument('--recursive'); } diff --git a/src/GitElephant/Command/DiffCommand.php b/src/GitElephant/Command/DiffCommand.php index 542c00dd..b10806b9 100644 --- a/src/GitElephant/Command/DiffCommand.php +++ b/src/GitElephant/Command/DiffCommand.php @@ -38,7 +38,7 @@ class DiffCommand extends BaseCommand * @param \GitElephant\Repository $repo The repository object this command * will interact with */ - public function __construct(Repository $repo = null) + public function __construct(?Repository $repo = null) { parent::__construct($repo); } diff --git a/src/GitElephant/Command/DiffTreeCommand.php b/src/GitElephant/Command/DiffTreeCommand.php index 473b0954..683e4f59 100644 --- a/src/GitElephant/Command/DiffTreeCommand.php +++ b/src/GitElephant/Command/DiffTreeCommand.php @@ -40,7 +40,7 @@ class DiffTreeCommand extends BaseCommand * @param \GitElephant\Repository $repo The repository object this command * will interact with */ - public function __construct(Repository $repo = null) + public function __construct(?Repository $repo = null) { parent::__construct($repo); } diff --git a/src/GitElephant/Command/FetchCommand.php b/src/GitElephant/Command/FetchCommand.php index b45fb477..cabe5138 100644 --- a/src/GitElephant/Command/FetchCommand.php +++ b/src/GitElephant/Command/FetchCommand.php @@ -38,7 +38,7 @@ class FetchCommand extends BaseCommand * @param \GitElephant\Repository $repo The repository object this command * will interact with */ - public function __construct(Repository $repo = null) + public function __construct(?Repository $repo = null) { parent::__construct($repo); } @@ -68,7 +68,7 @@ public function fetch($remote = null, $branch = null, array $options = []): stri foreach ($normalizedOptions as $value) { $this->addCommandArgument($value); } - + if (!is_null($remote)) { $this->addCommandSubject($remote); } diff --git a/src/GitElephant/Command/LogCommand.php b/src/GitElephant/Command/LogCommand.php index 42452c28..079461e6 100644 --- a/src/GitElephant/Command/LogCommand.php +++ b/src/GitElephant/Command/LogCommand.php @@ -41,7 +41,7 @@ class LogCommand extends BaseCommand * @param \GitElephant\Repository $repo The repository object this command * will interact with */ - public function __construct(Repository $repo = null) + public function __construct(?Repository $repo = null) { parent::__construct($repo); } @@ -57,7 +57,7 @@ public function __construct(Repository $repo = null) * @throws \RuntimeException * @return string */ - public function showObjectLog(NodeObject $obj, $branch = null, int $limit = null, int $offset = null): string + public function showObjectLog(NodeObject $obj, $branch = null, ?int $limit = null, ?int $offset = null): string { $subject = null; if (null !== $branch) { @@ -84,7 +84,7 @@ public function showObjectLog(NodeObject $obj, $branch = null, int $limit = null * @throws \RuntimeException * @return string */ - public function showLog($ref, $path = null, $limit = null, int $offset = null, bool $firstParent = false): string + public function showLog($ref, $path = null, $limit = null, ?int $offset = null, bool $firstParent = false): string { $this->clearAll(); @@ -114,7 +114,7 @@ public function showLog($ref, $path = null, $limit = null, int $offset = null, b if (null !== $path && !empty($path)) { $this->addPath($path); } - + $this->addCommandSubject($ref); return $this->getCommand(); diff --git a/src/GitElephant/Command/LogRangeCommand.php b/src/GitElephant/Command/LogRangeCommand.php index b651cb5e..c39966c1 100644 --- a/src/GitElephant/Command/LogRangeCommand.php +++ b/src/GitElephant/Command/LogRangeCommand.php @@ -35,7 +35,7 @@ class LogRangeCommand extends BaseCommand * @param \GitElephant\Repository $repo The repository object this command * will interact with */ - public function __construct(Repository $repo = null) + public function __construct(?Repository $repo = null) { parent::__construct($repo); } @@ -94,7 +94,7 @@ public function showLog( if (null !== $path && !empty($path)) { $this->addPath($path); } - + $this->addCommandSubject($refStart . '..' . $refEnd); return $this->getCommand(); diff --git a/src/GitElephant/Command/LsTreeCommand.php b/src/GitElephant/Command/LsTreeCommand.php index 9e5d75a2..48c4d057 100644 --- a/src/GitElephant/Command/LsTreeCommand.php +++ b/src/GitElephant/Command/LsTreeCommand.php @@ -40,7 +40,7 @@ class LsTreeCommand extends BaseCommand * @param \GitElephant\Repository $repo The repository object this command * will interact with */ - public function __construct(Repository $repo = null) + public function __construct(?Repository $repo = null) { parent::__construct($repo); } diff --git a/src/GitElephant/Command/MainCommand.php b/src/GitElephant/Command/MainCommand.php index 51fec2d5..e3002beb 100644 --- a/src/GitElephant/Command/MainCommand.php +++ b/src/GitElephant/Command/MainCommand.php @@ -47,7 +47,7 @@ class MainCommand extends BaseCommand * @param \GitElephant\Repository $repo The repository object this command * will interact with */ - public function __construct(Repository $repo = null) + public function __construct(?Repository $repo = null) { parent::__construct($repo); } @@ -149,7 +149,7 @@ public function commit( bool $stageAll = false, $author = null, bool $allowEmpty = false, - \DateTimeInterface $date = null + ?\DateTimeInterface $date = null ): string { $this->clearAll(); @@ -170,7 +170,7 @@ public function commit( if ($allowEmpty) { $this->addCommandArgument('--allow-empty'); } - + if (null !== $date) { $this->addCommandArgument('--date'); $this->addCommandArgument($date->format(\DateTimeInterface::RFC822)); diff --git a/src/GitElephant/Command/MergeCommand.php b/src/GitElephant/Command/MergeCommand.php index 776b1054..3831f23c 100644 --- a/src/GitElephant/Command/MergeCommand.php +++ b/src/GitElephant/Command/MergeCommand.php @@ -40,7 +40,7 @@ class MergeCommand extends BaseCommand * @param \GitElephant\Repository $repo The repository object this command * will interact with */ - public function __construct(Repository $repo = null) + public function __construct(?Repository $repo = null) { parent::__construct($repo); } @@ -76,7 +76,7 @@ public function merge(Branch $with, $message = '', array $options = []): string $this->addCommandArgument('-m'); $this->addCommandArgument($message); } - + $this->addCommandSubject($with->getFullRef()); return $this->getCommand(); diff --git a/src/GitElephant/Command/MvCommand.php b/src/GitElephant/Command/MvCommand.php index 0b130074..85ebf353 100644 --- a/src/GitElephant/Command/MvCommand.php +++ b/src/GitElephant/Command/MvCommand.php @@ -38,7 +38,7 @@ class MvCommand extends BaseCommand * @param \GitElephant\Repository $repo The repository object this command * will interact with */ - public function __construct(Repository $repo = null) + public function __construct(?Repository $repo = null) { parent::__construct($repo); } diff --git a/src/GitElephant/Command/PullCommand.php b/src/GitElephant/Command/PullCommand.php index d0dffb88..39cfe342 100644 --- a/src/GitElephant/Command/PullCommand.php +++ b/src/GitElephant/Command/PullCommand.php @@ -37,7 +37,7 @@ class PullCommand extends BaseCommand * @param \GitElephant\Repository $repo The repository object this command * will interact with */ - public function __construct(Repository $repo = null) + public function __construct(?Repository $repo = null) { parent::__construct($repo); } diff --git a/src/GitElephant/Command/PushCommand.php b/src/GitElephant/Command/PushCommand.php index e67b8ac9..e5ecea6f 100644 --- a/src/GitElephant/Command/PushCommand.php +++ b/src/GitElephant/Command/PushCommand.php @@ -37,7 +37,7 @@ class PushCommand extends BaseCommand * @param \GitElephant\Repository $repo The repository object this command * will interact with */ - public function __construct(Repository $repo = null) + public function __construct(?Repository $repo = null) { parent::__construct($repo); } @@ -49,7 +49,7 @@ public function __construct(Repository $repo = null) * @throws \RuntimeException * @return string */ - public function push($remote = 'origin', $branch = 'master', string $args = null): string + public function push($remote = 'origin', $branch = 'master', ?string $args = null): string { $this->clearAll(); @@ -63,7 +63,7 @@ public function push($remote = 'origin', $branch = 'master', string $args = null $this->addCommandName(self::GIT_PUSH_COMMAND); $this->addCommandSubject($remote); $this->addCommandSubject2($branch); - + if (!is_null($args)) { $this->addCommandArgument($args); } diff --git a/src/GitElephant/Command/Remote/AddSubCommand.php b/src/GitElephant/Command/Remote/AddSubCommand.php index 46acd586..43465313 100644 --- a/src/GitElephant/Command/Remote/AddSubCommand.php +++ b/src/GitElephant/Command/Remote/AddSubCommand.php @@ -48,7 +48,7 @@ class AddSubCommand extends SubCommandCommand * @param \GitElephant\Repository $repo The repository object this command * will interact with */ - public function __construct(Repository $repo = null) + public function __construct(?Repository $repo = null) { parent::__construct($repo); } @@ -97,7 +97,7 @@ public function prepare($name, $url, $options = []): self $this->addCmdSwitchOptions(), $this->addCmdValueOptions() ); - + $this->addCommandName(self::GIT_REMOTE_ADD); $this->addCommandSubject($name); $this->addCommandSubject($url); diff --git a/src/GitElephant/Command/Remote/ShowSubCommand.php b/src/GitElephant/Command/Remote/ShowSubCommand.php index 16b855dc..e57d90bc 100644 --- a/src/GitElephant/Command/Remote/ShowSubCommand.php +++ b/src/GitElephant/Command/Remote/ShowSubCommand.php @@ -42,7 +42,7 @@ class ShowSubCommand extends SubCommandCommand * @param \GitElephant\Repository $repo The repository object this command * will interact with */ - public function __construct(Repository $repo = null) + public function __construct(?Repository $repo = null) { parent::__construct($repo); } @@ -69,7 +69,7 @@ public function prepare($name = null, $queryRemotes = true): self if ($name) { $this->addCommandSubject($name); } - + if (!$queryRemotes) { $this->addCommandArgument('-n'); } diff --git a/src/GitElephant/Command/RemoteCommand.php b/src/GitElephant/Command/RemoteCommand.php index f763266f..d2fb7dfa 100644 --- a/src/GitElephant/Command/RemoteCommand.php +++ b/src/GitElephant/Command/RemoteCommand.php @@ -44,7 +44,7 @@ class RemoteCommand extends BaseCommand * @param \GitElephant\Repository $repo The repository object this command * will interact with */ - public function __construct(Repository $repo = null) + public function __construct(?Repository $repo = null) { parent::__construct($repo); } @@ -62,12 +62,12 @@ public function __construct(Repository $repo = null) * @throws \RuntimeException * @return string Command string to pass to caller */ - public function remote(SubCommandCommand $subcommand = null, array $options = []): string + public function remote(?SubCommandCommand $subcommand = null, array $options = []): string { $normalizedOptions = $this->normalizeOptions($options, $this->remoteCmdSwitchOptions()); - + $this->clearAll(); - + $this->addCommandName(self::GIT_REMOTE); foreach ($normalizedOptions as $value) { diff --git a/src/GitElephant/Command/ResetCommand.php b/src/GitElephant/Command/ResetCommand.php index b973ea8d..d0ecc225 100644 --- a/src/GitElephant/Command/ResetCommand.php +++ b/src/GitElephant/Command/ResetCommand.php @@ -27,7 +27,7 @@ class ResetCommand extends BaseCommand * @param \GitElephant\Repository $repo The repository object this command * will interact with */ - public function __construct(Repository $repo = null) + public function __construct(?Repository $repo = null) { parent::__construct($repo); } @@ -59,7 +59,7 @@ public function reset($arg = null, array $options = []): string * @param Repository $repository * @return ResetCommand */ - public static function getInstance(Repository $repository = null): \GitElephant\Command\ResetCommand + public static function getInstance(?Repository $repository = null): \GitElephant\Command\ResetCommand { return new self($repository); } diff --git a/src/GitElephant/Command/RevListCommand.php b/src/GitElephant/Command/RevListCommand.php index 41da2ee6..5384b087 100644 --- a/src/GitElephant/Command/RevListCommand.php +++ b/src/GitElephant/Command/RevListCommand.php @@ -39,7 +39,7 @@ class RevListCommand extends BaseCommand * @param \GitElephant\Repository $repo The repository object this command * will interact with */ - public function __construct(Repository $repo = null) + public function __construct(?Repository $repo = null) { parent::__construct($repo); } diff --git a/src/GitElephant/Command/RevParseCommand.php b/src/GitElephant/Command/RevParseCommand.php index 8e84e665..820ed2da 100644 --- a/src/GitElephant/Command/RevParseCommand.php +++ b/src/GitElephant/Command/RevParseCommand.php @@ -74,7 +74,7 @@ class RevParseCommand extends BaseCommand * @param \GitElephant\Repository $repo The repository object this command * will interact with */ - public function __construct(Repository $repo = null) + public function __construct(?Repository $repo = null) { parent::__construct($repo); } diff --git a/src/GitElephant/Command/ShowCommand.php b/src/GitElephant/Command/ShowCommand.php index 5e970d79..ed6879c9 100644 --- a/src/GitElephant/Command/ShowCommand.php +++ b/src/GitElephant/Command/ShowCommand.php @@ -37,7 +37,7 @@ class ShowCommand extends BaseCommand * @param \GitElephant\Repository $repo The repository object this command * will interact with */ - public function __construct(Repository $repo = null) + public function __construct(?Repository $repo = null) { parent::__construct($repo); } @@ -53,7 +53,7 @@ public function __construct(Repository $repo = null) public function showCommit($ref): string { $this->clearAll(); - + $this->addCommandName(self::GIT_SHOW); $this->addCommandArgument('-s'); $this->addCommandArgument('--pretty=raw'); diff --git a/src/GitElephant/Command/StashCommand.php b/src/GitElephant/Command/StashCommand.php index 058760ac..7467cd8c 100644 --- a/src/GitElephant/Command/StashCommand.php +++ b/src/GitElephant/Command/StashCommand.php @@ -38,7 +38,7 @@ class StashCommand extends BaseCommand * @param \GitElephant\Repository $repo The repository object this command * will interact with */ - public function __construct(Repository $repo = null) + public function __construct(?Repository $repo = null) { parent::__construct($repo); } @@ -80,12 +80,12 @@ public function save($message = null, $includeUntracked = false, $keepIndex = fa * * @return string */ - public function listStashes(array $options = null): string + public function listStashes(?array $options = null): string { $this->clearAll(); $this->addCommandName(self::STASH_COMMAND . ' list'); - + if (null !== $options) { $this->addCommandSubject($options); } diff --git a/src/GitElephant/Command/SubCommandCommand.php b/src/GitElephant/Command/SubCommandCommand.php index a1443e26..3503eee7 100644 --- a/src/GitElephant/Command/SubCommandCommand.php +++ b/src/GitElephant/Command/SubCommandCommand.php @@ -46,7 +46,7 @@ class SubCommandCommand extends BaseCommand * @param \GitElephant\Repository $repo The repository object this command * will interact with */ - public function __construct(Repository $repo = null) + public function __construct(?Repository $repo = null) { parent::__construct($repo); } diff --git a/src/GitElephant/Command/SubmoduleCommand.php b/src/GitElephant/Command/SubmoduleCommand.php index 83237cd3..64d21ba6 100644 --- a/src/GitElephant/Command/SubmoduleCommand.php +++ b/src/GitElephant/Command/SubmoduleCommand.php @@ -43,7 +43,7 @@ class SubmoduleCommand extends BaseCommand * @param \GitElephant\Repository $repo The repository object this command * will interact with */ - public function __construct(Repository $repo = null) + public function __construct(?Repository $repo = null) { parent::__construct($repo); } @@ -130,7 +130,7 @@ public function update( bool $recursive = false, bool $init = false, bool $force = false, - string $path = null + ?string $path = null ): string { $this->clearAll(); $this->addCommandName(sprintf('%s %s', self::SUBMODULE_COMMAND, self::SUBMODULE_UPDATE_COMMAND)); diff --git a/src/GitElephant/Command/TagCommand.php b/src/GitElephant/Command/TagCommand.php index b4c58a83..807df4ee 100644 --- a/src/GitElephant/Command/TagCommand.php +++ b/src/GitElephant/Command/TagCommand.php @@ -38,7 +38,7 @@ class TagCommand extends BaseCommand * @param \GitElephant\Repository $repo The repository object this command * will interact with */ - public function __construct(Repository $repo = null) + public function __construct(?Repository $repo = null) { parent::__construct($repo); } diff --git a/src/GitElephant/Exception/InvalidRepositoryPathException.php b/src/GitElephant/Exception/InvalidRepositoryPathException.php index 11ade45c..2e6204f3 100644 --- a/src/GitElephant/Exception/InvalidRepositoryPathException.php +++ b/src/GitElephant/Exception/InvalidRepositoryPathException.php @@ -39,7 +39,7 @@ class InvalidRepositoryPathException extends \InvalidArgumentException * @param int $code code * @param \Exception $previous previous */ - public function __construct($message = "", $code = 0, \Exception $previous = null) + public function __construct($message = "", $code = 0, ?\Exception $previous = null) { parent::__construct(sprintf($this->messageTpl, $message), $code, $previous); } diff --git a/src/GitElephant/Objects/Branch.php b/src/GitElephant/Objects/Branch.php index 2246a740..b0a51194 100644 --- a/src/GitElephant/Objects/Branch.php +++ b/src/GitElephant/Objects/Branch.php @@ -82,7 +82,7 @@ class Branch extends NodeObject implements TreeishInterface public static function create( Repository $repository, string $name, - string $startPoint = null + ?string $startPoint = null ): \GitElephant\Objects\Branch { /** @var BranchCommand $branchCommand */ $branchCommand = BranchCommand::getInstance($repository); diff --git a/src/GitElephant/Objects/Diff/Diff.php b/src/GitElephant/Objects/Diff/Diff.php index e684b247..90ffb668 100644 --- a/src/GitElephant/Objects/Diff/Diff.php +++ b/src/GitElephant/Objects/Diff/Diff.php @@ -69,7 +69,7 @@ public static function create( Repository $repository, $commit1 = null, $commit2 = null, - string $path = null + ?string $path = null ): \GitElephant\Objects\Diff\Diff { $commit = new self($repository); $commit->createFromCommand($commit1, $commit2, $path); diff --git a/src/GitElephant/Objects/Log.php b/src/GitElephant/Objects/Log.php index 18164b5b..e1ca9c17 100644 --- a/src/GitElephant/Objects/Log.php +++ b/src/GitElephant/Objects/Log.php @@ -82,7 +82,7 @@ public function __construct( $ref = 'HEAD', $path = null, int $limit = 15, - int $offset = null, + ?int $offset = null, bool $firstParent = false ) { $this->repository = $repository; @@ -107,8 +107,8 @@ public function __construct( private function createFromCommand( $ref, $path = null, - int $limit = null, - int $offset = null, + ?int $limit = null, + ?int $offset = null, bool $firstParent = false ): void { $command = LogCommand::getInstance($this->getRepository()) diff --git a/src/GitElephant/Objects/Remote.php b/src/GitElephant/Objects/Remote.php index ef40d4f1..d26c484e 100644 --- a/src/GitElephant/Objects/Remote.php +++ b/src/GitElephant/Objects/Remote.php @@ -82,7 +82,7 @@ class Remote * @throws \InvalidArgumentException * @throws \UnexpectedValueException */ - public function __construct(Repository $repository, string $name = null, bool $queryRemotes = true) + public function __construct(Repository $repository, ?string $name = null, bool $queryRemotes = true) { $this->repository = $repository; if ($name) { @@ -102,7 +102,7 @@ public function __construct(Repository $repository, string $name = null, bool $q */ public static function pick( Repository $repository, - string $name = null, + ?string $name = null, bool $queryRemotes = true ): \GitElephant\Objects\Remote { return new self($repository, $name, $queryRemotes); @@ -119,7 +119,7 @@ public static function pick( * @throws \Symfony\Component\Process\Exception\RuntimeException * @return array */ - public function getVerboseOutput(RemoteCommand $remoteCmd = null): array + public function getVerboseOutput(?RemoteCommand $remoteCmd = null): array { if ($remoteCmd === null) { $remoteCmd = RemoteCommand::getInstance($this->repository); @@ -146,8 +146,8 @@ public function getVerboseOutput(RemoteCommand $remoteCmd = null): array * @return array */ public function getShowOutput( - string $name = null, - RemoteCommand $remoteCmd = null, + ?string $name = null, + ?RemoteCommand $remoteCmd = null, bool $queryRemotes = true ): array { if ($remoteCmd === null) { diff --git a/src/GitElephant/Objects/Tag.php b/src/GitElephant/Objects/Tag.php index 14a85b5c..a4d9c5f2 100644 --- a/src/GitElephant/Objects/Tag.php +++ b/src/GitElephant/Objects/Tag.php @@ -68,7 +68,7 @@ public static function create( Repository $repository, string $name, $startPoint = null, - string $message = null + ?string $message = null ): ?\GitElephant\Objects\Tag { $repository ->getCaller() diff --git a/src/GitElephant/Objects/Tree.php b/src/GitElephant/Objects/Tree.php index 36b25b31..30f637d0 100644 --- a/src/GitElephant/Objects/Tree.php +++ b/src/GitElephant/Objects/Tree.php @@ -117,7 +117,7 @@ private function createFromCommand(): void * @throws \Symfony\Component\Process\Exception\RuntimeException * @internal param \GitElephant\Objects\Object|string $treeObject Object instance */ - public function __construct(Repository $repository, $ref = 'HEAD', NodeObject $subject = null) + public function __construct(Repository $repository, $ref = 'HEAD', ?NodeObject $subject = null) { $this->position = 0; $this->repository = $repository; diff --git a/src/GitElephant/Repository.php b/src/GitElephant/Repository.php index d255408d..4b5c2a47 100644 --- a/src/GitElephant/Repository.php +++ b/src/GitElephant/Repository.php @@ -119,7 +119,7 @@ class Repository * * @throws Exception\InvalidRepositoryPathException */ - public function __construct($repositoryPath, string $binary = null, $name = null) + public function __construct($repositoryPath, ?string $binary = null, $name = null) { $this->path = $repositoryPath; $this->caller = new Caller($binary, $repositoryPath); @@ -135,7 +135,7 @@ public function __construct($repositoryPath, string $binary = null, $name = null * * @return \GitElephant\Repository */ - public static function open($repositoryPath, string $binary = null, $name = null): \GitElephant\Repository + public static function open($repositoryPath, ?string $binary = null, $name = null): \GitElephant\Repository { return new self($repositoryPath, $binary, $name); } @@ -156,7 +156,7 @@ public static function open($repositoryPath, string $binary = null, $name = null public static function createFromRemote( $git, $repositoryPath = null, - string $binary = null, + ?string $binary = null, $name = null ): \GitElephant\Repository { if (null === $repositoryPath) { @@ -295,7 +295,7 @@ public function commit( $ref = null, $author = null, $allowEmpty = false, - \DateTimeInterface $date = null + ?\DateTimeInterface $date = null ): self { $currentBranch = null; if (!is_null($ref)) { @@ -623,7 +623,7 @@ public function merge(Branch $branch, string $message = '', string $mode = 'auto * @throws \Symfony\Component\Process\Exception\RuntimeException * @return Repository */ - public function createTag(string $name, $startPoint = null, string $message = null): self + public function createTag(string $name, $startPoint = null, ?string $message = null): self { Tag::create($this, $name, $startPoint, $message); @@ -876,7 +876,7 @@ public function getLogRange( $refEnd, $path = null, int $limit = 10, - int $offset = null, + ?int $offset = null, bool $firstParent = false ) { // Handle when clients provide bad start reference on branch creation @@ -910,7 +910,7 @@ public function getObjectLog( NodeObject $obj, $branch = null, int $limit = 1, - int $offset = null + ?int $offset = null ): \GitElephant\Objects\Log { $command = LogCommand::getInstance($this)->showObjectLog($obj, $branch, $limit, $offset); @@ -1003,9 +1003,9 @@ public function getDiff( */ public function cloneFrom( string $url, - string $to = null, - string $repoReference = null, - int $depth = null, + ?string $to = null, + ?string $repoReference = null, + ?int $depth = null, bool $recursive = false ): self { $command = Command\CloneCommand::getInstance($this) @@ -1118,7 +1118,7 @@ public function pull($from = null, $ref = null, bool $rebase = true): void * @throws InvalidArgumentException * @throws \Symfony\Component\Process\Exception\RuntimeException */ - public function push($to = null, $ref = null, string $args = null): void + public function push($to = null, $ref = null, ?string $args = null): void { $this->caller->execute(PushCommand::getInstance($this)->push($to, $ref, $args)); } @@ -1333,7 +1333,7 @@ public function removeGlobalCommandArgument($value): void * @param boolean $includeUntracked * @param boolean $keepIndex */ - public function stash(string $message = null, bool $includeUntracked = false, bool $keepIndex = false): void + public function stash(?string $message = null, bool $includeUntracked = false, bool $keepIndex = false): void { $stashCommand = StashCommand::getInstance($this); $command = $stashCommand->save($message, $includeUntracked, $keepIndex); @@ -1347,7 +1347,7 @@ public function stash(string $message = null, bool $includeUntracked = false, bo * * @return array */ - public function stashList(array $options = null): array + public function stashList(?array $options = null): array { $stashCommand = StashCommand::getInstance($this); $command = $stashCommand->listStashes($options); diff --git a/src/GitElephant/Status/StatusFile.php b/src/GitElephant/Status/StatusFile.php index 988d6e48..55710317 100644 --- a/src/GitElephant/Status/StatusFile.php +++ b/src/GitElephant/Status/StatusFile.php @@ -73,7 +73,7 @@ class StatusFile * @param string $name file name * @param string $renamed new file name (if renamed) */ - private function __construct(string $x, string $y, string $name, string $renamed = null) + private function __construct(string $x, string $y, string $name, ?string $renamed = null) { $this->x = ' ' === $x ? null : $x; $this->y = ' ' === $y ? null : $y; @@ -93,7 +93,7 @@ public static function create( string $x, string $y, string $name, - string $renamed = null + ?string $renamed = null ): \GitElephant\Status\StatusFile { return new self($x, $y, $name, $renamed); } diff --git a/tests/GitElephant/TestCase.php b/tests/GitElephant/TestCase.php index 8632d63b..b4827468 100644 --- a/tests/GitElephant/TestCase.php +++ b/tests/GitElephant/TestCase.php @@ -85,7 +85,7 @@ protected function getCaller(): CallerInterface * * @return void */ - protected function initRepository(string $name = null, int $index = null): void + protected function initRepository(?string $name = null, ?int $index = null): void { $tempDir = realpath(sys_get_temp_dir()); $tempName = null === $name @@ -134,9 +134,9 @@ protected function tearDown(): void */ protected function addFile( string $name, - string $folder = null, - string $content = null, - Repository $repository = null + ?string $folder = null, + ?string $content = null, + ?Repository $repository = null ): void { $path = is_null($repository) ? $this->path : $repository->getPath(); $filename = $folder == null From f49f9078ece4f0626e8758f180baebb5f4bc5edd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20H=C3=A4u=C3=9Fler?= Date: Tue, 26 Nov 2024 09:14:30 +0100 Subject: [PATCH 2/5] Add PHP 8.3 & 8.4 to test matrix --- .github/workflows/tests.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 10e7f124..fc681597 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -15,13 +15,18 @@ jobs: - "8.0" - "8.1" - "8.2" + - "8.3" + - "8.4" symfony: - 5.* - 6.* + - 7.* dependency-version: # - prefer-lowest - prefer-stable exclude: + - {php: "8.0", symfony: "7.*"} + - {php: "8.1", symfony: "7.*"} - {php: "8.2", symfony: "5.*"} name: PHP ${{ matrix.php }} - S ${{ matrix.symfony }} - ${{ matrix.dependency-version }} - tests From e266873c49543ef62447556e8f15083e7942a835 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20H=C3=A4u=C3=9Fler?= Date: Tue, 26 Nov 2024 10:04:06 +0100 Subject: [PATCH 3/5] Resolve PHPStan errors and migrate configuration --- phpstan.neon | 10 ++++++---- src/GitElephant/Command/BaseCommand.php | 4 ++-- src/GitElephant/Objects/Branch.php | 1 - 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index b7735a56..e1c126c2 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -3,18 +3,20 @@ parameters: paths: - src # - tests - + # things we disable for the moment, but one day... inferPrivatePropertyTypeFromConstructor: true - checkMissingIterableValueType: false - checkGenericClassInNonGenericObjectType: false ignoreErrors: - - + - message: '#Unsafe usage of new static\(\).#' path: %currentWorkingDirectory% - message: '#Parameter \#1 \$command of class Symfony\\Component\\Process\\Process constructor expects array, string given.#' path: src/GitElephant/Command/Caller/Caller.php + - + identifier: missingType.iterableValue + - + identifier: missingType.generics includes: - vendor/phpstan/phpstan-phpunit/extension.neon diff --git a/src/GitElephant/Command/BaseCommand.php b/src/GitElephant/Command/BaseCommand.php index 96eca110..33fbb2cd 100644 --- a/src/GitElephant/Command/BaseCommand.php +++ b/src/GitElephant/Command/BaseCommand.php @@ -76,14 +76,14 @@ class BaseCommand /** * the command subject * - * @var string|SubCommandCommand|null + * @var array|string|SubCommandCommand|null */ private $commandSubject = null; /** * the command second subject (i.e. for branch) * - * @var string|SubCommandCommand|null + * @var array|string|SubCommandCommand|null */ private $commandSubject2 = null; diff --git a/src/GitElephant/Objects/Branch.php b/src/GitElephant/Objects/Branch.php index b0a51194..713b8058 100644 --- a/src/GitElephant/Objects/Branch.php +++ b/src/GitElephant/Objects/Branch.php @@ -209,7 +209,6 @@ public static function getMatches(string $branchString): array '/^\*?\ *?\(.*(detached).*\)\ +(\S{40})\ +(.+)$/', ]; - $matches = []; while (empty($matches) and $regex = array_pop($regexList)) { preg_match($regex, trim($branchString), $matches); } From 6d293631235d440c3d2ed2d337cd7e9c59156364 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20H=C3=A4u=C3=9Fler?= Date: Tue, 26 Nov 2024 10:05:48 +0100 Subject: [PATCH 4/5] Fix code style issues --- src/GitElephant/Sequence/AbstractCollection.php | 10 +++++----- tests/GitElephant/Objects/TreeTest.php | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/GitElephant/Sequence/AbstractCollection.php b/src/GitElephant/Sequence/AbstractCollection.php index 9b8e809d..c755086f 100644 --- a/src/GitElephant/Sequence/AbstractCollection.php +++ b/src/GitElephant/Sequence/AbstractCollection.php @@ -40,11 +40,11 @@ public function contains($searchedElem): bool return false; } - /** - * @param callable $callable - * - * @return \PhpOption\LazyOption - */ + /** + * @param callable $callable + * + * @return \PhpOption\LazyOption + */ public function find(callable $callable): LazyOption { $self = $this; diff --git a/tests/GitElephant/Objects/TreeTest.php b/tests/GitElephant/Objects/TreeTest.php index 05ca6e30..09045e90 100644 --- a/tests/GitElephant/Objects/TreeTest.php +++ b/tests/GitElephant/Objects/TreeTest.php @@ -96,7 +96,7 @@ public function testSubmodule(): void mkdir($path); $repository = new Repository($path); $repository->init(false, 'master'); - // required for newer git versions, + // required for newer git versions, // see e.g. https://bugs.launchpad.net/ubuntu/+source/git/+bug/1993586 $repository->addGlobalConfig("protocol.file.allow", "always"); $repository->addSubmodule($this->repository->getPath()); From ce90fe129df166c24c6c05dd7b72da12bf47fb99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elias=20H=C3=A4u=C3=9Fler?= Date: Tue, 26 Nov 2024 10:26:14 +0100 Subject: [PATCH 5/5] Run code style check with PHP 8.1 --- .github/workflows/code_style_check.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/code_style_check.yaml b/.github/workflows/code_style_check.yaml index 361534a4..c89dc858 100644 --- a/.github/workflows/code_style_check.yaml +++ b/.github/workflows/code_style_check.yaml @@ -13,7 +13,7 @@ jobs: - uses: actions/checkout@v2 - uses: shivammathur/setup-php@v2 with: - php-version: 7.3 + php-version: 8.1 coverage: none # disable xdebug, pcov - run: composer install --no-progress # fix code style, automatically