Code Duplication    Length = 19-19 lines in 3 locations

src/Mouf/Database/TDBM/AbstractTDBMObject.php 3 locations

@@ 171-189 (lines=19) @@
168
		}
169
	}
170
171
	public function get($var, $tableName = null) {
172
		if ($tableName === null) {
173
			if (count($this->dbRows) > 1) {
174
				throw new TDBMException('This object is based on several tables. You must specify which table you are retrieving data from.');
175
			} elseif (count($this->dbRows) === 1) {
176
				$tableName = array_keys($this->dbRows)[0];
177
			}
178
		}
179
180
		if (!isset($this->dbRows[$tableName])) {
181
			if (count($this->dbRows[$tableName] === 0)) {
182
				throw new TDBMException('Object is not yet bound to any table.');
183
			} else {
184
				throw new TDBMException('Unknown table "'.$tableName.'"" in object.');
185
			}
186
		}
187
188
		return $this->dbRows[$tableName]->get($var);
189
	}
190
191
	/**
192
	 * Returns true if a column is set, false otherwise.
@@ 197-215 (lines=19) @@
194
	 * @param string $var
195
	 * @return boolean
196
	 */
197
	public function has($var, $tableName = null) {
198
		if ($tableName === null) {
199
			if (count($this->dbRows) > 1) {
200
				throw new TDBMException('This object is based on several tables. You must specify which table you are retrieving data from.');
201
			} elseif (count($this->dbRows) === 1) {
202
				$tableName = array_keys($this->dbRows)[0];
203
			}
204
		}
205
206
		if (!isset($this->dbRows[$tableName])) {
207
			if (count($this->dbRows[$tableName] === 0)) {
208
				throw new TDBMException('Object is not yet bound to any table.');
209
			} else {
210
				throw new TDBMException('Unknown table "'.$tableName.'"" in object.');
211
			}
212
		}
213
214
		return $this->dbRows[$tableName]->has($var);
215
	}
216
	
217
	public function set($var, $value, $tableName = null) {
218
		if ($tableName === null) {
@@ 267-285 (lines=19) @@
264
	 * @param string $foreignKeyName A unique name for this reference
265
	 * @return AbstractTDBMObject|null
266
	 */
267
	public function getRef($foreignKeyName, $tableName = null) {
268
		if ($tableName === null) {
269
			if (count($this->dbRows) > 1) {
270
				throw new TDBMException('This object is based on several tables. You must specify which table you are retrieving data from.');
271
			} elseif (count($this->dbRows) === 1) {
272
				$tableName = array_keys($this->dbRows)[0];
273
			}
274
		}
275
276
		if (!isset($this->dbRows[$tableName])) {
277
			if (count($this->dbRows[$tableName] === 0)) {
278
				throw new TDBMException('Object is not yet bound to any table.');
279
			} else {
280
				throw new TDBMException('Unknown table "'.$tableName.'"" in object.');
281
			}
282
		}
283
284
		return $this->dbRows[$tableName]->getRef($foreignKeyName);
285
	}
286
287
	/**
288
	 * Adds a many to many relationship to this bean.