From 0367c4d6c02674dbe1fca2b5ed5b6747f4275d8e Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Fri, 19 May 2023 17:23:04 +0200 Subject: [PATCH 1/9] added type annotation to some methods --- src/Gitonomy/Git/Admin.php | 6 +++++ src/Gitonomy/Git/Blame.php | 7 ++++- src/Gitonomy/Git/Commit.php | 14 ++++++++++ src/Gitonomy/Git/CommitReference.php | 5 +++- src/Gitonomy/Git/Hooks.php | 6 +++-- src/Gitonomy/Git/Log.php | 6 +++++ src/Gitonomy/Git/PushReference.php | 6 +++++ src/Gitonomy/Git/Reference.php | 7 +++++ src/Gitonomy/Git/Reference/Branch.php | 16 ++++++++++++ src/Gitonomy/Git/Reference/Tag.php | 8 ++++++ src/Gitonomy/Git/ReferenceBag.php | 33 +++++++++++++++++++++++ src/Gitonomy/Git/Repository.php | 36 +++++++++++++++++++++----- src/Gitonomy/Git/Revision.php | 9 +++++++ src/Gitonomy/Git/RevisionList.php | 3 +++ src/Gitonomy/Git/Tree.php | 18 +++++++++++++ src/Gitonomy/Git/Util/StringHelper.php | 32 +++++++++++++++++++++++ src/Gitonomy/Git/WorkingCopy.php | 9 +++++++ 17 files changed, 211 insertions(+), 10 deletions(-) diff --git a/src/Gitonomy/Git/Admin.php b/src/Gitonomy/Git/Admin.php index 7b32794c..041cad95 100644 --- a/src/Gitonomy/Git/Admin.php +++ b/src/Gitonomy/Git/Admin.php @@ -168,6 +168,12 @@ public static function cloneRepository($path, $url, array $args = [], array $opt /** * This internal method is used to create a process object. + * + * @param string $command + * @param array $args + * @param array $options + * + * @return Process */ private static function getProcess($command, array $args = [], array $options = []) { diff --git a/src/Gitonomy/Git/Blame.php b/src/Gitonomy/Git/Blame.php index dec0773b..98a27db6 100644 --- a/src/Gitonomy/Git/Blame.php +++ b/src/Gitonomy/Git/Blame.php @@ -47,7 +47,10 @@ class Blame implements \Countable protected $lines; /** - * @param string $lineRange Argument to pass to git blame (-L). + * @param Repository $repository + * @param Revision $revision + * @param string $file + * @param string $lineRange Argument to pass to git blame (-L). * Can be a line range (40,60 or 40,+21) * or a regexp ('/^function$/') */ @@ -60,6 +63,8 @@ public function __construct(Repository $repository, Revision $revision, $file, $ } /** + * @param int $number Line number + * * @return Line */ public function getLine($number) diff --git a/src/Gitonomy/Git/Commit.php b/src/Gitonomy/Git/Commit.php index 2008f7a3..00d695af 100644 --- a/src/Gitonomy/Git/Commit.php +++ b/src/Gitonomy/Git/Commit.php @@ -38,6 +38,7 @@ class Commit extends Revision * * @param Repository $repository Repository of the commit * @param string $hash Hash of the commit + * @param array $data Associative array of commit data. */ public function __construct(Repository $repository, $hash, array $data = []) { @@ -50,6 +51,9 @@ public function __construct(Repository $repository, $hash, array $data = []) $this->setData($data); } + /** + * @param array $data Associative array of commit data. + */ public function setData(array $data) { foreach ($data as $name => $value) { @@ -144,6 +148,8 @@ public function getTree() } /** + * @param string|null $path + * * @return Commit */ public function getLastModification($path = null) @@ -347,6 +353,14 @@ public function getCommit() return $this; } + /** + * Possible options are: treeHash, parentHashes, authorName, authorEmail, authorDate, + * committerName, committerEmail, committerDate, message or an other attribute + * + * @param string $name + * + * @return Tree|string + */ private function getData($name) { if (isset($this->data[$name])) { diff --git a/src/Gitonomy/Git/CommitReference.php b/src/Gitonomy/Git/CommitReference.php index 7be3d89c..b08db348 100644 --- a/src/Gitonomy/Git/CommitReference.php +++ b/src/Gitonomy/Git/CommitReference.php @@ -15,10 +15,13 @@ class CommitReference { /** - * @var string + * @var string $hash */ private $hash; + /** + * @param string $hash + */ public function __construct($hash) { $this->hash = $hash; diff --git a/src/Gitonomy/Git/Hooks.php b/src/Gitonomy/Git/Hooks.php index dd0adbe8..466cffef 100644 --- a/src/Gitonomy/Git/Hooks.php +++ b/src/Gitonomy/Git/Hooks.php @@ -24,12 +24,12 @@ class Hooks { /** - * @var \Gitonomy\Git\Repository + * @var Repository */ protected $repository; /** - * @var Repository + * @var Repository $repository */ public function __construct(Repository $repository) { @@ -123,6 +123,8 @@ public function remove($name) } /** + * @param string $name Name of the hook + * * @return string */ protected function getPath($name) diff --git a/src/Gitonomy/Git/Log.php b/src/Gitonomy/Git/Log.php index 47665359..4ab3614e 100644 --- a/src/Gitonomy/Git/Log.php +++ b/src/Gitonomy/Git/Log.php @@ -111,6 +111,8 @@ public function getOffset() /** * @param int $offset + * + * @return Log */ public function setOffset($offset) { @@ -129,6 +131,8 @@ public function getLimit() /** * @param int $limit + * + * @return Log */ public function setLimit($limit) { @@ -138,6 +142,8 @@ public function setLimit($limit) } /** + * Returns the last modification date of the reference. + * * @return Commit */ public function getSingleCommit() diff --git a/src/Gitonomy/Git/PushReference.php b/src/Gitonomy/Git/PushReference.php index dea10823..f581fc0e 100644 --- a/src/Gitonomy/Git/PushReference.php +++ b/src/Gitonomy/Git/PushReference.php @@ -48,6 +48,12 @@ class PushReference */ protected $isForce; + /** + * @param Repository $repository + * @param string $reference + * @param string $before + * @param string $after + */ public function __construct(Repository $repository, $reference, $before, $after) { $this->repository = $repository; diff --git a/src/Gitonomy/Git/Reference.php b/src/Gitonomy/Git/Reference.php index 96b8fa12..3252b5fb 100644 --- a/src/Gitonomy/Git/Reference.php +++ b/src/Gitonomy/Git/Reference.php @@ -25,6 +25,11 @@ abstract class Reference extends Revision { protected $commitHash; + /** + * @param Repository $repository + * @param string $revision + * @param string $commitHash + */ public function __construct(Repository $repository, $revision, $commitHash = null) { $this->repository = $repository; @@ -75,6 +80,8 @@ public function getCommit() } /** + * @param string|null $path + * * @return Commit */ public function getLastModification($path = null) diff --git a/src/Gitonomy/Git/Reference/Branch.php b/src/Gitonomy/Git/Reference/Branch.php index 0d27fb88..bcfa0ea3 100644 --- a/src/Gitonomy/Git/Reference/Branch.php +++ b/src/Gitonomy/Git/Reference/Branch.php @@ -24,8 +24,16 @@ */ class Branch extends Reference { + /** + * @var null | bool + */ private $local = null; + /** + * @throws RuntimeException Cannot extract branch name + * + * @return string + */ public function getName() { $fullname = $this->getFullname(); @@ -41,6 +49,9 @@ public function getName() throw new RuntimeException(sprintf('Cannot extract branch name from "%s"', $fullname)); } + /** + * @return null | bool + */ public function isRemote() { $this->detectBranchType(); @@ -48,6 +59,9 @@ public function isRemote() return !$this->local; } + /** + * @return null | bool + */ public function isLocal() { $this->detectBranchType(); @@ -62,6 +76,8 @@ public function isLocal() * @param string $destinationBranchName * @param bool $compareOnlyWithRemote * + * @throws RuntimeException Cannot determine if merged to the branch + * * @return null|bool */ public function isMergedTo($destinationBranchName = 'master', $compareOnlyWithRemote = false) diff --git a/src/Gitonomy/Git/Reference/Tag.php b/src/Gitonomy/Git/Reference/Tag.php index bca6ca49..46138ded 100644 --- a/src/Gitonomy/Git/Reference/Tag.php +++ b/src/Gitonomy/Git/Reference/Tag.php @@ -27,8 +27,16 @@ */ class Tag extends Reference { + /** + * @var array + */ protected $data; + /** + * @throws RuntimeException Cannot extract tag name + * + * @return string + */ public function getName() { if (!preg_match('#^refs/tags/(.*)$#', $this->revision, $vars)) { diff --git a/src/Gitonomy/Git/ReferenceBag.php b/src/Gitonomy/Git/ReferenceBag.php index 4b79fc66..cbed6f61 100644 --- a/src/Gitonomy/Git/ReferenceBag.php +++ b/src/Gitonomy/Git/ReferenceBag.php @@ -93,6 +93,8 @@ public function get($fullname) } /** + * @param string $fullname Fullname of the reference (refs/heads/master, for example). + * * @return bool */ public function has($fullname) @@ -103,6 +105,8 @@ public function has($fullname) } /** + * @param Reference $reference + * * @return Reference */ public function update(Reference $reference) @@ -118,6 +122,9 @@ public function update(Reference $reference) } /** + * @param string $name + * @param string $commitHash + * * @return Reference */ public function createBranch($name, $commitHash) @@ -128,6 +135,9 @@ public function createBranch($name, $commitHash) } /** + * @param string $name + * @param string $commitHash + * * @return Reference */ public function createTag($name, $commitHash) @@ -138,6 +148,8 @@ public function createTag($name, $commitHash) } /** + * @param string $fullname Fullname of the reference (refs/heads/master, for example). + * * @return void */ public function delete($fullname) @@ -157,16 +169,31 @@ public function hasBranches() return count($this->branches) > 0; } + /** + * @param string $name Name of the branch + * + * @return bool + */ public function hasBranch($name) { return $this->has('refs/heads/'.$name); } + /** + * @param string $name Name of the remote branch + * + * @return bool + */ public function hasRemoteBranch($name) { return $this->has('refs/remotes/'.$name); } + /** + * @param string $name Name of the tag + * + * @return bool + */ public function hasTag($name) { return $this->has('refs/tags/'.$name); @@ -184,6 +211,8 @@ public function getFirstBranch() } /** + * @param Commit | string $hash + * * @return Tag[] An array of Tag objects */ public function resolveTags($hash) @@ -205,6 +234,8 @@ public function resolveTags($hash) } /** + * @param Commit | string $hash + * * @return Branch[] An array of Branch objects */ public function resolveBranches($hash) @@ -226,6 +257,8 @@ public function resolveBranches($hash) } /** + * @param Commit | string $hash + * * @return Reference[] An array of references */ public function resolve($hash) diff --git a/src/Gitonomy/Git/Repository.php b/src/Gitonomy/Git/Repository.php index fe77a888..e67dbf38 100644 --- a/src/Gitonomy/Git/Repository.php +++ b/src/Gitonomy/Git/Repository.php @@ -103,13 +103,19 @@ class Repository * * Available options are: * - * * working_dir : specify where working copy is located (option --work-tree) + * * working_dir: (default: null) specify where working copy is located (option --work-tree) * - * * debug : (default: true) enable/disable minimize errors and reduce log level + * * debug: (default: true) enable/disable minimize errors and reduce log level * - * * logger : a logger to use for logging actions (Psr\Log\LoggerInterface) + * * logger: (default: null) a logger to use for logging actions (Psr\Log\LoggerInterface) * - * * environment_variables : define environment variables for every ran process + * * environment_variables: (default: []) define environment variables for every ran process in an array + * + * * command: (default: 'git') + * + * * inherit_environment_variables: (default: false) + * + * * process_timeout: (default: 3600) * * @param string $dir path to git repository * @param array $options array of options values @@ -377,6 +383,12 @@ public function getBlob($hash) } /** + * @param Revision | string $revision + * @param string $file + * @param string $lineRange Argument to pass to git blame (-L). + * Can be a line range (40,60 or 40,+21) + * or a regexp ('/^function$/') + * * @return Blame */ public function getBlame($revision, $file, $lineRange = null) @@ -393,8 +405,8 @@ public function getBlame($revision, $file, $lineRange = null) * * All those values can be null, meaning everything. * - * @param array $revisions An array of revisions to show logs from. Can be - * any text value type + * @param mixed $revisions can be a RevisionList, a string, an array of + * strings or an array of Revision, Branch, Tag, Commit * @param array $paths Restrict log to modifications occurring on given * paths. * @param int $offset Start from a given offset in results. @@ -408,6 +420,9 @@ public function getLog($revisions = null, $paths = null, $offset = null, $limit } /** + * @param mixed $revisions can be a RevisionList, a string, an array of + * strings or an array of Revision, Branch, Tag, Commit + * * @return Diff */ public function getDiff($revisions) @@ -446,6 +461,7 @@ public function getSize() * Executes a shell command on the repository, using PHP pipes. * * @param string $command The command to execute + * @param array $env Environment variables as a key-value pair */ public function shell($command, array $env = []) { @@ -507,6 +523,8 @@ public function hasDescription() /** * Changes the repository description (file description in git-directory). * + * @param string $description New description + * * @return Repository the current repository */ public function setDescription($description) @@ -598,6 +616,7 @@ public function getLogger() * * @param string $path path to the new repository in which current repository will be cloned * @param bool $bare flag indicating if repository is bare or has a working-copy + * @param array $options options for Repository creation * * @return Repository the newly created repository */ @@ -612,7 +631,12 @@ public function cloneTo($path, $bare = true, array $options = []) * Made private to be sure that process creation is handled through the run method. * run method ensures logging and debug. * + * @param string $command Git command to run (checkout, branch, tag) + * @param array $args Arguments of git command + * * @see self::run + * + * @return Process */ private function getProcess($command, $args = []) { diff --git a/src/Gitonomy/Git/Revision.php b/src/Gitonomy/Git/Revision.php index 9e1921fb..b1ca5207 100644 --- a/src/Gitonomy/Git/Revision.php +++ b/src/Gitonomy/Git/Revision.php @@ -34,6 +34,15 @@ public function __construct(Repository $repository, $revision) } /** + * Returns log for this revision + * + * All those values can be null, meaning everything. + * + * @param array $paths Restrict log to modifications occurring on given + * paths. + * @param int $offset Start from a given offset in results. + * @param int $limit Limit number of total results. + * * @return Log */ public function getLog($paths = null, $offset = null, $limit = null) diff --git a/src/Gitonomy/Git/RevisionList.php b/src/Gitonomy/Git/RevisionList.php index 1c1a1dcd..253a5b27 100644 --- a/src/Gitonomy/Git/RevisionList.php +++ b/src/Gitonomy/Git/RevisionList.php @@ -69,6 +69,9 @@ public function count() return count($this->revisions); } + /** + * @return String[] + */ public function getAsTextArray() { return array_map(function ($revision) { diff --git a/src/Gitonomy/Git/Tree.php b/src/Gitonomy/Git/Tree.php index 570c8ff8..eef04b71 100644 --- a/src/Gitonomy/Git/Tree.php +++ b/src/Gitonomy/Git/Tree.php @@ -21,8 +21,17 @@ class Tree { protected $repository; + /** + * @var string + */ protected $hash; + /** + * @var boolean + */ protected $isInitialized = false; + /** + * @var array + */ protected $entries; public function __construct(Repository $repository, $hash) @@ -31,6 +40,9 @@ public function __construct(Repository $repository, $hash) $this->hash = $hash; } + /** + * @return string + */ public function getHash() { return $this->hash; @@ -72,6 +84,9 @@ public function getEntries() return $this->entries; } + /** + * @return Blob + */ public function getEntry($name) { $this->initialize(); @@ -83,6 +98,9 @@ public function getEntry($name) return $this->entries[$name][1]; } + /** + * @return Tree + */ public function resolvePath($path) { if ($path == '') { diff --git a/src/Gitonomy/Git/Util/StringHelper.php b/src/Gitonomy/Git/Util/StringHelper.php index d784b66b..4b93daed 100644 --- a/src/Gitonomy/Git/Util/StringHelper.php +++ b/src/Gitonomy/Git/Util/StringHelper.php @@ -21,21 +21,39 @@ class StringHelper { private static $encoding = 'utf-8'; + /** + * @return string + */ public static function getEncoding() { return self::$encoding; } + /** + * @param string $encoding + */ public static function setEncoding($encoding) { self::$encoding = $encoding; } + /** + * @param string $string + * + * @return int + */ public static function strlen($string) { return function_exists('mb_strlen') ? mb_strlen($string, self::$encoding) : strlen($string); } + /** + * @param string $string + * @param int $start + * @param int|false $length + * + * @return false|string + */ public static function substr($string, $start, $length = false) { if (false === $length) { @@ -45,11 +63,25 @@ public static function substr($string, $start, $length = false) return function_exists('mb_substr') ? mb_substr($string, $start, $length, self::$encoding) : substr($string, $start, $length); } + /** + * @param string $haystack + * @param string $needle + * @param int $offset + * + * @return false|int + */ public static function strpos($haystack, $needle, $offset = 0) { return function_exists('mb_strpos') ? mb_strpos($haystack, $needle, $offset, self::$encoding) : strpos($haystack, $needle, $offset); } + /** + * @param string $haystack + * @param string $needle + * @param int $offset + * + * @return false|int + */ public static function strrpos($haystack, $needle, $offset = 0) { return function_exists('mb_strrpos') ? mb_strrpos($haystack, $needle, $offset, self::$encoding) : strrpos($haystack, $needle, $offset); diff --git a/src/Gitonomy/Git/WorkingCopy.php b/src/Gitonomy/Git/WorkingCopy.php index aed3b85c..f5061c2a 100644 --- a/src/Gitonomy/Git/WorkingCopy.php +++ b/src/Gitonomy/Git/WorkingCopy.php @@ -35,6 +35,9 @@ public function __construct(Repository $repository) } } + /** + * @return String[] + */ public function getUntrackedFiles() { $lines = explode("\0", $this->run('status', ['--porcelain', '--untracked-files=all', '-z'])); @@ -48,6 +51,9 @@ public function getUntrackedFiles() return $lines; } + /** + * @return Diff + */ public function getDiffPending() { $diff = Diff::parse($this->run('diff', ['-r', '-p', '-m', '-M', '--full-index'])); @@ -56,6 +62,9 @@ public function getDiffPending() return $diff; } + /** + * @return Diff + */ public function getDiffStaged() { $diff = Diff::parse($this->run('diff', ['-r', '-p', '-m', '-M', '--full-index', '--staged'])); From 0622eb41d428fafa5c3493c99751b02056ad2ced Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Sat, 20 May 2023 12:31:14 +0200 Subject: [PATCH 2/9] added exception annotation --- src/Gitonomy/Git/Blame.php | 3 + src/Gitonomy/Git/Blob.php | 2 + src/Gitonomy/Git/Commit.php | 8 +++ src/Gitonomy/Git/Diff/Diff.php | 3 + src/Gitonomy/Git/Diff/File.php | 63 +++++++++++++++++++ src/Gitonomy/Git/Diff/FileChange.php | 21 ++++++- .../Git/Exception/ProcessException.php | 12 ++++ .../Exception/ReferenceNotFoundException.php | 3 + src/Gitonomy/Git/Log.php | 4 ++ src/Gitonomy/Git/Parser/ParserBase.php | 3 + src/Gitonomy/Git/PushReference.php | 3 + src/Gitonomy/Git/Reference.php | 2 + src/Gitonomy/Git/Reference/Stash.php | 3 + src/Gitonomy/Git/Reference/Tag.php | 8 +++ src/Gitonomy/Git/ReferenceBag.php | 8 +++ src/Gitonomy/Git/Repository.php | 6 +- src/Gitonomy/Git/RevisionList.php | 2 +- src/Gitonomy/Git/Tree.php | 4 ++ src/Gitonomy/Git/WorkingCopy.php | 20 +++++- 19 files changed, 173 insertions(+), 5 deletions(-) diff --git a/src/Gitonomy/Git/Blame.php b/src/Gitonomy/Git/Blame.php index 98a27db6..c02cca52 100644 --- a/src/Gitonomy/Git/Blame.php +++ b/src/Gitonomy/Git/Blame.php @@ -14,6 +14,7 @@ use Gitonomy\Git\Blame\Line; use Gitonomy\Git\Exception\InvalidArgumentException; +use Gitonomy\Git\Exception\ProcessException; use Gitonomy\Git\Parser\BlameParser; /** @@ -113,6 +114,8 @@ public function getGroupedLines() } /** + * @throws ProcessException Error while executing git command (debug-mode only) + * * @return Line[] All lines of the blame. */ public function getLines() diff --git a/src/Gitonomy/Git/Blob.php b/src/Gitonomy/Git/Blob.php index e455fe2a..8eff6602 100644 --- a/src/Gitonomy/Git/Blob.php +++ b/src/Gitonomy/Git/Blob.php @@ -12,6 +12,8 @@ namespace Gitonomy\Git; +use Gitonomy\Git\Exception\ProcessException; + /** * Representation of a Blob commit. * diff --git a/src/Gitonomy/Git/Commit.php b/src/Gitonomy/Git/Commit.php index 00d695af..0d71a74f 100644 --- a/src/Gitonomy/Git/Commit.php +++ b/src/Gitonomy/Git/Commit.php @@ -62,6 +62,8 @@ public function setData(array $data) } /** + * @throws ProcessException Error while executing git command (debug-mode only) + * * @return Diff */ public function getDiff() @@ -150,6 +152,8 @@ public function getTree() /** * @param string|null $path * + * @throws ProcessException Error while executing git command (debug-mode only) + * * @return Commit */ public function getLastModification($path = null) @@ -359,6 +363,10 @@ public function getCommit() * * @param string $name * + * @throws ProcessException Error while executing git command (debug-mode only) + * @throws ReferenceNotFoundException Reference not found + * @throws InvalidArgumentException No data with give name + * * @return Tree|string */ private function getData($name) diff --git a/src/Gitonomy/Git/Diff/Diff.php b/src/Gitonomy/Git/Diff/Diff.php index 7737ee8f..3ac9a63b 100644 --- a/src/Gitonomy/Git/Diff/Diff.php +++ b/src/Gitonomy/Git/Diff/Diff.php @@ -55,6 +55,9 @@ public static function parse($rawDiff) return new self($parser->files, $rawDiff); } + /** + * @param Repository $repository + */ public function setRepository(Repository $repository) { foreach ($this->files as $file) { diff --git a/src/Gitonomy/Git/Diff/File.php b/src/Gitonomy/Git/Diff/File.php index d3da24bb..57ca33e7 100644 --- a/src/Gitonomy/Git/Diff/File.php +++ b/src/Gitonomy/Git/Diff/File.php @@ -12,6 +12,7 @@ namespace Gitonomy\Git\Diff; +use Gitonomy\Git\Blob; use Gitonomy\Git\Repository; /** @@ -66,6 +67,13 @@ class File /** * Instanciates a new File object. + * @param string $oldName + * @param string $newName + * @param string $oldMode + * @param string $newMode + * @param string $oldIndex + * @param string $newIndex + * @param bool $isBinary */ public function __construct($oldName, $newName, $oldMode, $newMode, $oldIndex, $newIndex, $isBinary) { @@ -80,6 +88,9 @@ public function __construct($oldName, $newName, $oldMode, $newMode, $oldIndex, $ $this->changes = []; } + /** + * @param FileChange $change + */ public function addChange(FileChange $change) { $this->changes[] = $change; @@ -119,6 +130,8 @@ public function isRename() /** * Indicates if the file mode has changed. + * + * @return bool */ public function isChangeMode() { @@ -171,16 +184,25 @@ public function getDeletions() return $result; } + /** + * @return string + */ public function getOldName() { return $this->oldName; } + /** + * @return string + */ public function getNewName() { return $this->newName; } + /** + * @return string + */ public function getName() { if (null === $this->newName) { @@ -190,26 +212,41 @@ public function getName() return $this->newName; } + /** + * @return string + */ public function getOldMode() { return $this->oldMode; } + /** + * @return string + */ public function getNewMode() { return $this->newMode; } + /** + * @return string + */ public function getOldIndex() { return $this->oldIndex; } + /** + * @return string + */ public function getNewIndex() { return $this->newIndex; } + /** + * @return bool + */ public function isBinary() { return $this->isBinary; @@ -223,6 +260,9 @@ public function getChanges() return $this->changes; } + /** + * @return array + */ public function toArray() { return [ @@ -240,6 +280,8 @@ public function toArray() } /** + * @param array $array + * * @return File */ public static function fromArray(array $array) @@ -253,21 +295,36 @@ public static function fromArray(array $array) return $file; } + /** + * @return false|string + */ public function getAnchor() { return substr($this->newIndex, 0, 12); } + /** + * @return Repository + */ public function getRepository() { return $this->repository; } + /** + * @param Repository $repository + */ public function setRepository(Repository $repository) { $this->repository = $repository; } + /** + * @throws \RuntimeException Repository is missing to return Blob object. + * @throws \LogicException Can't return old Blob on a creation. + * + * @return Blob + */ public function getOldBlob() { if (null === $this->repository) { @@ -281,6 +338,12 @@ public function getOldBlob() return $this->repository->getBlob($this->oldIndex); } + /** + * @throws \RuntimeException Repository is missing to return Blob object. + * @throws \LogicException Can't return new Blob on a deletion. + * + * @return Blob + */ public function getNewBlob() { if (null === $this->repository) { diff --git a/src/Gitonomy/Git/Diff/FileChange.php b/src/Gitonomy/Git/Diff/FileChange.php index cca18dc6..f489454e 100644 --- a/src/Gitonomy/Git/Diff/FileChange.php +++ b/src/Gitonomy/Git/Diff/FileChange.php @@ -18,10 +18,25 @@ class FileChange const LINE_REMOVE = -1; const LINE_ADD = 1; + /** + * @var int + */ protected $rangeOldStart; + /** + * @var int + */ protected $rangeOldCount; + /** + * @var int + */ protected $rangeNewStart; + /** + * @var int + */ protected $rangeNewCount; + /** + * @var array + */ protected $lines; /** @@ -30,8 +45,6 @@ class FileChange * @param int $rangeNewStart * @param int $rangeNewCount * @param array $lines - * - * @return void */ public function __construct($rangeOldStart, $rangeOldCount, $rangeNewStart, $rangeNewCount, $lines) { @@ -43,6 +56,10 @@ public function __construct($rangeOldStart, $rangeOldCount, $rangeNewStart, $ran } /** + * @param int $type 'FileChange::LINE_CONTEXT', + * 'FileChange::LINE_ADD', + * 'FileChange::LINE_REMOVE' + * * @return int */ public function getCount($type) diff --git a/src/Gitonomy/Git/Exception/ProcessException.php b/src/Gitonomy/Git/Exception/ProcessException.php index 6d6b6912..66174dcf 100644 --- a/src/Gitonomy/Git/Exception/ProcessException.php +++ b/src/Gitonomy/Git/Exception/ProcessException.php @@ -6,8 +6,14 @@ class ProcessException extends RuntimeException implements GitExceptionInterface { + /** + * @var Process $process + */ protected $process; + /** + * @param Process $process + */ public function __construct(Process $process) { parent::__construct( @@ -22,11 +28,17 @@ public function __construct(Process $process) $this->process = $process; } + /** + * @return string + */ public function getErrorOutput() { return $this->process->getErrorOutput(); } + /** + * @return string + */ public function getOutput() { return $this->process->getOutput(); diff --git a/src/Gitonomy/Git/Exception/ReferenceNotFoundException.php b/src/Gitonomy/Git/Exception/ReferenceNotFoundException.php index dd9ae98d..fb0c5503 100644 --- a/src/Gitonomy/Git/Exception/ReferenceNotFoundException.php +++ b/src/Gitonomy/Git/Exception/ReferenceNotFoundException.php @@ -14,6 +14,9 @@ class ReferenceNotFoundException extends \InvalidArgumentException implements GitExceptionInterface { + /** + * @param string $reference + */ public function __construct($reference) { parent::__construct(sprintf('Reference not found: "%s"', $reference)); diff --git a/src/Gitonomy/Git/Log.php b/src/Gitonomy/Git/Log.php index 4ab3614e..149b3a74 100644 --- a/src/Gitonomy/Git/Log.php +++ b/src/Gitonomy/Git/Log.php @@ -161,6 +161,8 @@ public function getSingleCommit() } /** + * @throws ReferenceNotFoundException Can not find revision + * * @return Commit[] */ public function getCommits() @@ -230,6 +232,8 @@ public function getIterator() /** * Count commits, without offset or limit. * + * @throws ProcessException Error while executing git command (debug-mode only) + * * @return int */ public function countCommits() diff --git a/src/Gitonomy/Git/Parser/ParserBase.php b/src/Gitonomy/Git/Parser/ParserBase.php index 7cd37e75..67fc3dd2 100644 --- a/src/Gitonomy/Git/Parser/ParserBase.php +++ b/src/Gitonomy/Git/Parser/ParserBase.php @@ -22,6 +22,9 @@ abstract class ParserBase abstract protected function doParse(); + /** + * @param string $content + */ public function parse($content) { $this->cursor = 0; diff --git a/src/Gitonomy/Git/PushReference.php b/src/Gitonomy/Git/PushReference.php index f581fc0e..bd845055 100644 --- a/src/Gitonomy/Git/PushReference.php +++ b/src/Gitonomy/Git/PushReference.php @@ -13,6 +13,7 @@ namespace Gitonomy\Git; use Gitonomy\Git\Exception\LogicException; +use Gitonomy\Git\Exception\ProcessException; /** * Push reference contains a commit interval. This object aggregates methods @@ -165,6 +166,8 @@ protected function isZero($reference) } /** + * @throws ProcessException Error while executing git command (debug-mode only) + * * @return bool */ protected function getForce() diff --git a/src/Gitonomy/Git/Reference.php b/src/Gitonomy/Git/Reference.php index 3252b5fb..dd72fcd1 100644 --- a/src/Gitonomy/Git/Reference.php +++ b/src/Gitonomy/Git/Reference.php @@ -54,6 +54,8 @@ public function delete() } /** + * @throws ReferenceNotFoundException Can not find revision + * * @return string */ public function getCommitHash() diff --git a/src/Gitonomy/Git/Reference/Stash.php b/src/Gitonomy/Git/Reference/Stash.php index 9f26802f..855c7f52 100644 --- a/src/Gitonomy/Git/Reference/Stash.php +++ b/src/Gitonomy/Git/Reference/Stash.php @@ -19,6 +19,9 @@ */ class Stash extends Reference { + /** + * @return string + */ public function getName() { return 'stash'; diff --git a/src/Gitonomy/Git/Reference/Tag.php b/src/Gitonomy/Git/Reference/Tag.php index 46138ded..5f754189 100644 --- a/src/Gitonomy/Git/Reference/Tag.php +++ b/src/Gitonomy/Git/Reference/Tag.php @@ -174,6 +174,14 @@ public function isSigned() } } + /** + * @param string $name + * + * @throws \InvalidArgumentException No data wtih provided name + * @throws ProcessException Error while executing git command + * + * @return bool|\DateTime|string + */ private function getData($name) { if (!$this->isAnnotated()) { diff --git a/src/Gitonomy/Git/ReferenceBag.php b/src/Gitonomy/Git/ReferenceBag.php index cbed6f61..36a3ab28 100644 --- a/src/Gitonomy/Git/ReferenceBag.php +++ b/src/Gitonomy/Git/ReferenceBag.php @@ -12,6 +12,7 @@ namespace Gitonomy\Git; +use Gitonomy\Git\Exception\ProcessException; use Gitonomy\Git\Exception\ReferenceNotFoundException; use Gitonomy\Git\Exception\RuntimeException; use Gitonomy\Git\Reference\Branch; @@ -107,6 +108,8 @@ public function has($fullname) /** * @param Reference $reference * + * @throws ProcessException Error while executing git command (debug-mode only) + * * @return Reference */ public function update(Reference $reference) @@ -150,6 +153,8 @@ public function createTag($name, $commitHash) /** * @param string $fullname Fullname of the reference (refs/heads/master, for example). * + * @throws ProcessException Error while executing git command (debug-mode only) + * * @return void */ public function delete($fullname) @@ -376,6 +381,9 @@ public function getRemoteBranch($name) return $this->get('refs/remotes/'.$name); } + /** + * @throws RuntimeException Error while getting list of references + */ protected function initialize() { if (true === $this->initialized) { diff --git a/src/Gitonomy/Git/Repository.php b/src/Gitonomy/Git/Repository.php index e67dbf38..1079b08e 100644 --- a/src/Gitonomy/Git/Repository.php +++ b/src/Gitonomy/Git/Repository.php @@ -423,6 +423,8 @@ public function getLog($revisions = null, $paths = null, $offset = null, $limit * @param mixed $revisions can be a RevisionList, a string, an array of * strings or an array of Revision, Branch, Tag, Commit * + * @throws ProcessException Error while executing git command (debug-mode only) + * * @return Diff */ public function getDiff($revisions) @@ -546,7 +548,7 @@ public function setDescription($description) * @param string $command Git command to run (checkout, branch, tag) * @param array $args Arguments of git command * - * @throws RuntimeException Error while executing git command (debug-mode only) + * @throws ProcessException Error while executing git command (debug-mode only) * * @return string Output of a successful process or null if execution failed and debug-mode is disabled. */ @@ -634,6 +636,8 @@ public function cloneTo($path, $bare = true, array $options = []) * @param string $command Git command to run (checkout, branch, tag) * @param array $args Arguments of git command * + * @throws ProcessException Error while executing git command (debug-mode only) + * * @see self::run * * @return Process diff --git a/src/Gitonomy/Git/RevisionList.php b/src/Gitonomy/Git/RevisionList.php index 253a5b27..d64bcb76 100644 --- a/src/Gitonomy/Git/RevisionList.php +++ b/src/Gitonomy/Git/RevisionList.php @@ -70,7 +70,7 @@ public function count() } /** - * @return String[] + * @return string[] */ public function getAsTextArray() { diff --git a/src/Gitonomy/Git/Tree.php b/src/Gitonomy/Git/Tree.php index eef04b71..11742eeb 100644 --- a/src/Gitonomy/Git/Tree.php +++ b/src/Gitonomy/Git/Tree.php @@ -13,6 +13,7 @@ namespace Gitonomy\Git; use Gitonomy\Git\Exception\InvalidArgumentException; +use Gitonomy\Git\Exception\ProcessException; use Gitonomy\Git\Exception\UnexpectedValueException; /** @@ -48,6 +49,9 @@ public function getHash() return $this->hash; } + /** + * @throws ProcessException Error while executing git command (debug-mode only) + */ protected function initialize() { if (true === $this->isInitialized) { diff --git a/src/Gitonomy/Git/WorkingCopy.php b/src/Gitonomy/Git/WorkingCopy.php index f5061c2a..45fadc19 100644 --- a/src/Gitonomy/Git/WorkingCopy.php +++ b/src/Gitonomy/Git/WorkingCopy.php @@ -14,6 +14,7 @@ use Gitonomy\Git\Diff\Diff; use Gitonomy\Git\Exception\InvalidArgumentException; +use Gitonomy\Git\Exception\ProcessException; use Gitonomy\Git\Exception\LogicException; /** @@ -36,7 +37,7 @@ public function __construct(Repository $repository) } /** - * @return String[] + * @return string[] */ public function getUntrackedFiles() { @@ -74,6 +75,11 @@ public function getDiffStaged() } /** + * @param Commit | Reference | string $revision + * @param string $branch + * + * @throws InvalidArgumentException If the $revision type is not Commit, Reference or string + * * @return WorkingCopy */ public function checkout($revision, $branch = null) @@ -98,6 +104,18 @@ public function checkout($revision, $branch = null) return $this; } + + /** + * This command is a facility command. You can run any command + * directly on git repository. + * + * @param string $command Git command to run (checkout, branch, tag) + * @param array $args Arguments of git command + * + * @throws ProcessException Error while executing git command (debug-mode only) + * + * @return string Output of a successful process or null if execution failed and debug-mode is disabled. + */ protected function run($command, array $args = []) { return $this->repository->run($command, $args); From 07eac611becd4bf96bb930986c9e3ea39d634c41 Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Sat, 20 May 2023 19:55:41 +0200 Subject: [PATCH 3/9] added some more exception annotations, esp for protected methods --- src/Gitonomy/Git/Admin.php | 6 ++-- src/Gitonomy/Git/Blame.php | 6 ++-- src/Gitonomy/Git/Commit.php | 10 +++++-- src/Gitonomy/Git/Log.php | 6 +++- src/Gitonomy/Git/Parser/CommitParser.php | 15 ++++++++++ src/Gitonomy/Git/Parser/ParserBase.php | 36 ++++++++++++++++++++++++ src/Gitonomy/Git/Parser/TagParser.php | 15 ++++++++++ src/Gitonomy/Git/PushReference.php | 10 +++++-- src/Gitonomy/Git/Reference.php | 6 ++-- src/Gitonomy/Git/Reference/Tag.php | 2 +- src/Gitonomy/Git/ReferenceBag.php | 4 ++- src/Gitonomy/Git/Repository.php | 12 ++++---- src/Gitonomy/Git/RevisionList.php | 2 ++ src/Gitonomy/Git/Tree.php | 9 ++++++ src/Gitonomy/Git/WorkingCopy.php | 5 ++++ 15 files changed, 123 insertions(+), 21 deletions(-) diff --git a/src/Gitonomy/Git/Admin.php b/src/Gitonomy/Git/Admin.php index 041cad95..788c80f8 100644 --- a/src/Gitonomy/Git/Admin.php +++ b/src/Gitonomy/Git/Admin.php @@ -151,6 +151,8 @@ public static function mirrorTo($path, $url, array $options = []) * @param array $args arguments to be added to the command-line * @param array $options options for Repository creation * + * @throws RuntimeException Error while initializing repository + * * @return Repository */ public static function cloneRepository($path, $url, array $args = [], array $options = []) @@ -170,8 +172,8 @@ public static function cloneRepository($path, $url, array $args = [], array $opt * This internal method is used to create a process object. * * @param string $command - * @param array $args - * @param array $options + * @param array $args + * @param array $options * * @return Process */ diff --git a/src/Gitonomy/Git/Blame.php b/src/Gitonomy/Git/Blame.php index c02cca52..ad7100f2 100644 --- a/src/Gitonomy/Git/Blame.php +++ b/src/Gitonomy/Git/Blame.php @@ -52,8 +52,8 @@ class Blame implements \Countable * @param Revision $revision * @param string $file * @param string $lineRange Argument to pass to git blame (-L). - * Can be a line range (40,60 or 40,+21) - * or a regexp ('/^function$/') + * Can be a line range (40,60 or 40,+21) + * or a regexp ('/^function$/') */ public function __construct(Repository $repository, Revision $revision, $file, $lineRange = null) { @@ -66,6 +66,8 @@ public function __construct(Repository $repository, Revision $revision, $file, $ /** * @param int $number Line number * + * @throws InvalidArgumentException Line number does either not exist or is below 1 + * * @return Line */ public function getLine($number) diff --git a/src/Gitonomy/Git/Commit.php b/src/Gitonomy/Git/Commit.php index 0d71a74f..f0a3eea0 100644 --- a/src/Gitonomy/Git/Commit.php +++ b/src/Gitonomy/Git/Commit.php @@ -39,6 +39,8 @@ class Commit extends Revision * @param Repository $repository Repository of the commit * @param string $hash Hash of the commit * @param array $data Associative array of commit data. + * + * @throws ReferenceNotFoundException Hash not matching regular expression */ public function __construct(Repository $repository, $hash, array $data = []) { @@ -150,7 +152,7 @@ public function getTree() } /** - * @param string|null $path + * @param string $path * * @throws ProcessException Error while executing git command (debug-mode only) * @@ -213,6 +215,8 @@ public function resolveReferences() * @param bool $local set true to try to locate a commit on local repository * @param bool $remote set true to try to locate a commit on remote repository * + * @throws InvalidArgumentException You should a least set one argument to true + * * @return Reference[]|Branch[] An array of Reference\Branch */ public function getIncludingBranches($local = true, $remote = true) @@ -363,9 +367,9 @@ public function getCommit() * * @param string $name * - * @throws ProcessException Error while executing git command (debug-mode only) + * @throws ProcessException Error while executing git command (debug-mode only) * @throws ReferenceNotFoundException Reference not found - * @throws InvalidArgumentException No data with give name + * @throws InvalidArgumentException No data with give name * * @return Tree|string */ diff --git a/src/Gitonomy/Git/Log.php b/src/Gitonomy/Git/Log.php index 149b3a74..de4590fe 100644 --- a/src/Gitonomy/Git/Log.php +++ b/src/Gitonomy/Git/Log.php @@ -52,9 +52,11 @@ class Log implements \Countable, \IteratorAggregate * * @param Repository $repository the repository where log occurs * @param RevisionList|Revision|array|null $revisions a list of revisions or null if you want all history - * @param array $paths paths to filter on + * @param array|string $paths paths to filter on * @param int|null $offset start list from a given position * @param int|null $limit limit number of fetched elements + * + * @throws \InvalidArgumentException Expected a string or an array for $paths */ public function __construct(Repository $repository, $revisions = null, $paths = null, $offset = null, $limit = null) { @@ -144,6 +146,8 @@ public function setLimit($limit) /** * Returns the last modification date of the reference. * + * @ReferenceNotFoundException The log is empty + * * @return Commit */ public function getSingleCommit() diff --git a/src/Gitonomy/Git/Parser/CommitParser.php b/src/Gitonomy/Git/Parser/CommitParser.php index 98234f6d..4f619944 100644 --- a/src/Gitonomy/Git/Parser/CommitParser.php +++ b/src/Gitonomy/Git/Parser/CommitParser.php @@ -26,6 +26,9 @@ class CommitParser extends ParserBase public $committerDate; public $message; + /** + * @throws RuntimeException Unable to parse name, email and date + */ protected function doParse() { $this->consume('tree '); @@ -56,6 +59,11 @@ protected function doParse() $this->message = $this->consumeAll(); } + /** + * @throws RuntimeException unable to parse name, email and date + * + * @return array + */ protected function consumeNameEmailDate() { if (!preg_match('/(([^\n]*) <([^\n]*)> (\d+ [+-]\d{4}))/A', $this->content, $vars, 0, $this->cursor)) { @@ -67,6 +75,13 @@ protected function consumeNameEmailDate() return [$vars[2], $vars[3], $vars[4]]; } + /** + * @param string $text + * + * @throws RuntimeException Unable to convert given string to datetime + * + * @return \DateTime + */ protected function parseDate($text) { $date = \DateTime::createFromFormat('U e O', $text.' UTC'); diff --git a/src/Gitonomy/Git/Parser/ParserBase.php b/src/Gitonomy/Git/Parser/ParserBase.php index 67fc3dd2..b443c410 100644 --- a/src/Gitonomy/Git/Parser/ParserBase.php +++ b/src/Gitonomy/Git/Parser/ParserBase.php @@ -60,6 +60,11 @@ protected function expects($expected) return true; } + /** + * @throws RuntimeException No short hash found + * + * @return string + */ protected function consumeShortHash() { if (!preg_match('/([A-Za-z0-9]{7,40})/A', $this->content, $vars, 0, $this->cursor)) { @@ -71,6 +76,11 @@ protected function consumeShortHash() return $vars[1]; } + /** + * @throws RuntimeException No hash found + * + * @return string + */ protected function consumeHash() { if (!preg_match('/([A-Za-z0-9]{40})/A', $this->content, $vars, 0, $this->cursor)) { @@ -82,6 +92,13 @@ protected function consumeHash() return $vars[1]; } + /** + * @param string $regexp + * + * @throws RuntimeException No match for $regexp + * + * @return string[] + */ protected function consumeRegexp($regexp) { if (!preg_match($regexp.'A', $this->content, $vars, 0, $this->cursor)) { @@ -93,6 +110,13 @@ protected function consumeRegexp($regexp) return $vars; } + /** + * @param $text + * + * @throws RuntimeException Unable to find $text + * + * @return false|string + */ protected function consumeTo($text) { $pos = strpos($this->content, $text, $this->cursor); @@ -107,6 +131,13 @@ protected function consumeTo($text) return $result; } + /** + * @param $expected + * + * @throws RuntimeException + * + * @return false|string + */ protected function consume($expected) { $length = strlen($expected); @@ -119,6 +150,11 @@ protected function consume($expected) return $expected; } + /** + * @throws RuntimeException + * + * @return false|string + */ protected function consumeNewLine() { return $this->consume("\n"); diff --git a/src/Gitonomy/Git/Parser/TagParser.php b/src/Gitonomy/Git/Parser/TagParser.php index 659be18a..a5a79cfb 100644 --- a/src/Gitonomy/Git/Parser/TagParser.php +++ b/src/Gitonomy/Git/Parser/TagParser.php @@ -54,6 +54,9 @@ protected function doParse() } } + /** + * @return false|string + */ protected function consumeGPGSignature() { $expected = '-----BEGIN PGP SIGNATURE-----'; @@ -67,6 +70,11 @@ protected function consumeGPGSignature() return $this->consumeTo('-----END PGP SIGNATURE-----'); } + /** + * @throws RuntimeException Unable to parse name, email and date + * + * @return array + */ protected function consumeNameEmailDate() { if (!preg_match('/(([^\n]*) <([^\n]*)> (\d+ [+-]\d{4}))/A', $this->content, $vars, 0, $this->cursor)) { @@ -78,6 +86,13 @@ protected function consumeNameEmailDate() return [$vars[2], $vars[3], $vars[4]]; } + /** + * @param string $text + * + * @throws RuntimeException Unable to convert $text to datetime + * + * @return \DateTime + */ protected function parseDate($text) { $date = \DateTime::createFromFormat('U e O', $text.' UTC'); diff --git a/src/Gitonomy/Git/PushReference.php b/src/Gitonomy/Git/PushReference.php index bd845055..72491dd9 100644 --- a/src/Gitonomy/Git/PushReference.php +++ b/src/Gitonomy/Git/PushReference.php @@ -51,9 +51,9 @@ class PushReference /** * @param Repository $repository - * @param string $reference - * @param string $before - * @param string $after + * @param string $reference + * @param string $before + * @param string $after */ public function __construct(Repository $repository, $reference, $before, $after) { @@ -97,6 +97,8 @@ public function getAfter() } /** + * @param array $excludes + * * @return Log */ public function getLog($excludes = []) @@ -110,6 +112,8 @@ public function getLog($excludes = []) } /** + * @throws LogicException + * * @return string */ public function getRevision() diff --git a/src/Gitonomy/Git/Reference.php b/src/Gitonomy/Git/Reference.php index dd72fcd1..5cbc83a6 100644 --- a/src/Gitonomy/Git/Reference.php +++ b/src/Gitonomy/Git/Reference.php @@ -27,8 +27,8 @@ abstract class Reference extends Revision /** * @param Repository $repository - * @param string $revision - * @param string $commitHash + * @param string $revision + * @param string $commitHash */ public function __construct(Repository $repository, $revision, $commitHash = null) { @@ -82,7 +82,7 @@ public function getCommit() } /** - * @param string|null $path + * @param string $path * * @return Commit */ diff --git a/src/Gitonomy/Git/Reference/Tag.php b/src/Gitonomy/Git/Reference/Tag.php index 5f754189..8b103d95 100644 --- a/src/Gitonomy/Git/Reference/Tag.php +++ b/src/Gitonomy/Git/Reference/Tag.php @@ -178,7 +178,7 @@ public function isSigned() * @param string $name * * @throws \InvalidArgumentException No data wtih provided name - * @throws ProcessException Error while executing git command + * @throws ProcessException Error while executing git command * * @return bool|\DateTime|string */ diff --git a/src/Gitonomy/Git/ReferenceBag.php b/src/Gitonomy/Git/ReferenceBag.php index 36a3ab28..e8e51270 100644 --- a/src/Gitonomy/Git/ReferenceBag.php +++ b/src/Gitonomy/Git/ReferenceBag.php @@ -80,7 +80,9 @@ public function __construct($repository) * * @param string $fullname Fullname of the reference (refs/heads/master, for example). * - * @return Reference A reference object. + * @throws ReferenceNotFoundException + * + * @return Reference|Tag A reference object. */ public function get($fullname) { diff --git a/src/Gitonomy/Git/Repository.php b/src/Gitonomy/Git/Repository.php index 1079b08e..ee9f384f 100644 --- a/src/Gitonomy/Git/Repository.php +++ b/src/Gitonomy/Git/Repository.php @@ -163,6 +163,8 @@ public function __construct($dir, $options = []) * * @param string $gitDir directory of a working copy with files checked out * @param string $workingDir directory containing git files (objects, config...) + * + * @throws InvalidArgumentException Directory $$gitDir does not exist or is not a directory */ private function initDir($gitDir, $workingDir = null) { @@ -384,10 +386,10 @@ public function getBlob($hash) /** * @param Revision | string $revision - * @param string $file - * @param string $lineRange Argument to pass to git blame (-L). - * Can be a line range (40,60 or 40,+21) - * or a regexp ('/^function$/') + * @param string $file + * @param string $lineRange Argument to pass to git blame (-L). + * Can be a line range (40,60 or 40,+21) + * or a regexp ('/^function$/') * * @return Blame */ @@ -463,7 +465,7 @@ public function getSize() * Executes a shell command on the repository, using PHP pipes. * * @param string $command The command to execute - * @param array $env Environment variables as a key-value pair + * @param array $env Environment variables as a key-value pair */ public function shell($command, array $env = []) { diff --git a/src/Gitonomy/Git/RevisionList.php b/src/Gitonomy/Git/RevisionList.php index d64bcb76..87579ab1 100644 --- a/src/Gitonomy/Git/RevisionList.php +++ b/src/Gitonomy/Git/RevisionList.php @@ -22,6 +22,8 @@ class RevisionList implements \IteratorAggregate, \Countable /** * Constructs a revision list from a variety of types. * + * @throws \InvalidArgumentException Unexpected revision type + * * @param mixed $revisions can be a string, an array of strings or an array of Revision, Branch, Tag, Commit */ public function __construct(Repository $repository, $revisions) diff --git a/src/Gitonomy/Git/Tree.php b/src/Gitonomy/Git/Tree.php index 11742eeb..0e22277d 100644 --- a/src/Gitonomy/Git/Tree.php +++ b/src/Gitonomy/Git/Tree.php @@ -89,6 +89,10 @@ public function getEntries() } /** + * @param string $name + * + * @throws InvalidArgumentException No entry found + * * @return Blob */ public function getEntry($name) @@ -103,6 +107,11 @@ public function getEntry($name) } /** + * @param string $path + * + * @throws InvalidArgumentException Unresolvable path + * @throws UnexpectedValueException Unknow type of element + * * @return Tree */ public function resolvePath($path) diff --git a/src/Gitonomy/Git/WorkingCopy.php b/src/Gitonomy/Git/WorkingCopy.php index 45fadc19..0bbeef15 100644 --- a/src/Gitonomy/Git/WorkingCopy.php +++ b/src/Gitonomy/Git/WorkingCopy.php @@ -27,6 +27,11 @@ class WorkingCopy */ protected $repository; + /** + * @param Repository $repository + * + * @throws LogicException Can't create a working copy on a bare repository + */ public function __construct(Repository $repository) { $this->repository = $repository; From b2b0fe906d7187946e6f97d5acee72c528b22880 Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Sat, 20 May 2023 20:06:24 +0200 Subject: [PATCH 4/9] some fixes for styleci --- src/Gitonomy/Git/Blame.php | 6 +++--- src/Gitonomy/Git/Commit.php | 2 +- src/Gitonomy/Git/CommitReference.php | 4 ++-- src/Gitonomy/Git/Diff/File.php | 3 ++- src/Gitonomy/Git/Exception/ProcessException.php | 2 +- src/Gitonomy/Git/Hooks.php | 3 --- src/Gitonomy/Git/Repository.php | 6 +++--- src/Gitonomy/Git/Revision.php | 10 +++++----- src/Gitonomy/Git/RevisionList.php | 4 ++-- src/Gitonomy/Git/Tree.php | 5 ++++- src/Gitonomy/Git/Util/StringHelper.php | 8 ++++---- src/Gitonomy/Git/WorkingCopy.php | 6 +++--- 12 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/Gitonomy/Git/Blame.php b/src/Gitonomy/Git/Blame.php index ad7100f2..30e504c6 100644 --- a/src/Gitonomy/Git/Blame.php +++ b/src/Gitonomy/Git/Blame.php @@ -51,9 +51,9 @@ class Blame implements \Countable * @param Repository $repository * @param Revision $revision * @param string $file - * @param string $lineRange Argument to pass to git blame (-L). - * Can be a line range (40,60 or 40,+21) - * or a regexp ('/^function$/') + * @param string $lineRange Argument to pass to git blame (-L). + * Can be a line range (40,60 or 40,+21) + * or a regexp ('/^function$/') */ public function __construct(Repository $repository, Revision $revision, $file, $lineRange = null) { diff --git a/src/Gitonomy/Git/Commit.php b/src/Gitonomy/Git/Commit.php index f0a3eea0..05e07d87 100644 --- a/src/Gitonomy/Git/Commit.php +++ b/src/Gitonomy/Git/Commit.php @@ -363,7 +363,7 @@ public function getCommit() /** * Possible options are: treeHash, parentHashes, authorName, authorEmail, authorDate, - * committerName, committerEmail, committerDate, message or an other attribute + * committerName, committerEmail, committerDate, message or an other attribute. * * @param string $name * diff --git a/src/Gitonomy/Git/CommitReference.php b/src/Gitonomy/Git/CommitReference.php index b08db348..3696b6aa 100644 --- a/src/Gitonomy/Git/CommitReference.php +++ b/src/Gitonomy/Git/CommitReference.php @@ -15,12 +15,12 @@ class CommitReference { /** - * @var string $hash + * @var string */ private $hash; /** - * @param string $hash + * @param string $hash */ public function __construct($hash) { diff --git a/src/Gitonomy/Git/Diff/File.php b/src/Gitonomy/Git/Diff/File.php index 57ca33e7..4fac08eb 100644 --- a/src/Gitonomy/Git/Diff/File.php +++ b/src/Gitonomy/Git/Diff/File.php @@ -67,13 +67,14 @@ class File /** * Instanciates a new File object. + * * @param string $oldName * @param string $newName * @param string $oldMode * @param string $newMode * @param string $oldIndex * @param string $newIndex - * @param bool $isBinary + * @param bool $isBinary */ public function __construct($oldName, $newName, $oldMode, $newMode, $oldIndex, $newIndex, $isBinary) { diff --git a/src/Gitonomy/Git/Exception/ProcessException.php b/src/Gitonomy/Git/Exception/ProcessException.php index 66174dcf..7fb66aad 100644 --- a/src/Gitonomy/Git/Exception/ProcessException.php +++ b/src/Gitonomy/Git/Exception/ProcessException.php @@ -7,7 +7,7 @@ class ProcessException extends RuntimeException implements GitExceptionInterface { /** - * @var Process $process + * @var Process */ protected $process; diff --git a/src/Gitonomy/Git/Hooks.php b/src/Gitonomy/Git/Hooks.php index 466cffef..2f475613 100644 --- a/src/Gitonomy/Git/Hooks.php +++ b/src/Gitonomy/Git/Hooks.php @@ -28,9 +28,6 @@ class Hooks */ protected $repository; - /** - * @var Repository $repository - */ public function __construct(Repository $repository) { $this->repository = $repository; diff --git a/src/Gitonomy/Git/Repository.php b/src/Gitonomy/Git/Repository.php index ee9f384f..11f67c97 100644 --- a/src/Gitonomy/Git/Repository.php +++ b/src/Gitonomy/Git/Repository.php @@ -465,7 +465,7 @@ public function getSize() * Executes a shell command on the repository, using PHP pipes. * * @param string $command The command to execute - * @param array $env Environment variables as a key-value pair + * @param array $env Environment variables as a key-value pair */ public function shell($command, array $env = []) { @@ -618,8 +618,8 @@ public function getLogger() /** * Clones the current repository to a new directory and return instance of new repository. * - * @param string $path path to the new repository in which current repository will be cloned - * @param bool $bare flag indicating if repository is bare or has a working-copy + * @param string $path path to the new repository in which current repository will be cloned + * @param bool $bare flag indicating if repository is bare or has a working-copy * @param array $options options for Repository creation * * @return Repository the newly created repository diff --git a/src/Gitonomy/Git/Revision.php b/src/Gitonomy/Git/Revision.php index b1ca5207..b46d9c82 100644 --- a/src/Gitonomy/Git/Revision.php +++ b/src/Gitonomy/Git/Revision.php @@ -34,14 +34,14 @@ public function __construct(Repository $repository, $revision) } /** - * Returns log for this revision + * Returns log for this revision. * * All those values can be null, meaning everything. * - * @param array $paths Restrict log to modifications occurring on given - * paths. - * @param int $offset Start from a given offset in results. - * @param int $limit Limit number of total results. + * @param array $paths Restrict log to modifications occurring on given + * paths. + * @param int $offset Start from a given offset in results. + * @param int $limit Limit number of total results. * * @return Log */ diff --git a/src/Gitonomy/Git/RevisionList.php b/src/Gitonomy/Git/RevisionList.php index 87579ab1..5dd2fa0b 100644 --- a/src/Gitonomy/Git/RevisionList.php +++ b/src/Gitonomy/Git/RevisionList.php @@ -22,9 +22,9 @@ class RevisionList implements \IteratorAggregate, \Countable /** * Constructs a revision list from a variety of types. * - * @throws \InvalidArgumentException Unexpected revision type - * * @param mixed $revisions can be a string, an array of strings or an array of Revision, Branch, Tag, Commit + * + * @throws \InvalidArgumentException Unexpected revision type */ public function __construct(Repository $repository, $revisions) { diff --git a/src/Gitonomy/Git/Tree.php b/src/Gitonomy/Git/Tree.php index 0e22277d..b9ad266f 100644 --- a/src/Gitonomy/Git/Tree.php +++ b/src/Gitonomy/Git/Tree.php @@ -22,14 +22,17 @@ class Tree { protected $repository; + /** * @var string */ protected $hash; + /** - * @var boolean + * @var bool */ protected $isInitialized = false; + /** * @var array */ diff --git a/src/Gitonomy/Git/Util/StringHelper.php b/src/Gitonomy/Git/Util/StringHelper.php index 4b93daed..501e6b3d 100644 --- a/src/Gitonomy/Git/Util/StringHelper.php +++ b/src/Gitonomy/Git/Util/StringHelper.php @@ -48,8 +48,8 @@ public static function strlen($string) } /** - * @param string $string - * @param int $start + * @param string $string + * @param int $start * @param int|false $length * * @return false|string @@ -66,7 +66,7 @@ public static function substr($string, $start, $length = false) /** * @param string $haystack * @param string $needle - * @param int $offset + * @param int $offset * * @return false|int */ @@ -78,7 +78,7 @@ public static function strpos($haystack, $needle, $offset = 0) /** * @param string $haystack * @param string $needle - * @param int $offset + * @param int $offset * * @return false|int */ diff --git a/src/Gitonomy/Git/WorkingCopy.php b/src/Gitonomy/Git/WorkingCopy.php index 0bbeef15..a7441db9 100644 --- a/src/Gitonomy/Git/WorkingCopy.php +++ b/src/Gitonomy/Git/WorkingCopy.php @@ -14,8 +14,8 @@ use Gitonomy\Git\Diff\Diff; use Gitonomy\Git\Exception\InvalidArgumentException; -use Gitonomy\Git\Exception\ProcessException; use Gitonomy\Git\Exception\LogicException; +use Gitonomy\Git\Exception\ProcessException; /** * @author Alexandre Salomé @@ -80,8 +80,8 @@ public function getDiffStaged() } /** - * @param Commit | Reference | string $revision - * @param string $branch + * @param Commit|Reference|string $revision + * @param string $branch * * @throws InvalidArgumentException If the $revision type is not Commit, Reference or string * From 87efd1a93288ac1df4e3d3e4e5041da5ffbaaf7f Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Sat, 20 May 2023 20:08:11 +0200 Subject: [PATCH 5/9] removed unnecessary blank line --- src/Gitonomy/Git/WorkingCopy.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Gitonomy/Git/WorkingCopy.php b/src/Gitonomy/Git/WorkingCopy.php index a7441db9..8addb415 100644 --- a/src/Gitonomy/Git/WorkingCopy.php +++ b/src/Gitonomy/Git/WorkingCopy.php @@ -109,7 +109,6 @@ public function checkout($revision, $branch = null) return $this; } - /** * This command is a facility command. You can run any command * directly on git repository. From 34806c152cd4b27dffc847c937a391477090fa72 Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Sun, 21 May 2023 12:55:13 +0200 Subject: [PATCH 6/9] added missing try-catch around $process->run in $repository->run --- src/Gitonomy/Git/Repository.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Gitonomy/Git/Repository.php b/src/Gitonomy/Git/Repository.php index 11f67c97..a04eade6 100644 --- a/src/Gitonomy/Git/Repository.php +++ b/src/Gitonomy/Git/Repository.php @@ -550,9 +550,10 @@ public function setDescription($description) * @param string $command Git command to run (checkout, branch, tag) * @param array $args Arguments of git command * - * @throws ProcessException Error while executing git command (debug-mode only) - * * @return string Output of a successful process or null if execution failed and debug-mode is disabled. + * + * @throws ProcessException Error while executing git command (debug-mode only) + * or when there are Problems with executing the Process */ public function run($command, $args = []) { @@ -563,7 +564,11 @@ public function run($command, $args = []) $before = microtime(true); } - $process->run(); + try { + $process->run(); + } catch (\Exception $e) { + throw new ProcessException($process); + } $output = $process->getOutput(); From f2a4031901d185f8673209e0fff7722de56f3b25 Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Sun, 21 May 2023 13:04:38 +0200 Subject: [PATCH 7/9] added more @throws --- src/Gitonomy/Git/Admin.php | 9 +++++---- src/Gitonomy/Git/Blame.php | 5 +++-- src/Gitonomy/Git/Blob.php | 5 +++-- src/Gitonomy/Git/Commit.php | 11 +++++++---- src/Gitonomy/Git/Log.php | 5 +++-- src/Gitonomy/Git/PushReference.php | 1 + src/Gitonomy/Git/Reference/Tag.php | 3 ++- src/Gitonomy/Git/ReferenceBag.php | 4 ++++ src/Gitonomy/Git/Repository.php | 1 + src/Gitonomy/Git/Tree.php | 1 + src/Gitonomy/Git/WorkingCopy.php | 12 ++++++++++++ 11 files changed, 42 insertions(+), 15 deletions(-) diff --git a/src/Gitonomy/Git/Admin.php b/src/Gitonomy/Git/Admin.php index 788c80f8..3be66cf5 100644 --- a/src/Gitonomy/Git/Admin.php +++ b/src/Gitonomy/Git/Admin.php @@ -12,6 +12,7 @@ namespace Gitonomy\Git; +use Gitonomy\Git\Exception\ProcessException; use Gitonomy\Git\Exception\RuntimeException; use Symfony\Component\Process\Process; @@ -29,9 +30,9 @@ class Admin * @param bool $bare indicate to create a bare repository * @param array $options options for Repository creation * - * @throws RuntimeException Directory exists or not writable (only if debug=true) - * * @return Repository + * + * @throws RuntimeException Directory exists or not writable */ public static function init($path, $bare = true, array $options = []) { @@ -151,9 +152,9 @@ public static function mirrorTo($path, $url, array $options = []) * @param array $args arguments to be added to the command-line * @param array $options options for Repository creation * - * @throws RuntimeException Error while initializing repository - * * @return Repository + * + * @throws RuntimeException Error while initializing repository */ public static function cloneRepository($path, $url, array $args = [], array $options = []) { diff --git a/src/Gitonomy/Git/Blame.php b/src/Gitonomy/Git/Blame.php index 30e504c6..d66b17cd 100644 --- a/src/Gitonomy/Git/Blame.php +++ b/src/Gitonomy/Git/Blame.php @@ -116,9 +116,10 @@ public function getGroupedLines() } /** - * @throws ProcessException Error while executing git command (debug-mode only) - * * @return Line[] All lines of the blame. + * + * @throws ProcessException Error while executing git command (debug-mode only) + * or when there are Problems with executing the Process */ public function getLines() { diff --git a/src/Gitonomy/Git/Blob.php b/src/Gitonomy/Git/Blob.php index 8eff6602..6f992a4f 100644 --- a/src/Gitonomy/Git/Blob.php +++ b/src/Gitonomy/Git/Blob.php @@ -60,9 +60,10 @@ public function getHash() } /** - * @throws ProcessException Error occurred while getting content of blob - * * @return string Content of the blob. + * + * @throws ProcessException Error while executing git command (debug-mode only) + * or when there are Problems with executing the Process */ public function getContent() { diff --git a/src/Gitonomy/Git/Commit.php b/src/Gitonomy/Git/Commit.php index 05e07d87..0cae610c 100644 --- a/src/Gitonomy/Git/Commit.php +++ b/src/Gitonomy/Git/Commit.php @@ -64,9 +64,10 @@ public function setData(array $data) } /** - * @throws ProcessException Error while executing git command (debug-mode only) - * * @return Diff + * + * @throws ProcessException Error while executing git command (debug-mode only) + * or when there are Problems with executing the Process */ public function getDiff() { @@ -154,9 +155,10 @@ public function getTree() /** * @param string $path * - * @throws ProcessException Error while executing git command (debug-mode only) - * * @return Commit + * + * @throws ProcessException Error while executing git command (debug-mode only) + * or when there are Problems with executing the Process */ public function getLastModification($path = null) { @@ -368,6 +370,7 @@ public function getCommit() * @param string $name * * @throws ProcessException Error while executing git command (debug-mode only) + * or when there are Problems with executing the Process * @throws ReferenceNotFoundException Reference not found * @throws InvalidArgumentException No data with give name * diff --git a/src/Gitonomy/Git/Log.php b/src/Gitonomy/Git/Log.php index de4590fe..531ba964 100644 --- a/src/Gitonomy/Git/Log.php +++ b/src/Gitonomy/Git/Log.php @@ -236,9 +236,10 @@ public function getIterator() /** * Count commits, without offset or limit. * - * @throws ProcessException Error while executing git command (debug-mode only) - * * @return int + * + * @throws ProcessException Error while executing git command (debug-mode only) + * or when there are Problems with executing the Process */ public function countCommits() { diff --git a/src/Gitonomy/Git/PushReference.php b/src/Gitonomy/Git/PushReference.php index 72491dd9..222748cb 100644 --- a/src/Gitonomy/Git/PushReference.php +++ b/src/Gitonomy/Git/PushReference.php @@ -171,6 +171,7 @@ protected function isZero($reference) /** * @throws ProcessException Error while executing git command (debug-mode only) + * or when there are Problems with executing the Process * * @return bool */ diff --git a/src/Gitonomy/Git/Reference/Tag.php b/src/Gitonomy/Git/Reference/Tag.php index 8b103d95..f37dfb0a 100644 --- a/src/Gitonomy/Git/Reference/Tag.php +++ b/src/Gitonomy/Git/Reference/Tag.php @@ -178,7 +178,8 @@ public function isSigned() * @param string $name * * @throws \InvalidArgumentException No data wtih provided name - * @throws ProcessException Error while executing git command + * @throws ProcessException Error while executing git command (debug-mode only) + * or when there are Problems with executing the Process * * @return bool|\DateTime|string */ diff --git a/src/Gitonomy/Git/ReferenceBag.php b/src/Gitonomy/Git/ReferenceBag.php index e8e51270..c592fd50 100644 --- a/src/Gitonomy/Git/ReferenceBag.php +++ b/src/Gitonomy/Git/ReferenceBag.php @@ -111,6 +111,7 @@ public function has($fullname) * @param Reference $reference * * @throws ProcessException Error while executing git command (debug-mode only) + * or when there are Problems with executing the Process * * @return Reference */ @@ -156,6 +157,7 @@ public function createTag($name, $commitHash) * @param string $fullname Fullname of the reference (refs/heads/master, for example). * * @throws ProcessException Error while executing git command (debug-mode only) + * or when there are Problems with executing the Process * * @return void */ @@ -385,6 +387,8 @@ public function getRemoteBranch($name) /** * @throws RuntimeException Error while getting list of references + * @throws ProcessException Error while executing git command (debug-mode only) + * or when there are Problems with executing the Process */ protected function initialize() { diff --git a/src/Gitonomy/Git/Repository.php b/src/Gitonomy/Git/Repository.php index a04eade6..5743992b 100644 --- a/src/Gitonomy/Git/Repository.php +++ b/src/Gitonomy/Git/Repository.php @@ -426,6 +426,7 @@ public function getLog($revisions = null, $paths = null, $offset = null, $limit * strings or an array of Revision, Branch, Tag, Commit * * @throws ProcessException Error while executing git command (debug-mode only) + * or when there are Problems with executing the Process * * @return Diff */ diff --git a/src/Gitonomy/Git/Tree.php b/src/Gitonomy/Git/Tree.php index b9ad266f..d0a2a5d1 100644 --- a/src/Gitonomy/Git/Tree.php +++ b/src/Gitonomy/Git/Tree.php @@ -54,6 +54,7 @@ public function getHash() /** * @throws ProcessException Error while executing git command (debug-mode only) + * or when there are Problems with executing the Process */ protected function initialize() { diff --git a/src/Gitonomy/Git/WorkingCopy.php b/src/Gitonomy/Git/WorkingCopy.php index 8addb415..76ea27ec 100644 --- a/src/Gitonomy/Git/WorkingCopy.php +++ b/src/Gitonomy/Git/WorkingCopy.php @@ -43,6 +43,9 @@ public function __construct(Repository $repository) /** * @return string[] + * + * @throws ProcessException Error while executing git command (debug-mode only) + * or when there are Problems with executing the Process */ public function getUntrackedFiles() { @@ -59,6 +62,9 @@ public function getUntrackedFiles() /** * @return Diff + * + * @throws ProcessException Error while executing git command (debug-mode only) + * or when there are Problems with executing the Process */ public function getDiffPending() { @@ -70,6 +76,9 @@ public function getDiffPending() /** * @return Diff + * + * @throws ProcessException Error while executing git command (debug-mode only) + * or when there are Problems with executing the Process */ public function getDiffStaged() { @@ -84,6 +93,8 @@ public function getDiffStaged() * @param string $branch * * @throws InvalidArgumentException If the $revision type is not Commit, Reference or string + * @throws ProcessException Error while executing git command (debug-mode only) + * or when there are Problems with executing the Process * * @return WorkingCopy */ @@ -117,6 +128,7 @@ public function checkout($revision, $branch = null) * @param array $args Arguments of git command * * @throws ProcessException Error while executing git command (debug-mode only) + * or when there are Problems with executing the Process * * @return string Output of a successful process or null if execution failed and debug-mode is disabled. */ From 2a638eef5e3128cc14d85aff693f3dd3d9014748 Mon Sep 17 00:00:00 2001 From: Anatolij Vasilev Date: Sun, 21 May 2023 13:09:48 +0200 Subject: [PATCH 8/9] fixed style --- src/Gitonomy/Git/Admin.php | 9 ++++----- src/Gitonomy/Git/Blame.php | 4 ++-- src/Gitonomy/Git/Blob.php | 4 ++-- src/Gitonomy/Git/Commit.php | 8 ++++---- src/Gitonomy/Git/Log.php | 4 ++-- src/Gitonomy/Git/Repository.php | 4 ++-- src/Gitonomy/Git/WorkingCopy.php | 16 ++++++++-------- 7 files changed, 24 insertions(+), 25 deletions(-) diff --git a/src/Gitonomy/Git/Admin.php b/src/Gitonomy/Git/Admin.php index 3be66cf5..15422c10 100644 --- a/src/Gitonomy/Git/Admin.php +++ b/src/Gitonomy/Git/Admin.php @@ -12,7 +12,6 @@ namespace Gitonomy\Git; -use Gitonomy\Git\Exception\ProcessException; use Gitonomy\Git\Exception\RuntimeException; use Symfony\Component\Process\Process; @@ -30,9 +29,9 @@ class Admin * @param bool $bare indicate to create a bare repository * @param array $options options for Repository creation * - * @return Repository - * * @throws RuntimeException Directory exists or not writable + * + * @return Repository */ public static function init($path, $bare = true, array $options = []) { @@ -152,9 +151,9 @@ public static function mirrorTo($path, $url, array $options = []) * @param array $args arguments to be added to the command-line * @param array $options options for Repository creation * - * @return Repository - * * @throws RuntimeException Error while initializing repository + * + * @return Repository */ public static function cloneRepository($path, $url, array $args = [], array $options = []) { diff --git a/src/Gitonomy/Git/Blame.php b/src/Gitonomy/Git/Blame.php index d66b17cd..b88b8ee0 100644 --- a/src/Gitonomy/Git/Blame.php +++ b/src/Gitonomy/Git/Blame.php @@ -116,10 +116,10 @@ public function getGroupedLines() } /** - * @return Line[] All lines of the blame. - * * @throws ProcessException Error while executing git command (debug-mode only) * or when there are Problems with executing the Process + * + * @return Line[] All lines of the blame. */ public function getLines() { diff --git a/src/Gitonomy/Git/Blob.php b/src/Gitonomy/Git/Blob.php index 6f992a4f..2c89cfae 100644 --- a/src/Gitonomy/Git/Blob.php +++ b/src/Gitonomy/Git/Blob.php @@ -60,10 +60,10 @@ public function getHash() } /** - * @return string Content of the blob. - * * @throws ProcessException Error while executing git command (debug-mode only) * or when there are Problems with executing the Process + * + * @return string Content of the blob. */ public function getContent() { diff --git a/src/Gitonomy/Git/Commit.php b/src/Gitonomy/Git/Commit.php index 0cae610c..4dd22882 100644 --- a/src/Gitonomy/Git/Commit.php +++ b/src/Gitonomy/Git/Commit.php @@ -64,10 +64,10 @@ public function setData(array $data) } /** - * @return Diff - * * @throws ProcessException Error while executing git command (debug-mode only) * or when there are Problems with executing the Process + * + * @return Diff */ public function getDiff() { @@ -155,10 +155,10 @@ public function getTree() /** * @param string $path * - * @return Commit - * * @throws ProcessException Error while executing git command (debug-mode only) * or when there are Problems with executing the Process + * + * @return Commit */ public function getLastModification($path = null) { diff --git a/src/Gitonomy/Git/Log.php b/src/Gitonomy/Git/Log.php index 531ba964..cbeef318 100644 --- a/src/Gitonomy/Git/Log.php +++ b/src/Gitonomy/Git/Log.php @@ -236,10 +236,10 @@ public function getIterator() /** * Count commits, without offset or limit. * - * @return int - * * @throws ProcessException Error while executing git command (debug-mode only) * or when there are Problems with executing the Process + * + * @return int */ public function countCommits() { diff --git a/src/Gitonomy/Git/Repository.php b/src/Gitonomy/Git/Repository.php index 5743992b..2fd806bb 100644 --- a/src/Gitonomy/Git/Repository.php +++ b/src/Gitonomy/Git/Repository.php @@ -551,10 +551,10 @@ public function setDescription($description) * @param string $command Git command to run (checkout, branch, tag) * @param array $args Arguments of git command * - * @return string Output of a successful process or null if execution failed and debug-mode is disabled. - * * @throws ProcessException Error while executing git command (debug-mode only) * or when there are Problems with executing the Process + * + * @return string Output of a successful process or null if execution failed and debug-mode is disabled. */ public function run($command, $args = []) { diff --git a/src/Gitonomy/Git/WorkingCopy.php b/src/Gitonomy/Git/WorkingCopy.php index 76ea27ec..624a00db 100644 --- a/src/Gitonomy/Git/WorkingCopy.php +++ b/src/Gitonomy/Git/WorkingCopy.php @@ -42,10 +42,10 @@ public function __construct(Repository $repository) } /** - * @return string[] - * * @throws ProcessException Error while executing git command (debug-mode only) * or when there are Problems with executing the Process + * + * @return string[] */ public function getUntrackedFiles() { @@ -61,10 +61,10 @@ public function getUntrackedFiles() } /** - * @return Diff - * * @throws ProcessException Error while executing git command (debug-mode only) * or when there are Problems with executing the Process + * + * @return Diff */ public function getDiffPending() { @@ -75,10 +75,10 @@ public function getDiffPending() } /** - * @return Diff - * * @throws ProcessException Error while executing git command (debug-mode only) * or when there are Problems with executing the Process + * + * @return Diff */ public function getDiffStaged() { @@ -93,8 +93,8 @@ public function getDiffStaged() * @param string $branch * * @throws InvalidArgumentException If the $revision type is not Commit, Reference or string - * @throws ProcessException Error while executing git command (debug-mode only) - * or when there are Problems with executing the Process + * @throws ProcessException Error while executing git command (debug-mode only) + * or when there are Problems with executing the Process * * @return WorkingCopy */ From e4e06bb9db45728a3a9f05499cb4295fd6f3bdba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Mon, 22 May 2023 17:00:21 +0200 Subject: [PATCH 9/9] Bump minimal PHP version to 8.0 (#204) * Bump minimal PHP version to 8.0 * Fixed ci when pushing on origin repo --- .github/workflows/tests.yml | 84 ++++----------------- composer.json | 15 ++-- tests/Gitonomy/Git/Tests/RepositoryTest.php | 5 +- 3 files changed, 24 insertions(+), 80 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 34cc6607..79d8bf10 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -2,42 +2,23 @@ name: Tests on: push: + branches: [ main ] pull_request: jobs: tests: - name: PHP ${{ matrix.php }}; Symfony ${{ matrix.symfony }} - runs-on: ubuntu-20.04 - + name: Test PHP ${{ matrix.php-version }} ${{ matrix.name }} + runs-on: ubuntu-latest strategy: + fail-fast: false matrix: - php: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1'] - symfony: ['3', '4', '5', '6'] - exclude: - - php: '5.6' - symfony: '4' - - php: '5.6' - symfony: '5' - - php: '5.6' - symfony: '6' - - php: '7.0' - symfony: '4' - - php: '7.0' - symfony: '5' - - php: '7.0' - symfony: '6' - - php: '7.1' - symfony: '5' - - php: '7.1' - symfony: '6' - - php: '7.2' - symfony: '6' - - php: '7.3' - symfony: '6' - - php: '7.4' - symfony: '6' - - php: '8.1' - symfony: '3' + php-version: ['8.1', '8.2'] + composer-flags: [''] + name: [''] + include: + - php: 8.0 + composer-flags: '--prefer-lowest' + name: '(prefer lowest dependencies)' steps: - name: Checkout Code @@ -47,50 +28,13 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - tools: composer:v2 - coverage: none - name: Setup Problem Matchers run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" - - name: Select Symfony 3 - uses: nick-invision/retry@v1 - with: - timeout_minutes: 5 - max_attempts: 5 - command: composer require "symfony/process:^3.4" --no-update --no-interaction - if: "matrix.symfony == '3'" - - - name: Select Symfony 4 - uses: nick-invision/retry@v1 - with: - timeout_minutes: 5 - max_attempts: 5 - command: composer require "symfony/process:^4.4" --no-update --no-interaction - if: "matrix.symfony == '4'" - - - name: Select Symfony 5 - uses: nick-invision/retry@v1 - with: - timeout_minutes: 5 - max_attempts: 5 - command: composer require "symfony/process:^5.3" --no-update --no-interaction - if: "matrix.symfony == '5'" - - - name: Select Symfony 6 - uses: nick-invision/retry@v1 - with: - timeout_minutes: 5 - max_attempts: 5 - command: composer require "symfony/process:^6.0" --no-update --no-interaction - if: "matrix.symfony == '6'" - - - name: Install PHP Dependencies - uses: nick-invision/retry@v1 - with: - timeout_minutes: 5 - max_attempts: 5 - command: composer update --no-interaction --no-progress + - name: Install Composer dependencies + run: | + composer update --prefer-dist --no-interaction ${{ matrix.composer-flags }} - name: Execute PHPUnit run: vendor/bin/phpunit diff --git a/composer.json b/composer.json index 86735c14..fe0dd35c 100644 --- a/composer.json +++ b/composer.json @@ -35,23 +35,20 @@ } }, "require": { - "php": "^5.6 || ^7.0 || ^8.0", + "php": "^8.0", "ext-pcre": "*", "symfony/polyfill-mbstring": "^1.7", - "symfony/process": "^3.4 || ^4.4 || ^5.0 || ^6.0" + "symfony/process": "^5.4 || ^6.0" }, "require-dev": { "ext-fileinfo": "*", - "phpspec/prophecy": "^1.10.2", - "phpunit/phpunit": "^5.7.27 || ^6.5.14 || ^7.5.20 || ^8.5.20 || ^9.5.9", + "phpspec/prophecy-phpunit": "^2.0", + "phpunit/phpunit": "^7.5.20 || ^8.5.20 || ^9.5.9", "psr/log": "^1.0" }, - "suggest": { - "ext-fileinfo": "Required to determine the mimetype of a blob", - "psr/log": "Required to use loggers for reporting of execution" - }, "config": { - "preferred-install": "dist" + "preferred-install": "dist", + "sort-packages": true }, "minimum-stability": "dev", "prefer-stable": true diff --git a/tests/Gitonomy/Git/Tests/RepositoryTest.php b/tests/Gitonomy/Git/Tests/RepositoryTest.php index 7ff6a195..de433dff 100644 --- a/tests/Gitonomy/Git/Tests/RepositoryTest.php +++ b/tests/Gitonomy/Git/Tests/RepositoryTest.php @@ -15,9 +15,12 @@ use Gitonomy\Git\Blob; use Gitonomy\Git\Exception\RuntimeException; use Prophecy\Argument; +use Prophecy\PhpUnit\ProphecyTrait; class RepositoryTest extends AbstractTest { + use ProphecyTrait; + /** * @dataProvider provideFoobar */ @@ -40,7 +43,7 @@ public function testGetBlobWithExistingWorks($repository) public function testGetSize($repository) { $size = $repository->getSize(); - $this->assertGreaterThanOrEqual(69, $size, 'Repository is at least 69KB'); + $this->assertGreaterThanOrEqual(53, $size, 'Repository is at least 53KB'); $this->assertLessThan(80, $size, 'Repository is less than 80KB'); }