Code Duplication    Length = 19-19 lines in 3 locations

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

@@ 211-229 (lines=19) @@
208
		}
209
	}
210
211
	public function get($var, $tableName = null) {
212
		if ($tableName === null) {
213
			if (count($this->dbRows) > 1) {
214
				throw new TDBMException('This object is based on several tables. You must specify which table you are retrieving data from.');
215
			} elseif (count($this->dbRows) === 1) {
216
				$tableName = array_keys($this->dbRows)[0];
217
			}
218
		}
219
220
		if (!isset($this->dbRows[$tableName])) {
221
			if (count($this->dbRows[$tableName] === 0)) {
222
				throw new TDBMException('Object is not yet bound to any table.');
223
			} else {
224
				throw new TDBMException('Unknown table "'.$tableName.'"" in object.');
225
			}
226
		}
227
228
		return $this->dbRows[$tableName]->get($var);
229
	}
230
231
	/**
232
	 * Returns true if a column is set, false otherwise.
@@ 237-255 (lines=19) @@
234
	 * @param string $var
235
	 * @return boolean
236
	 */
237
	public function has($var, $tableName = null) {
238
		if ($tableName === null) {
239
			if (count($this->dbRows) > 1) {
240
				throw new TDBMException('This object is based on several tables. You must specify which table you are retrieving data from.');
241
			} elseif (count($this->dbRows) === 1) {
242
				$tableName = array_keys($this->dbRows)[0];
243
			}
244
		}
245
246
		if (!isset($this->dbRows[$tableName])) {
247
			if (count($this->dbRows[$tableName] === 0)) {
248
				throw new TDBMException('Object is not yet bound to any table.');
249
			} else {
250
				throw new TDBMException('Unknown table "'.$tableName.'"" in object.');
251
			}
252
		}
253
254
		return $this->dbRows[$tableName]->has($var);
255
	}
256
	
257
	public function set($var, $value, $tableName = null) {
258
		if ($tableName === null) {
@@ 307-325 (lines=19) @@
304
	 * @param string $foreignKeyName A unique name for this reference
305
	 * @return AbstractTDBMObject|null
306
	 */
307
	public function getRef($foreignKeyName, $tableName = null) {
308
		if ($tableName === null) {
309
			if (count($this->dbRows) > 1) {
310
				throw new TDBMException('This object is based on several tables. You must specify which table you are retrieving data from.');
311
			} elseif (count($this->dbRows) === 1) {
312
				$tableName = array_keys($this->dbRows)[0];
313
			}
314
		}
315
316
		if (!isset($this->dbRows[$tableName])) {
317
			if (count($this->dbRows[$tableName] === 0)) {
318
				throw new TDBMException('Object is not yet bound to any table.');
319
			} else {
320
				throw new TDBMException('Unknown table "'.$tableName.'"" in object.');
321
			}
322
		}
323
324
		return $this->dbRows[$tableName]->getRef($foreignKeyName);
325
	}
326
327
	/**
328
	 * Adds a many to many relationship to this bean.