Code Duplication    Length = 41-41 lines in 2 locations

src/PropertiesHandler.php 2 locations

@@ 229-269 (lines=41) @@
226
     * @throws BadMethodCallException If custom prefix is not an ``string`` instance.
227
     * @see ICustomPrefixedPropertiesContainer::getCustomSetterPrefix()
228
     */
229
    protected static function getPropertySetter($name)
230
    {
231
        $args = [
232
            'class' => get_called_class(),
233
        ];
234
235
        $prefix = 'set';
236
237
        $args['name'] = static::ensurePropertyExists($name, $args['class']);
238
239
        try {
240
            $setter = static::ensureMethodExists($prefix.$args['name']);
241
        } catch (InvalidArgumentException $error) {
242
            $msg = msg('"{name}" property has not a setter method in "{class}".', $args);
243
244
            if (is_subclass_of($args['class'], ICustomPrefixedPropertiesContainer::class)) {
245
                // If not available standard setter, check if custom available
246
                try {
247
                    $prefix = Text::ensureIsString(static::getCustomSetterPrefix());
248
                } catch (InvalidArgumentException $e) {
249
                    $msg = msg(
250
                        '"{class}::getCustomSetterPrefix" method must to return an string.',
251
                        $args['class']
252
                    );
253
254
                    throw new BadMethodCallException($msg, 31, $e);
255
                }
256
257
                try {
258
                    $setter = static::ensureMethodExists($prefix.$args['name']);
259
                } catch (InvalidArgumentException $e) {
260
                    throw new InvalidArgumentException($msg, 32, $e);
261
                }
262
            } else {
263
                // Error for non custom prefixes
264
                throw new InvalidArgumentException($msg, 30, $error);
265
            }
266
        }
267
268
        return $setter;
269
    }
270
271
272
    /**
@@ 283-323 (lines=41) @@
280
     * @throws BadMethodCallException If custom prefix is not an ``string`` instance.
281
     * @see ICustomPrefixedPropertiesContainer::getCustomGetterPrefix()
282
     */
283
    protected static function getPropertyGetter($name)
284
    {
285
        $args = [
286
            'class' => get_called_class(),
287
        ];
288
289
        $prefix = 'get';
290
291
        $args['name'] = static::ensurePropertyExists($name, $args['class']);
292
293
        try {
294
            $getter = static::ensureMethodExists($prefix.$args['name']);
295
        } catch (InvalidArgumentException $error) {
296
            $msg = msg('"{name}" property has not a getter method in "{class}".', $args);
297
298
            if (is_subclass_of($args['class'], ICustomPrefixedPropertiesContainer::class)) {
299
                // If not available standard getter, check if custom available
300
                try {
301
                    $prefix = Text::ensureIsString(static::getCustomGetterPrefix());
302
                } catch (InvalidArgumentException $e) {
303
                    $msg = msg(
304
                        '"{class}::getCustomGetterPrefix" method must to return an string.',
305
                        $args['class']
306
                    );
307
308
                    throw new BadMethodCallException($msg, 31, $e);
309
                }
310
311
                try {
312
                    $getter = static::ensureMethodExists($prefix.$args['name']);
313
                } catch (InvalidArgumentException $e) {
314
                    throw new InvalidArgumentException($msg, 32, $e);
315
                }
316
            } else {
317
                // Error for non custom prefixes
318
                throw new InvalidArgumentException($msg, 30, $error);
319
            }
320
        }
321
322
        return $getter;
323
    }
324
}
325