Code Duplication    Length = 12-12 lines in 5 locations

src/AbstractActiveRecord.php 5 locations

@@ 104-115 (lines=12) @@
101
	 * @param string $columnName The name of the column that is registered.
102
	 * @param string|callable $fn Either a callable, or the name of a method on the inheriting object.
103
	 */
104
	public function registerCreateHook($columnName, $fn)
105
	{
106
		$this->checkHookConstraints($columnName, $this->registeredCreateHooks);
107
108
		if (is_string($fn) && is_callable([$this, $fn])) {
109
			$this->registeredCreateHooks[$columnName] = [$this, $fn];
110
		} else if (is_callable($fn)) {
111
			$this->registeredCreateHooks[$columnName] = $fn;
112
		} else {
113
			throw new ActiveRecordException("Provided hook on column \"$columnName\" is not callable", 0);
114
		}
115
	}
116
117
	/**
118
	 * Register a new hook for a specific column that gets called before execution of the read() method
@@ 123-134 (lines=12) @@
120
	 * @param string $columnName The name of the column that is registered.
121
	 * @param string|callable $fn Either a callable, or the name of a method on the inheriting object.
122
	 */
123
	public function registerReadHook($columnName, $fn)
124
	{
125
		$this->checkHookConstraints($columnName, $this->registeredReadHooks);
126
127
		if (is_string($fn) && is_callable([$this, $fn])) {
128
			$this->registeredReadHooks[$columnName] = [$this, $fn];
129
		} else if (is_callable($fn)) {
130
			$this->registeredReadHooks[$columnName] = $fn;
131
		} else {
132
			throw new ActiveRecordException("Provided hook on column \"$columnName\" is not callable", 0);
133
		}
134
	}
135
136
137
@@ 145-156 (lines=12) @@
142
	 * @param string $columnName The name of the column that is registered.
143
	 * @param string|callable $fn Either a callable, or the name of a method on the inheriting object.
144
	 */
145
	public function registerUpdateHook($columnName, $fn)
146
	{
147
		$this->checkHookConstraints($columnName, $this->registeredUpdateHooks);
148
149
		if (is_string($fn) && is_callable([$this, $fn])) {
150
			$this->registeredUpdateHooks[$columnName] = [$this, $fn];
151
		} else if (is_callable($fn)) {
152
			$this->registeredUpdateHooks[$columnName] = $fn;
153
		} else {
154
			throw new ActiveRecordException("Provided hook on column \"$columnName\" is not callable", 0);
155
		}
156
	}
157
158
	/**
159
	 * Register a new hook for a specific column that gets called before execution of the delete() method
@@ 164-175 (lines=12) @@
161
	 * @param string $columnName The name of the column that is registered.
162
	 * @param string|callable $fn Either a callable, or the name of a method on the inheriting object.
163
	 */
164
	public function registerDeleteHook($columnName, $fn)
165
	{
166
		$this->checkHookConstraints($columnName, $this->registeredDeleteHooks);
167
168
		if (is_string($fn) && is_callable([$this, $fn])) {
169
			$this->registeredDeleteHooks[$columnName] = [$this, $fn];
170
		} else if (is_callable($fn)) {
171
			$this->registeredDeleteHooks[$columnName] = $fn;
172
		} else {
173
			throw new ActiveRecordException("Provided hook on column \"$columnName\" is not callable", 0);
174
		}
175
	}
176
177
	/**
178
	 * Register a new hook for a specific column that gets called before execution of the search() method
@@ 183-194 (lines=12) @@
180
	 * @param string $columnName The name of the column that is registered.
181
	 * @param string|callable $fn Either a callable, or the name of a method on the inheriting object. The callable is required to take one argument: an instance of miBadger\Query\Query; 
182
	 */
183
	public function registerSearchHook($columnName, $fn)
184
	{
185
		$this->checkHookConstraints($columnName, $this->registeredSearchHooks);
186
187
		if (is_string($fn) && is_callable([$this, $fn])) {
188
			$this->registeredSearchHooks[$columnName] = [$this, $fn];
189
		} else if (is_callable($fn)) {
190
			$this->registeredSearchHooks[$columnName] = $fn;
191
		} else {
192
			throw new ActiveRecordException("Provided hook on column \"$columnName\" is not callable", 0);
193
		}
194
	}
195
196
	/**
197
	 * Adds a new column definition to the table.