ArrayableConverter   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 16
ccs 3
cts 3
cp 1
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A convert() 0 5 1
1
<?php
2
declare(strict_types=1);
3
4
namespace MarcinOrlowski\ResponseBuilder\Converters;
5
6
/**
7
 * Laravel API Response Builder
8
 *
9
 * @package   MarcinOrlowski\ResponseBuilder
10
 *
11
 * @author    Marcin Orlowski <mail (#) marcinOrlowski (.) com>
12
 * @copyright 2016-2021 Marcin Orlowski
13
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
14
 * @link      https://github.com/MarcinOrlowski/laravel-api-response-builder
15
 */
16
17
use Illuminate\Contracts\Support\Arrayable;
18
use MarcinOrlowski\ResponseBuilder\Contracts\ConverterContract;
19
use MarcinOrlowski\ResponseBuilder\Validator;
20
21
/**
22
 * Converter for Arrayable class type of objects.
23
 */
24
final class ArrayableConverter implements ConverterContract
25
{
26
	/**
27
	 * Returns array representation of the object implementing Arrayable interface
28
	 *
29
	 * @param Arrayable $obj    Object to be converted
30
	 * @param array     $config Converter config array to be used for this object (based on exact class
31 1
	 *                          name match or inheritance).
32
	 *
33 1
	 * @return array
34
	 */
35 1
	public function convert(object $obj, /** @scrutinizer ignore-unused */ array $config): array
36
	{
37
		Validator::assertInstanceOf('obj', $obj, Arrayable::class);
38
39
		return $obj->toArray();
40
	}
41
}
42