From 878e74dba56e76f6be6b707e87e7bec0fdaba636 Mon Sep 17 00:00:00 2001 From: Christian Fritsch Date: Fri, 30 Jun 2017 09:42:44 +0200 Subject: [PATCH] More CS fixes. --- src/Asset/Article.php | 8 +- src/Asset/BaseAsset.php | 11 +- src/Asset/Image.php | 8 +- src/ClientInterface.php | 35 ++- src/Controller/DcxDebugController.php | 12 +- src/Exception/DcxClientException.php | 2 +- src/Exception/IllegalAssetTypeException.php | 2 +- src/Exception/IllegalAttributeException.php | 2 +- src/Exception/MandatoryAttributeException.php | 2 +- .../UnknownDocumentTypeException.php | 2 +- src/JsonClient.php | 247 +++++++++--------- 11 files changed, 175 insertions(+), 156 deletions(-) diff --git a/src/Asset/Article.php b/src/Asset/Article.php index 96e1e61..c870111 100644 --- a/src/Asset/Article.php +++ b/src/Asset/Article.php @@ -8,13 +8,13 @@ * @package Drupal\dcx_integration\Asset */ class Article extends BaseAsset { - static $mandatory_attributes = [ + protected static $mandatoryAttributes = [ 'id', 'title', 'body', ]; - static $optional_attributes = [ + protected static $optionalAttributes = [ 'files', ]; @@ -24,8 +24,8 @@ class Article extends BaseAsset { * @param array $data * Data representing this asset. */ - public function __construct($data) { - parent::__construct($data, self::$mandatory_attributes, self::$optional_attributes); + public function __construct(array $data) { + parent::__construct($data, self::$mandatoryAttributes, self::$optionalAttributes); } } diff --git a/src/Asset/BaseAsset.php b/src/Asset/BaseAsset.php index 9203b08..ed85001 100644 --- a/src/Asset/BaseAsset.php +++ b/src/Asset/BaseAsset.php @@ -21,14 +21,16 @@ abstract class BaseAsset { * @param array $data * The data representing the asset. * @param array $mandatory_attributes + * List of mandatory attributes for this asset. * @param array $optional_attributes + * List of optional attributes for this asset. * * @throws \Drupal\dcx_integration\Exception\MandatoryAttributeException - * if mandatory attributes are missing. + * If mandatory attributes are missing. * @throws \Drupal\dcx_integration\Exception\IllegalAttributeException - * if unknown attributes are present. + * If unknown attributes are present. */ - public function __construct($data, $mandatory_attributes, $optional_attributes = []) { + public function __construct(array $data, array $mandatory_attributes, array $optional_attributes = []) { foreach ($mandatory_attributes as $attribute) { if (!isset($data[$attribute]) || empty($data[$attribute])) { $e = new MandatoryAttributeException($attribute); @@ -47,7 +49,10 @@ public function __construct($data, $mandatory_attributes, $optional_attributes = } /** + * The data representing the asset. * + * @return array + * Return the data. */ public function data() { return $this->data; diff --git a/src/Asset/Image.php b/src/Asset/Image.php index 38fd61d..9d26ee8 100644 --- a/src/Asset/Image.php +++ b/src/Asset/Image.php @@ -8,7 +8,7 @@ * @package Drupal\dcx_integration\Asset */ class Image extends BaseAsset { - static $mandatory_attributes = [ + protected static $mandatoryAttributes = [ 'id', 'filename', 'title', @@ -16,7 +16,7 @@ class Image extends BaseAsset { 'status', ]; - static $optional_attributes = [ + protected static $optionalAttributes = [ 'creditor', 'copyright', 'fotocredit', @@ -31,8 +31,8 @@ class Image extends BaseAsset { * @param array $data * Data representing this asset. */ - public function __construct($data) { - parent::__construct($data, self::$mandatory_attributes, self::$optional_attributes); + public function __construct(array $data) { + parent::__construct($data, self::$mandatoryAttributes, self::$optionalAttributes); } } diff --git a/src/ClientInterface.php b/src/ClientInterface.php index d858015..3a8049a 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -10,7 +10,22 @@ interface ClientInterface { /** + * Retrieve a DC-X object with the given id. * + * Emits an HTTP request to the DC-X server and evaluates the response. + * Depending on the document "Type" (an attribute stored within the fields, + * not to be confused with the attribute "type") it returns subclasses of + * BaseAsset which encapsulate a flat array representation of the data + * retrieved. + * + * @param string $id + * A dcx object identifier. Something like "dcxapi:document/xyz". + * + * @return \Drupal\dcx_integration\Asset\BaseAsset + * An instance of BaseAsset depending on the retrieved data. + * + * @throws \Exception + * Throws exceptions if anything fails. */ public function getObject($id); @@ -22,7 +37,7 @@ public function getObject($id); * * @param array $used_entities * List entities keyed by their DC-X document ids. - * @param string $url + * @param string $path * Relative canonical URL where the documents are used. * @param bool $published * Status of the given URL. @@ -32,7 +47,7 @@ public function getObject($id); * @throws \Exception * If something is going wrong. */ - public function trackUsage($used_entities, $url, $published, $type); + public function trackUsage(array $used_entities, $path, $published, $type); /** * Archive an article. @@ -50,7 +65,7 @@ public function trackUsage($used_entities, $url, $published, $type); * @throws \Exception * If something is going wrong. */ - public function archiveArticle($url, $data, $dcx_id); + public function archiveArticle($url, array $data, $dcx_id); /** * Return all DC-X documents which have a pubinfo referencing the given path. @@ -82,7 +97,8 @@ public function removeAllUsage($dcx_id); /** * Retrieve collections of the current user. * - * @return array of arrays keyed by collection id. + * @return array + * Of arrays keyed by collection id. */ public function getCollections(); @@ -90,16 +106,19 @@ public function getCollections(); * Return filename and url of a thumbnail for the given (image) document. * * @param string $id + * DC-X document ID. * - * @return data array containg filename, url and id. + * @return array + * Data containg filename, url and id. * - * @throws DcxClientException + * @throws \Drupal\dcx_integration\Exception\DcxClientException */ public function getPreview($id); /** - * Removes usage information about the given DC-X ID on the current site, but - * only for the given entity. + * Removes usage information about the given DC-X ID on the current site. + * + * But only for the given entity. * * The reason for calling this is deleting a cloned media entity. * diff --git a/src/Controller/DcxDebugController.php b/src/Controller/DcxDebugController.php index 233c831..5ca93c2 100644 --- a/src/Controller/DcxDebugController.php +++ b/src/Controller/DcxDebugController.php @@ -18,13 +18,13 @@ class DcxDebugController extends ControllerBase { * * @var \Drupal\dcx_integration\ClientInterface */ - protected $dcx_integration_client; + protected $dcxIntegrationClient; /** * {@inheritdoc} */ public function __construct(ClientInterface $dcx_integration_client) { - $this->dcx_integration_client = $dcx_integration_client; + $this->dcxIntegrationClient = $dcx_integration_client; } /** @@ -43,10 +43,10 @@ public function debug($type, $id) { $dcxid = "dcxapi:" . $type . '/' . $id; try { - if (method_exists($this->dcx_integration_client, 'getJson')) { - $json = $this->dcx_integration_client->getJson($dcxid); + if (method_exists($this->dcxIntegrationClient, 'getJson')) { + $json = $this->dcxIntegrationClient->getJson($dcxid); } - $data = $this->dcx_integration_client->getObject($dcxid); + $data = $this->dcxIntegrationClient->getObject($dcxid); } catch (\Exception $e) { dpm($e->getMessage(), "Meh :("); @@ -76,7 +76,7 @@ public function archive() { $dcx_id = NULL; try { - $dcx_id = $this->dcx_integration_client->archiveArticle($url, $title, $text, $dcx_id); + $dcx_id = $this->dcxIntegrationClient->archiveArticle($url, $title, $text, $dcx_id); } catch (\Exception $e) { dpm($e); diff --git a/src/Exception/DcxClientException.php b/src/Exception/DcxClientException.php index bcffa13..a310b49 100644 --- a/src/Exception/DcxClientException.php +++ b/src/Exception/DcxClientException.php @@ -8,7 +8,7 @@ class DcxClientException extends \Exception { /** - * + * Constructs DcxClientException. */ public function __construct($method, $code, $url, $params = [], $json = [], $message = '') { $message = sprintf('Error performing %s on url "%s". Status code was %s. Params: %s. JSON: %s. %s', $method, $url, $code, json_encode($params), json_encode($json), $message); diff --git a/src/Exception/IllegalAssetTypeException.php b/src/Exception/IllegalAssetTypeException.php index ec2761c..36c5bf2 100644 --- a/src/Exception/IllegalAssetTypeException.php +++ b/src/Exception/IllegalAssetTypeException.php @@ -8,7 +8,7 @@ class IllegalAssetTypeException extends \Exception { /** - * + * Constructs IllegalAssetTypeException. */ public function __construct($id, $found_type, $expected_type) { $message = sprintf("DC-X document '%s' is of type '%s'. Expecting type '%s'.", $id, $found_type, $expected_type); diff --git a/src/Exception/IllegalAttributeException.php b/src/Exception/IllegalAttributeException.php index cc0fc60..c716bd4 100644 --- a/src/Exception/IllegalAttributeException.php +++ b/src/Exception/IllegalAttributeException.php @@ -8,7 +8,7 @@ class IllegalAttributeException extends \Exception { /** - * + * Constructs IllegalAttributeException. */ public function __construct($attribute) { $message = sprintf("Attribute %s is not allowed", $attribute); diff --git a/src/Exception/MandatoryAttributeException.php b/src/Exception/MandatoryAttributeException.php index 9f94810..02a702b 100644 --- a/src/Exception/MandatoryAttributeException.php +++ b/src/Exception/MandatoryAttributeException.php @@ -10,7 +10,7 @@ class MandatoryAttributeException extends \Exception { public $attribute; /** - * + * Constructs MandatoryAttributeException. */ public function __construct($attribute) { $message = sprintf("Attribute '%s' is mandatory", $attribute); diff --git a/src/Exception/UnknownDocumentTypeException.php b/src/Exception/UnknownDocumentTypeException.php index aff405d..96545ea 100644 --- a/src/Exception/UnknownDocumentTypeException.php +++ b/src/Exception/UnknownDocumentTypeException.php @@ -8,7 +8,7 @@ class UnknownDocumentTypeException extends \Exception { /** - * + * Constructs UnknownDocumentTypeException. */ public function __construct($type, $id) { $message = sprintf("DC-X object %s has unknown type '%s'.", $id, $type); diff --git a/src/JsonClient.php b/src/JsonClient.php index 3a93c81..f18ef94 100644 --- a/src/JsonClient.php +++ b/src/JsonClient.php @@ -23,6 +23,7 @@ * @package Drupal\dcx_integration */ class JsonClient implements ClientInterface { + use StringTranslationTrait; /** @@ -30,7 +31,7 @@ class JsonClient implements ClientInterface { * * @var \Digicol\DcxSdk\DcxApiClient */ - protected $api_client; + protected $dcxApiClient; /** * JSON client settings. @@ -38,18 +39,17 @@ class JsonClient implements ClientInterface { * @var \Drupal\Core\Config\ImmutableConfig */ protected $config; - /** - * Constructor. - */ /** * Publication ID from 'dcx_integration.jsonclientsettings'. * * @var string */ - protected $publication_id; + protected $publicationId; /** + * Logger service. + * * @var \Psr\Log\LoggerInterface */ protected $logger; @@ -88,13 +88,13 @@ public function __construct(ConfigFactoryInterface $config_factory, AccountProxy 'username' => $username, 'password' => $password, ]; - $this->api_client = new DcxApiClient($url, $credentials, $options); + $this->dcxApiClient = new DcxApiClient($url, $credentials, $options); } else { - $this->api_client = $override_client_class; + $this->dcxApiClient = $override_client_class; } - $this->publication_id = $this->config->get('publication'); + $this->publicationId = $this->config->get('publication'); } /** @@ -125,11 +125,11 @@ public function getJson($id, $params = NULL) { } $url = preg_replace('/^dcxapi:/', '', $id); - $http_status = $this->api_client->getObject($url, $params, $json); + $http_status = $this->dcxApiClient->get($url, $params, $json); if (200 !== $http_status) { - $exception = new DcxClientException('getObject', $http_status, $url, $params, $json); - $this->watchdog_exception(__METHOD__, $exception); + $exception = new DcxClientException('get', $http_status, $url, $params, $json); + $this->watchdogException(__METHOD__, $exception); throw $exception; } @@ -137,22 +137,7 @@ public function getJson($id, $params = NULL) { } /** - * Retrieve a DC-X object with the given id. - * - * Emits an HTTP request to the DC-X server and evaluates the response. - * Depending on the document "Type" (an attribute stored within the fields, - * not to be confused with the attribute "type") it returns subclasses of - * BaseAsset which encapsulate a flat array representation of the data - * retrieved. - * - * @param string $id - * A dcx object identifier. Something like "dcxapi:document/xyz". - * - * @return \Drupal\dcx_integration\Asset\BaseAsset - * An instance of BaseAsset depending on the retrieved data. - * - * @throws \Exception - * Throws exceptions if anything fails. + * {@inheritdoc} */ public function getObject($id) { $json = $this->getJson($id); @@ -170,7 +155,7 @@ public function getObject($id) { default: $exception = new UnknownDocumentTypeException($type, $id); - $this->watchdog_exception(__METHOD__, $exception); + $this->watchdogException(__METHOD__, $exception); throw $exception; } return $asset; @@ -179,12 +164,16 @@ public function getObject($id) { /** * Builds an Image object from given json array. * + * @param array $json + * Data array. + * * @return \Drupal\dcx_integration\Asset\Image * The Image object. + * + * @throws \Exception + * If it's not possible to create an asset. */ - protected function buildImageAsset($json) { - $data = []; - + protected function buildImageAsset(array $json) { /* * Maps an asset attribute to * - the keys of a nested array, or @@ -200,30 +189,32 @@ protected function buildImageAsset($json) { 'source' => [[$this, 'joinValues'], 'fields', 'Creator'], 'copyright' => ['fields', 'CopyrightNotice', 0, 'value'], 'status' => [[$this, 'computeStatus']], - // Deliberately disabled. See comment in ::computeExpire - // 'kill_date' => [[$this, 'computeExpire']],. ]; $data = $this->processAttributeMap($attribute_map, $json); try { - $asset = new Image($data); + return new Image($data); } catch (\Exception $e) { - $this->watchdog_exception(__METHOD__, $e); + $this->watchdogException(__METHOD__, $e); throw $e; } - return $asset; } /** * Builds an Article object from given json array. * + * @param array $json + * Data array. + * * @return \Drupal\dcx_integration\Asset\Article * The Article object. + * + * @throws \Exception + * If it's not possible to create an asset. */ - protected function buildArticleAsset($json) { - $data = []; + protected function buildArticleAsset(array $json) { $attribute_map = [ 'id' => ['_id'], @@ -235,14 +226,12 @@ protected function buildArticleAsset($json) { $data = $this->processAttributeMap($attribute_map, $json); try { - $asset = new Article($data); + return new Article($data); } catch (\Exception $e) { - $this->watchdog_exception(__METHOD__, $e); + $this->watchdogException(__METHOD__, $e); throw $e; } - return $asset; - } /** @@ -254,9 +243,15 @@ protected function buildArticleAsset($json) { * callable [object, method] pair, arguments for further processing in this * very callable. * - * @return array of extracted data + * @param array $attribute_map + * Array of attributes. + * @param array $source + * Data array. + * + * @return array + * Array of extracted data. */ - protected function processAttributeMap($attribute_map, $source) { + protected function processAttributeMap(array $attribute_map, array $source) { $data = []; foreach ($attribute_map as $target_key => $source_keys) { @@ -273,16 +268,19 @@ protected function processAttributeMap($attribute_map, $source) { } /** - * Descends in the nested array $json following the path of keys given in keys. + * Descends in the array $json following the path of keys given in keys. * * Returns whatever it finds there. * - * @param array $keys * @param array $json + * Data array. + * @param array $keys + * Keys to look for. * - * @return mixed $value + * @return mixed + * Value of an asset. */ - protected function extractData($json, $keys) { + protected function extractData(array $json, array $keys) { foreach ($keys as $key) { $json = !empty($json[$key]) ? $json[$key] : ''; } @@ -294,13 +292,15 @@ protected function extractData($json, $keys) { * * This function "knows" where to look for the URL of the file in question. * - * @param array $keys * @param array $json + * Data array. + * @param array $keys + * Keys to look for. * * @return string * URL referenced by the file_id nested in $keys. */ - protected function extractUrl($json, $keys) { + protected function extractUrl(array $json, array $keys) { $file_id = $this->extractData($json, $keys); $file_url = $this->extractData($json, [ @@ -318,36 +318,48 @@ protected function extractUrl($json, $keys) { * * This function "knows" where to look for the IDs in question. * - * @param array $keys * @param array $json + * Data array. + * @param array $keys + * Keys to look for. * - * @return array of image IDs + * @return array + * of image IDs */ - protected function extractImageIds($json, $keys) { + protected function extractImageIds(array $json, array $keys) { $data = $this->extractData($json, $keys); if (!$data) { - return; + return []; } + $images = []; foreach ($data as $image_data) { - $images[] = $this->extractData($image_data, ['fields', 'DocumentRef', 0, '_id']); + $images[] = $this->extractData($image_data, [ + 'fields', + 'DocumentRef', + 0, + '_id', + ]); } return $images; } /** - * Computes the (published) status of the image, evaluating the key - * '_rights_effective'. + * Computes the (published) status of the image. + * + * Evaluating the key '_rights_effective'. * - * Searches for a right with the topic_id 'dcxapi:tm_topic/rightsusage-UsagePermittedDigital'. + * Searches for a right with the topic_id + * 'dcxapi:tm_topic/rightsusage-UsagePermittedDigital'. * * @param array $json + * Data array. * * @return bool * The status of the image. True if a right with topic_id * 'dcxapi:tm_topic/rightsusage-Online' is present, false otherwise */ - protected function computeStatus($json) { + protected function computeStatus(array $json) { $rights_ids = $this->extractData($json, [ '_rights_effective', 'rightstype-UsagePermittedDigital', @@ -363,53 +375,19 @@ protected function computeStatus($json) { } /** - * Computes the expired of the image, evaluating the key - * '_rights_effective'. + * Returns comma separated string of values of the list referenced by $keys. * - * Searches for a right with the topic_id 'dcxapi:tm_topic/rightsusage-Online'. + * Use to collect the values of a multi values DC-X field. * * @param array $json - * - * @return string - * date string of expired date - */ - protected function computeExpire($json) { - // As it is implemented right now, this returns a DateTime instance - // representing the current date if no data is available in $json. - // It breaks sites using this. - $rights_ids = $this->extractData($json, [ - '_rights_effective', - 'rightstype-UsagePermitted', - ]); - foreach (current($rights_ids) as $right) { - $right_id = $right['_id']; - $dereferenced_right_id = $json['_referenced']['dcx:rights'][$right_id]['properties']['topic_id']['_id']; - if ('dcxapi:tm_topic/rightsusage-Online' == $dereferenced_right_id) { - if (isset($right['from_date']) && isset($right['to_date']) && empty($right['to_date'])) { - $date = new \DateTime($right['from_date']); - return $date->format('Y-m-d'); - } - if (isset($right['to_date'])) { - $date = new \DateTime($right['to_date']); - return $date->format('Y-m-d'); - } - return NULL; - } - } - return FALSE; - } - - /** - * Returns a comma separated string of the values of the list referenced by - * $keys. Use to collect the values of a multi values DC-X field. - * + * Data array. * @param array $keys - * @param array $json + * Keys to look for. * * @return string * The referenced values as comma separated string. */ - protected function joinValues($json, $keys) { + protected function joinValues(array $json, array $keys) { $items = $this->extractData($json, $keys); $values = []; @@ -423,14 +401,14 @@ protected function joinValues($json, $keys) { /** * {@inheritdoc} */ - public function trackUsage($used_entities, $path, $published, $type) { + public function trackUsage(array $used_entities, $path, $published, $type) { $dcx_status = $published ? 'pubstatus-published' : 'pubstatus-unpublished'; $dateTime = new \DateTime(); $date = $dateTime->format(\DateTime::W3C); - $dcx_publication = $this->publication_id; + $dcx_publication = $this->publicationId; $known_publications = $this->pubinfoOnPath($path, $type); @@ -488,10 +466,10 @@ public function trackUsage($used_entities, $path, $published, $type) { } $response_body = NULL; if (0 == count($pubinfo)) { - $http_status = $this->api_client->createObject('pubinfo', [], $data, $response_body); + $http_status = $this->dcxApiClient->createObject('pubinfo', [], $data, $response_body); if (201 !== $http_status) { $exception = new DcxClientException('createObject', $http_status, 'pubinfo', [], $data); - $this->watchdog_exception(__METHOD__, $exception); + $this->watchdogException(__METHOD__, $exception); throw $exception; } } @@ -504,10 +482,10 @@ public function trackUsage($used_entities, $path, $published, $type) { $data['properties']['_modcount'] = $modcount; $data['_id'] = $pubinfo['_id']; - $http_status = $this->api_client->setObject($dcx_api_url, [], $data, $response_body); + $http_status = $this->dcxApiClient->setObject($dcx_api_url, [], $data, $response_body); if (200 !== $http_status) { $exception = new DcxClientException('createObject', $http_status, $dcx_api_url, [], $data); - $this->watchdog_exception(__METHOD__, $exception); + $this->watchdogException(__METHOD__, $exception); throw $exception; } } @@ -517,7 +495,7 @@ public function trackUsage($used_entities, $path, $published, $type) { /** * {@inheritdoc} */ - public function archiveArticle($url, $info, $dcx_id) { + public function archiveArticle($url, array $info, $dcx_id) { $title = isset($info['title']) ? $info['title'] : ''; $status = isset($info['status']) ? $info['status'] : FALSE; @@ -605,11 +583,11 @@ public function archiveArticle($url, $info, $dcx_id) { $data['properties']['_modcount'] = $modcount; $data['_id'] = '/dcx/api/' . $dcx_id; $dcx_api_url = $dcx_id; - $http_status = $this->api_client->setObject($dcx_api_url, [], $data, $response_body); + $http_status = $this->dcxApiClient->setObject($dcx_api_url, [], $data, $response_body); } else { $dcx_api_url = 'document'; - $http_status = $this->api_client->createObject($dcx_api_url, [], $data, $response_body); + $http_status = $this->dcxApiClient->createObject($dcx_api_url, [], $data, $response_body); } $error = FALSE; @@ -652,7 +630,7 @@ public function archiveArticle($url, $info, $dcx_id) { if ($error) { $exception = new DcxClientException('createObject|setObject', $http_status, $dcx_api_url, [], $data, sprintf('Unable to archive: %s', $message)); - $this->watchdog_exception(__METHOD__, $exception); + $this->watchdogException(__METHOD__, $exception); throw $exception; } @@ -673,17 +651,17 @@ public function pubinfoOnPath($path, $type) { 'q[type_id]' => "pubtype-$type", ]; - $http_status = $this->api_client->getObject('pubinfo', $params, $json); + $http_status = $this->dcxApiClient->get('pubinfo', $params, $json); if (200 !== $http_status) { - $exception = new DcxClientException('getObject', $http_status, 'pubinfo', $params, $json); - $this->watchdog_exception(__METHOD__, $exception); + $exception = new DcxClientException('get', $http_status, 'pubinfo', $params, $json); + $this->watchdogException(__METHOD__, $exception); throw $exception; } $pubinfo = []; foreach ($json['entries'] as $entry) { // Ignore entry, if the publication id of this entry does not match ours. - if ("dcxapi:tm_topic/" . $this->publication_id !== $entry['properties']['publication_id']['_id']) { + if ("dcxapi:tm_topic/" . $this->publicationId !== $entry['properties']['publication_id']['_id']) { continue; } $doc_id = $entry['properties']['doc_id']['_id']; @@ -704,14 +682,14 @@ public function pubinfoOnPath($path, $type) { * * @throws \Exception */ - protected function removePubinfos($pubinfos) { + protected function removePubinfos(array $pubinfos) { $response_body = 'we know we wont evaluate this ;)'; foreach ($pubinfos as $data) { $dcx_api_url = $data['_id_url']; - $http_status = $this->api_client->deleteObject($dcx_api_url, [], $response_body); + $http_status = $this->dcxApiClient->deleteObject($dcx_api_url, [], $response_body); if (204 != $http_status) { $exception = new DcxClientException('deleteObject', $http_status, $dcx_api_url); - $this->watchdog_exception(__METHOD__, $exception); + $this->watchdogException(__METHOD__, $exception); throw $exception; } } @@ -739,6 +717,7 @@ public function removeAllUsage($dcx_id) { /** * Retrieve all usage information about the given DC-X ID on the current site. + * * May be filtered by a certain entity (say media:image) instance. * * @param string $dcx_id @@ -747,6 +726,9 @@ public function removeAllUsage($dcx_id) { * Entity type of the entity representing the dcx_id. * @param int $entity_id * Entity id of the entity representing the dcx_id. + * + * @return array + * Usages of an document. */ protected function getAllUsage($dcx_id, $entity_type = NULL, $entity_id = NULL) { $document = $this->getJson($dcx_id); @@ -754,16 +736,17 @@ protected function getAllUsage($dcx_id, $entity_type = NULL, $entity_id = NULL) $selected_pubinfos = []; foreach ($pubinfos as $key => $pubinfo) { - if ("dcxapi:tm_topic/" . $this->publication_id === $pubinfo['properties']['publication_id']['_id']) { + if ("dcxapi:tm_topic/" . $this->publicationId === $pubinfo['properties']['publication_id']['_id']) { // If either type or id is not set, find all. if (!$entity_type || !$entity_id) { $selected_pubinfos[$pubinfo['properties']['uri']] = $pubinfo; } // If pubinfo contains type and id both equal to the given one, find it. elseif (isset($pubinfo['info']['entity_type']) - && isset($pubinfo['info']['entity_id']) - && $pubinfo['info']['entity_type'] == $entity_type - && $pubinfo['info']['entity_id'] == $entity_id) { + && isset($pubinfo['info']['entity_id']) + && $pubinfo['info']['entity_type'] == $entity_type + && $pubinfo['info']['entity_id'] == $entity_id + ) { $selected_pubinfos[$pubinfo['properties']['uri']] = $pubinfo; } } @@ -777,7 +760,7 @@ protected function getAllUsage($dcx_id, $entity_type = NULL, $entity_id = NULL) * * Global watchdog_exception is not unit testable. :( This method is. */ - protected function watchdog_exception($type, \Exception $exception, $message = NULL, $variables = [], $severity = RfcLogLevel::ERROR, $link = NULL) { + protected function watchdogException($type, \Exception $exception, $message = NULL, $variables = [], $severity = RfcLogLevel::ERROR, $link = NULL) { if (empty($message)) { $message = '%type: @message in %function (line %line of %file).'; } @@ -808,7 +791,7 @@ public function getCollections() { ], ]; - $this->api_client->getObject('usertag', $params, $usertags); + $this->dcxApiClient->get('usertag', $params, $usertags); $collections = []; foreach ($usertags['entries'] as $usertag) { @@ -839,7 +822,13 @@ public function getCollections() { } /** + * Retrieve all docs of a collection. + * + * @param string $utag_id + * Id of a collection. * + * @return array + * Documents of the given collection. */ public function getDocsOfCollection($utag_id) { $doctoutag_params = [ @@ -848,7 +837,7 @@ public function getDocsOfCollection($utag_id) { 's[_referenced][dcx:document][s][files]' => '*', ]; - $this->api_client->getObject('doctoutag', $doctoutag_params, $docs); + $this->dcxApiClient->get('doctoutag', $doctoutag_params, $docs); $documents = []; @@ -874,15 +863,21 @@ public function getPreview($id) { ]; $url = preg_replace('/^dcxapi:/', '', $id); - $http_status = $this->api_client->getObject($url, $params, $json); + $http_status = $this->dcxApiClient->get($url, $params, $json); if (200 !== $http_status) { - $exception = new DcxClientException('getObject', $http_status, $url, $params, $json); - $this->watchdog_exception(__METHOD__, $exception); + $exception = new DcxClientException('get', $http_status, $url, $params, $json); + $this->watchdogException(__METHOD__, $exception); throw $exception; } - $variant_types = $this->processAttributeMap(['variants' => ['_files_index', 'variant_type', 'master']], $json); + $variant_types = $this->processAttributeMap([ + 'variants' => [ + '_files_index', + 'variant_type', + 'master', + ], + ], $json); $thumb_id = $variant_types['variants']['thumbnail'];