Skip to content

Commit

Permalink
More CS fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrfritsch committed Jun 30, 2017
1 parent 5680a96 commit 878e74d
Show file tree
Hide file tree
Showing 11 changed files with 175 additions and 156 deletions.
8 changes: 4 additions & 4 deletions src/Asset/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];

Expand All @@ -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);
}

}
11 changes: 8 additions & 3 deletions src/Asset/BaseAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/Asset/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
* @package Drupal\dcx_integration\Asset
*/
class Image extends BaseAsset {
static $mandatory_attributes = [
protected static $mandatoryAttributes = [
'id',
'filename',
'title',
'url',
'status',
];

static $optional_attributes = [
protected static $optionalAttributes = [
'creditor',
'copyright',
'fotocredit',
Expand All @@ -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);
}

}
35 changes: 27 additions & 8 deletions src/ClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -82,24 +97,28 @@ 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();

/**
* 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.
*
Expand Down
12 changes: 6 additions & 6 deletions src/Controller/DcxDebugController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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 :(");
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/DcxClientException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/IllegalAssetTypeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/IllegalAttributeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class IllegalAttributeException extends \Exception {

/**
*
* Constructs IllegalAttributeException.
*/
public function __construct($attribute) {
$message = sprintf("Attribute %s is not allowed", $attribute);
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/MandatoryAttributeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class MandatoryAttributeException extends \Exception {
public $attribute;

/**
*
* Constructs MandatoryAttributeException.
*/
public function __construct($attribute) {
$message = sprintf("Attribute '%s' is mandatory", $attribute);
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/UnknownDocumentTypeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 878e74d

Please sign in to comment.