From 926ffe6b00c9db4943b8eadcfcc704451a9834ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoander=20Vald=C3=A9s=20Rodr=C3=ADguez?= Date: Fri, 25 May 2012 14:50:01 -0400 Subject: [PATCH 1/3] Fixed: Undefined variable: repositories in gitlist/lib/Git/Client.php on line 94 --- lib/Git/Client.php | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/Git/Client.php b/lib/Git/Client.php index e7a4ae0..e0b650e 100644 --- a/lib/Git/Client.php +++ b/lib/Git/Client.php @@ -13,7 +13,7 @@ class Client /** * Creates a new repository on the specified path - * + * * @param string $path Path where the new repository will be created * @return Repository Instance of Repository */ @@ -29,7 +29,7 @@ class Client /** * Opens a repository at the specified path - * + * * @param string $path Path where the repository is located * @return Repository Instance of Repository */ @@ -44,7 +44,7 @@ class Client /** * Searches for valid repositories on the specified path - * + * * @param string $path Path where repositories will be searched * @return array Found repositories, containing their name, path and description */ @@ -55,7 +55,7 @@ class Client if (!isset($repositories)) { throw new \RuntimeException('There are no GIT repositories in ' . $path); } - + sort($repositories); return $repositories; @@ -65,6 +65,9 @@ class Client { $dir = new \DirectoryIterator($path); + // Good practice defined a variable before using it + $repositories = null; + foreach ($dir as $file) { if ($file->isDot()) { continue; @@ -72,14 +75,14 @@ class Client $isBare = file_exists($file->getPathname() . '/HEAD'); $isRepository = file_exists($file->getPathname() . '/.git/HEAD'); - + if ($file->isDir() && $isRepository || $isBare) { if ($isBare) { $description = file_get_contents($file->getPathname() . '/description'); } else { $description = file_get_contents($file->getPathname() . '/.git/description'); } - + $repositories[] = array('name' => $file->getFilename(), 'path' => $file->getPathname(), 'description' => $description); continue; } @@ -94,11 +97,11 @@ class Client /** * Execute a git command on the repository being manipulated - * + * * This method will start a new process on the current machine and - * run git commands. Once the command has been run, the method will + * run git commands. Once the command has been run, the method will * return the command line output. - * + * * @param Repository $repository Repository where the command will be run * @param string $command Git command to be run * @return string Returns the command output @@ -118,7 +121,7 @@ class Client /** * Get the current Git binary path - * + * * @return string Path where the Git binary is located */ protected function getPath() @@ -128,7 +131,7 @@ class Client /** * Set the current Git binary path - * + * * @param string $path Path where the Git binary is located */ protected function setPath($path) From 198d1735365908c4732b155ba874c2b033cd5fd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoander=20Vald=C3=A9s=20Rodr=C3=ADguez?= Date: Fri, 25 May 2012 16:31:48 -0400 Subject: [PATCH 2/3] Initializing the repositories vas as empty array instead of null --- lib/Git/Client.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Git/Client.php b/lib/Git/Client.php index e0b650e..aafbca0 100644 --- a/lib/Git/Client.php +++ b/lib/Git/Client.php @@ -65,8 +65,7 @@ class Client { $dir = new \DirectoryIterator($path); - // Good practice defined a variable before using it - $repositories = null; + $repositories = array(); foreach ($dir as $file) { if ($file->isDot()) { From ab33a63c49654b03c8cbcc6e102b1f5d8d1f494c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoander=20Vald=C3=A9s=20Rodr=C3=ADguez?= Date: Fri, 25 May 2012 16:43:40 -0400 Subject: [PATCH 3/3] checking repositories var as empty array --- lib/Git/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Git/Client.php b/lib/Git/Client.php index aafbca0..bdb5a48 100644 --- a/lib/Git/Client.php +++ b/lib/Git/Client.php @@ -52,7 +52,7 @@ class Client { $repositories = $this->recurseDirectory($path); - if (!isset($repositories)) { + if (!empty($repositories)) { throw new \RuntimeException('There are no GIT repositories in ' . $path); }