Issues (109)

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

1
<?php
2
3
/**
4
 * @file AbstractDoc.php
5
 * @brief This file contains the AbstractDoc class.
6
 * @details
7
 * @author Filippo F. Fadda
8
 */
9
10
11
//! The CouchDB's documents namespace
12
namespace EoC\Doc;
13
14
15
use Meta\MetaClass;
16
17
18
/**
19
 * @brief The abstract document is the ancestor of the other document classes.
20
 * @details This class encapsulates common properties and methods to provide persistence. Since it's an abstract class,
21
 * you can't create an instance of it.\n
22
 * You should instead inherit your persistent classes from the abstract Doc or LocalDoc (in case of local documents).
23
 * @attention Don't inherit from this superclass!
24
 * @nosubgrouping
25
 *
26
 * @cond HIDDEN_SYMBOLS
27
 *
28
 * @property string $id;
29
 * @property string $rev;
30
 *
31
 * @endcond
32
 */
33
abstract class AbstractDoc extends MetaClass implements IDoc {
34
35
36
  /**
37
   * @brief Removes tha path from the document identifier, because CouchDB returns it for local and design documents.
38
   * @details Both LocalDoc and DesignDoc override this method.
39
   */
40
  abstract protected function fixDocId();
41
42
43
  /**
44
   * @brief Sets the object class.
45
   * @param[in] string $value The instance class.
46
   */
47
  public function setClass($value) {
48
    $this->meta['class'] = $value;
49
  }
50
51
52
  /**
53
   * @copydoc IDoc::setType()
54
   */
55
  public function setType($value) {
56
    $this->meta['type'] = $value;
57
  }
58
59
60
  /**
61
   * @brief Returns the object type.
62
   * @retval string
63
   */
64
  public function getType() {
65
    return $this->meta['type'];
66
  }
67
68
69
  /**
70
   * @copydoc IDoc::hasType()
71
   */
72
  public function hasType() {
73
    return FALSE;
74
  }
75
76
77
  /**
78
   * @copydoc IDoc::getPath()
79
   */
80
  abstract public function getPath();
81
82
83
  public function assignJson($json) {
84
    parent::assignJson($json);
85
    $this->fixDocId();
86
  }
87
88
89
  public function assignArray(array $array) {
90
    parent::assignArray($array);
91
    $this->fixDocId();
92
  }
93
94
95
  public function assignObject(\stdClass $object) {
96
    parent::assignObject($object);
97
    $this->fixDocId();
98
  }
99
100
101
  /**
102
   * @brief Marks the document as deleted. To be effected the document must be saved.
103
   */
104
  public function delete() {
105
    $this->meta['_deleted'] = TRUE;
106
  }
107
108
109
  /**
110
   * @brief Indicates that this document has been deleted and previous revisions will be removed on next compaction run.
111
   */
112
  public function isDeleted() {
113
    return $this->meta['_deleted'];
114
  }
115
116
117
  /**
118
   * @brief Gets the document revisions.
119
   */
120
  public function getRevisions() {
121
    return (array_key_exists('_revisions', $this->meta)) ? $this->meta['_revisions'] : NULL;
122
  }
123
124
125
  //! @cond HIDDEN_SYMBOLS
126
127
  public function getId() {
128
    return $this->meta['_id'];
129
  }
130
131
132
  public function issetId() {
133
    return isset($this->meta['_id']);
134
  }
135
136
137
  public function setId($value) {
138
    $this->meta['_id'] = (string)$value;
139
  }
140
141
142
  public function unsetId() {
143
    if ($this->isMetadataPresent('_id'))
144
      unset($this->meta['_id']);
145
  }
146
147
148
  public function getRev() {
149
    return $this->meta['_rev'];
150
  }
151
152
153
  public function issetRev() {
154
    return isset($this->meta['_rev']);
155
  }
156
157
158
  public function setRev($value) {
159
    $this->meta['_rev'] = (string)$value;
160
  }
161
162
163
  public function unsetRev() {
164
    if ($this->isMetadataPresent('_rev'))
165
      unset($this->meta['_rev']);
166
  }
167
168
  //! @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...
169
170
}