Page MenuHomeDevCentral

D611.diff
No OneTemporary

D611.diff

diff --git a/app/Phabricator/PhabricatorAPIException.php b/app/Phabricator/PhabricatorAPIException.php
--- a/app/Phabricator/PhabricatorAPIException.php
+++ b/app/Phabricator/PhabricatorAPIException.php
@@ -3,6 +3,7 @@
namespace Nasqueron\Notifications\Phabricator;
class PhabricatorAPIException extends \RuntimeException {
+
/**
* @param int $code The error_code field for the API reply
* @param string $message The error_info field from the API reply
@@ -11,4 +12,5 @@
$this->code = $code;
$this->message = $message;
}
+
}
diff --git a/app/Phabricator/PhabricatorAPIFactory.php b/app/Phabricator/PhabricatorAPIFactory.php
--- a/app/Phabricator/PhabricatorAPIFactory.php
+++ b/app/Phabricator/PhabricatorAPIFactory.php
@@ -7,7 +7,7 @@
class PhabricatorAPIFactory implements APIFactory {
/**
- * Gets an instance of the Phabricator API client class
+ * Gets an instance of the Phabricator API client class.
*
* @param string $instance The Phabricator instance
* @return Nasqueron\Notifications\Phabricator\PhabricatorAPI
@@ -17,7 +17,7 @@
}
/**
- * Gets an instance of the Phabricator API client class for a project
+ * Gets an instance of the Phabricator API client class for a project.
*
* @param string $project The Phabricator project name
* @return Nasqueron\Notifications\Phabricator\PhabricatorAPI
diff --git a/app/Phabricator/ProjectsMap.php b/app/Phabricator/ProjectsMap.php
--- a/app/Phabricator/ProjectsMap.php
+++ b/app/Phabricator/ProjectsMap.php
@@ -14,22 +14,22 @@
///
/**
- * The maximum number of projects to fetch
- */
+ * The maximum number of projects to fetch
+ */
const LIMIT = 1000;
/**
- * The projects as an array with phid as keys, project names as $value
- *
- * @var string[]
- */
+ * The projects as an array with phid as keys, project names as $value
+ *
+ * @var string[]
+ */
private $map = [];
/**
- * The Phabricator instance for this projects map
- *
- * @var string
- */
+ * The Phabricator instance for this projects map
+ *
+ * @var string
+ */
private $instance;
/**
@@ -50,10 +50,10 @@
///
/**
- * Initializes a new instance of ProjectsMap
- *
- * @param string $instance The Phabricator root URL without trailing slash
- */
+ * Initializes a new instance of ProjectsMap.
+ *
+ * @param string $instance The Phabricator root URL without trailing slash
+ */
public function __construct ($instance) {
$this->instance = $instance;
}
@@ -63,10 +63,10 @@
///
/**
- * Gets iterator
- *
- * @return Traversable
- */
+ * Gets iterator.
+ *
+ * @return Traversable
+ */
public function getIterator () {
return new \ArrayIterator($this->map);
}
@@ -76,39 +76,40 @@
///
/**
- * Determines whether an offset exists
- *
- * @param mixed $offset The offset
- */
+ * Determines whether an offset exists.
+ *
+ * @param mixed $offset The offset
+ * @return bool
+ */
public function offsetExists ($offset) {
return array_key_exists($offset, $this->map);
}
/**
- * Gets an offset
- *
- * @param mixed $offset The offset
- * @return mixed The value
- */
+ * Gets the value at the specified offset.
+ *
+ * @param mixed $offset The offset.
+ * @return mixed The value
+ */
public function offsetGet ($offset) {
return $this->map[$offset];
}
/**
- * Assigns a value to the specified offset
- *
- * @param mixed $offset The offset
- * @param mixed $value The value to assign
- */
+ * Assigns a value to the specified offset.
+ *
+ * @param mixed $offset The offset
+ * @param mixed $value The value to assign
+ */
public function offsetSet ($offset, $value) {
$this->map[$offset] = $value;
}
/**
- * Unset an offset
- *
- * @param mixed $offset The offset
- */
+ * Unsets a value at the specified offset.
+ *
+ * @param mixed $offset The offset where to remove the value
+ */
public function offsetUnset ($offset) {
unset($this->map[$offset]);
}
@@ -118,11 +119,11 @@
///
/**
- * Gets a new ProjectsMap instance from cache or API when not cached
- *
- * @param string $phabricatorURL The Phabricator URL (e.g. http://secure.phabricator.com)
- * @return ProjectsMap
- */
+ * Gets a new ProjectsMap instance from cache or API when not cached.
+ *
+ * @param string $phabricatorURL The Phabricator URL (e.g. http://secure.phabricator.com)
+ * @return ProjectsMap
+ */
public static function load ($phabricatorURL) {
$instance = new self($phabricatorURL);
@@ -136,12 +137,12 @@
}
/**
- * Gets a new ProjectsMap instance and queries Phabricator API to fill it
- *
- * @param string $phabricatorURL The Phabricator URL (e.g. http://secure.phabricator.com)
- * @param Nasqueron\Notifications\Contracts\APIClient $apiClient The Phabricator API client
- * @return ProjectsMap
- */
+ * Gets a new ProjectsMap instance and queries Phabricator API to fill it.
+ *
+ * @param string $phabricatorURL The Phabricator URL (e.g. http://secure.phabricator.com)
+ * @param Nasqueron\Notifications\Contracts\APIClient $apiClient The Phabricator API client
+ * @return ProjectsMap
+ */
public static function fetch ($phabricatorURL, APIClient $apiClient = null) {
$instance = new self($phabricatorURL);
$instance->setAPIClient($apiClient);
@@ -172,8 +173,10 @@
}
/**
- * Fetches the projects' map from the Phabricator API
- */
+ * Fetches the projects' map from the Phabricator API.
+ *
+ * @throws \Exception when API reply is empty or invalid.
+ */
private function fetchFromAPI () {
$reply = $this->getAPIClient()->call(
'project.query',
@@ -200,35 +203,35 @@
///
/**
- * Gets cache key
- *
- * @return string The cache key for the current projects map
- */
+ * Gets cache key.
+ *
+ * @return string The cache key for the current projects map
+ */
private function getCacheKey () {
return class_basename(get_class($this)) . '-' . md5($this->instance);
}
/**
- * Determines if the instance is cached
- *
- * @return bool true if cached; otherwise, false.
- */
+ * Determines if the instance is cached
+ *
+ * @return bool true if cached; otherwise, false.
+ */
public function isCached () {
return Cache::has($this->getCacheKey());
}
/**
- * Saves data to cache
- */
+ * Saves data to cache
+ */
public function saveToCache () {
Cache::forever($this->getCacheKey(), $this->map);
}
/**
- * Loads data from cache
- *
- * Populates 'map' and 'source' properties
- */
+ * Loads data from cache
+ *
+ * Populates 'map' and 'source' properties
+ */
public function loadFromCache () {
$cachedMap = Cache::get($this->getCacheKey());
if ($cachedMap !== null) {
@@ -242,11 +245,11 @@
///
/**
- * Gets project name, refreshing the cache if needed
- *
- * @param string $projectPHID the PHID of the project to query the name
- * @return string
- */
+ * Gets project name, refreshing the cache if needed.
+ *
+ * @param string $projectPHID the PHID of the project to query the name
+ * @return string The name of the poject, or an empty string if not found
+ */
public function getProjectName ($projectPHID) {
if ($this->offsetExists($projectPHID)) {
return $this->offsetGet($projectPHID);
@@ -261,10 +264,10 @@
}
/**
- * Returns the projects map as an array, each row ['PHID', 'project name']
- *
- * @return array
- */
+ * Returns the projects map as an array.
+ *
+ * @return array An array, each row containing ['PHID', 'project name']
+ */
public function toArray () {
$array = [];
foreach ($this->map as $phid => $projectName) {
diff --git a/app/Phabricator/ProjectsMapFactory.php b/app/Phabricator/ProjectsMapFactory.php
--- a/app/Phabricator/ProjectsMapFactory.php
+++ b/app/Phabricator/ProjectsMapFactory.php
@@ -5,7 +5,7 @@
class ProjectsMapFactory {
/**
- * Loads projects map from cache or fetches it from API if not cached
+ * Loads projects map from cache or fetches it from API if not cached.
*
* @param string $instance The Phabricator instance
* @return Nasqueron\Notifications\Phabricator\ProjectsMap
@@ -15,7 +15,7 @@
}
/**
- * Fetches projects map from API
+ * Fetches projects map from API.
*
* @param string $instance The Phabricator instance
* @return Nasqueron\Notifications\Phabricator\ProjectsMap

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 24, 07:12 (14 h, 20 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2259685
Default Alt Text
D611.diff (8 KB)

Event Timeline