From 3631e4918f0ac47654ac0be7775e97a381c9d183 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Mon, 24 Oct 2016 20:47:29 +0200 Subject: [PATCH] Add comments --- Event/EventManager.php | 2 -- Uri/Http.php | 3 ++ Uri/UriFactory.php | 28 +++++++++++++----- Uri/UriInterface.php | 10 +++++++ Utils/Git/Repository.php | 63 +++++++++++++++++++++++++++++++++++----- 5 files changed, 88 insertions(+), 18 deletions(-) diff --git a/Event/EventManager.php b/Event/EventManager.php index 81b333c24..be7446beb 100644 --- a/Event/EventManager.php +++ b/Event/EventManager.php @@ -32,8 +32,6 @@ use phpOMS\Pattern\Mediator; */ class EventManager implements Mediator { - const DELIM = ':'; - /** * Events. * diff --git a/Uri/Http.php b/Uri/Http.php index 9ea8bcc06..7bd77288f 100644 --- a/Uri/Http.php +++ b/Uri/Http.php @@ -261,6 +261,9 @@ class Http implements UriInterface return $this->path ?? ''; } + /** + * {@inheritdoc} + */ public function getRoute() : string { return ($this->path ?? '') . '?' . $this->getQuery(); diff --git a/Uri/UriFactory.php b/Uri/UriFactory.php index 1bd6c2495..3536802bd 100644 --- a/Uri/UriFactory.php +++ b/Uri/UriFactory.php @@ -87,27 +87,39 @@ class UriFactory return false; } + /** + * Simplify url + * + * While adding, and removing elements to a uri it can have multiple parameters or empty parameters which need to be cleaned up + * + * @param string $url Url to simplify + * + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ private static function unique(string $url) : string { $parts = explode('?', $url); if (count($parts) >= 2) { - $full = $parts[1]; - $pars = explode('&', $full); - $comps = []; - $spl = null; + $full = $parts[1]; + $pars = explode('&', $full); + $comps = []; + $spl = null; $length = count($pars); for ($i = 0; $i < $length; $i++) { - $spl = explode('=', $pars[$i]); + $spl = explode('=', $pars[$i]); - if(isset($spl[1])) { + if (isset($spl[1])) { $comps[$spl[0]] = $spl[1]; } } $pars = []; - foreach($comps as $key => $value) { + foreach ($comps as $key => $value) { $pars[] = $key . '=' . $value; } @@ -146,7 +158,7 @@ class UriFactory }, $uri); // todo: maybe don't do this and adjust unique?! - if(strpos($parsed, '?')) { + if (strpos($parsed, '?')) { str_replace('&', '?', $parsed); } diff --git a/Uri/UriInterface.php b/Uri/UriInterface.php index fe4d653ac..12454d966 100644 --- a/Uri/UriInterface.php +++ b/Uri/UriInterface.php @@ -155,6 +155,16 @@ interface UriInterface */ public function getBase() : string; + /** + * Get route representation of uri. + * + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getRoute() : string; + /** * Set uri. * diff --git a/Utils/Git/Repository.php b/Utils/Git/Repository.php index 335f0e73b..0a42fe7c6 100644 --- a/Utils/Git/Repository.php +++ b/Utils/Git/Repository.php @@ -301,15 +301,28 @@ class Repository return implode("\n", $this->run('add ' . $files . ' -v')); } + /** + * Remove file(s) from repository + * + * @param string|array $files Files to remove + * @param bool $cached ? + * + * @return string + * + * @throws \InvalidArgumentException + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function rm($files = '*', bool $cached = false) : string { if (is_array($files)) { $files = '"' . implode('" "', $files) . '"'; } elseif (!is_string($files)) { - throw new \Exception('Wrong type'); + throw new \InvalidArgumentException('Wrong type for $files.'); } - return $this->run('rm ' . ($cached ? '--cached ' : '') . $files); + return implode("\n", $this->run('rm ' . ($cached ? '--cached ' : '') . $files)); } /** @@ -328,31 +341,65 @@ class Repository return implode("\n", $this->run('commit ' . ($all ? '-av' : '-v') . ' -m ' . escapeshellarg($commit->getMessage()))); } + /** + * Clone repository to different directory + * + * @param string $target Target clone directory + * + * @return string + * + * @throws PathException in case the target is not a valid directory + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function cloneTo(string $target) : string { if (!is_dir($target)) { - throw new \Exception('Not a directory'); + throw new PathException($target); } - return $this->run('clone --local ' . $this->path . ' ' . $target); + return implode("\n", $this->run('clone --local ' . $this->path . ' ' . $target)); } + /** + * Clone repository to current directory + * + * @param string $source Source repository to clone + * + * @return string + * + * @throws PathException in case the source repository is not valid + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function cloneFrom(string $source) : string { if (!is_dir($source)) { - throw new \Exception('Not a directory'); + throw new PathException($source); } // todo: is valid git repository? - return $this->run('clone --local ' . $source . ' ' . $this->path); + return implode("\n", $this->run('clone --local ' . $source . ' ' . $this->path)); } + /** + * Clone remote repository to current directory + * + * @param string $source Source repository to clone + * + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ public function cloneRemote(string $source) : string { // todo: is valid remote git repository? - return $this->run('clone ' . $source . ' ' . $this->path); + return implode("\n", $this->run('clone ' . $source . ' ' . $this->path)); } /** @@ -853,7 +900,7 @@ class Repository throw new \Exception('Invalid commit id'); } - if(StringUtils::startsWith($lines[1], 'Merge')) { + if (StringUtils::startsWith($lines[1], 'Merge')) { return new Commit(); }