Code Duplication    Length = 31-31 lines in 2 locations

engine/classes/ElggGroup.php 1 location

@@ 56-86 (lines=31) @@
53
	 *
54
	 * @throws IOException|InvalidParameterException if there was a problem creating the group.
55
	 */
56
	public function __construct($row = null) {
57
		$this->initializeAttributes();
58
59
		// compatibility for 1.7 api.
60
		$this->initialise_attributes(false);
61
62
		if (!empty($row)) {
63
			// Is $guid is a entity table DB row
64
			if ($row instanceof \stdClass) {
65
				// Load the rest
66
				if (!$this->load($row)) {
67
					$msg = "Failed to load new " . get_class() . " for GUID:" . $row->guid;
68
					throw new \IOException($msg);
69
				}
70
			} else if ($row instanceof \ElggGroup) {
71
				// $row is an \ElggGroup so this is a copy constructor
72
				elgg_deprecated_notice('This type of usage of the \ElggGroup constructor was deprecated. Please use the clone method.', 1.7);
73
				foreach ($row->attributes as $key => $value) {
74
					$this->attributes[$key] = $value;
75
				}
76
			} else if (is_numeric($row)) {
77
				// $row is a GUID so load entity
78
				elgg_deprecated_notice('Passing a GUID to constructor is deprecated. Use get_entity()', 1.9);
79
				if (!$this->load($row)) {
80
					throw new \IOException("Failed to load new " . get_class() . " from GUID:" . $row);
81
				}
82
			} else {
83
				throw new \InvalidParameterException("Unrecognized value passed to constuctor.");
84
			}
85
		}
86
	}
87
88
	/**
89
	 * {@inheritdoc}

engine/classes/ElggObject.php 1 location

@@ 68-98 (lines=31) @@
65
	 * @throws IOException If cannot load remaining data from db
66
	 * @throws InvalidParameterException If not passed a db row result
67
	 */
68
	public function __construct($row = null) {
69
		$this->initializeAttributes();
70
71
		// compatibility for 1.7 api.
72
		$this->initialise_attributes(false);
73
74
		if (!empty($row)) {
75
			// Is $row is a DB row from the entity table
76
			if ($row instanceof \stdClass) {
77
				// Load the rest
78
				if (!$this->load($row)) {
79
					$msg = "Failed to load new " . get_class() . " for GUID: " . $row->guid;
80
					throw new \IOException($msg);
81
				}
82
			} else if ($row instanceof \ElggObject) {
83
				// $row is an \ElggObject so this is a copy constructor
84
				elgg_deprecated_notice('This type of usage of the \ElggObject constructor was deprecated. Please use the clone method.', 1.7);
85
				foreach ($row->attributes as $key => $value) {
86
					$this->attributes[$key] = $value;
87
				}
88
			} else if (is_numeric($row)) {
89
				// $row is a GUID so load
90
				elgg_deprecated_notice('Passing a GUID to constructor is deprecated. Use get_entity()', 1.9);
91
				if (!$this->load($row)) {
92
					throw new \IOException("Failed to load new " . get_class() . " from GUID:" . $row);
93
				}
94
			} else {
95
				throw new \InvalidParameterException("Unrecognized value passed to constuctor.");
96
			}
97
		}
98
	}
99
100
	/**
101
	 * Loads the full \ElggObject when given a guid.