Issues (109)

src/EoC/Doc/Doc.php (1 issue)

1
<?php
2
3
/**
4
 * @file Doc.php
5
 * @brief This file contains the Doc class.
6
 * @details
7
 * @author Filippo F. Fadda
8
 */
9
10
11
namespace EoC\Doc;
12
13
14
use EoC\Doc\Attachment\Attachment;
15
16
17
/**
18
 * @brief Standard documents are replicable documents.
19
 * @nosubgrouping
20
 */
21
class Doc extends AbstractDoc {
22
  const ATTACHMENTS = "_attachments";
23
  const REVS_INFO = "_revs_info";
24
  const CONFLICTS = "_conflicts";
25
  const DELETED_CONFLICTS = "_deleted_conflicts";
26
  const LOCAL_SEQUENCE = "_local_seq";
27
28
29
  protected function fixDocId() {}
30
31
32
  /**
33
   * @brief Standard documents path is null.
34
   * @retval string An empty string.
35
   */
36
  public function getPath() {
37
    return "";
38
  }
39
40
41
  /**
42
   * @brief
43
   * @todo To be documented.
44
   */
45
  public function getAttachments() {
46
    $attachments = [];
47
48
    foreach ($this->meta[self::ATTACHMENTS] as $attachment)
49
      $attachments[] = Attachment::fromArray($attachment);
50
51
    return $attachments;
52
  }
53
54
55
  /**
56
   * @brief Adds an attachment.
57
   */
58
  public function addAttachment(Attachment $attachment) {
59
    $this->meta[self::ATTACHMENTS][$attachment->getName()] = $attachment->asArray();
60
  }
61
62
63
  /**
64
   * @brief Removes an attachment.
65
   */
66
  public function removeAttachment($name) {
67
    if ($this->isMetadataPresent(self::ATTACHMENTS))
68
      if (array_key_exists($name, $this->meta[self::ATTACHMENTS]))
69
        unset($this->meta[self::ATTACHMENTS][$name]);
70
      else
71
        throw new \Exception("Can't find `$name` attachment in the document.");
72
    else
73
      throw new \Exception("The document doesn't have any attachment.");
74
  }
75
76
77
  //! @cond HIDDEN_SYMBOLS
78
79
  /**
80
   * @brief Returns the `_local_seq` number.
81
   */
82
  public function getLocalSequence() {
83
    return $this->meta[self::LOCAL_SEQUENCE];
84
  }
85
86
87
  /**
88
   * @brief Returns `true` is the `_local_sequence` number is present, `false` otherwise.
89
   */
90
  public function issetLocalSequence() {
91
    return $this->isMetadataPresent(self::LOCAL_SEQUENCE);
92
  }
93
94
  //! @endcond
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
95
96
}