Code Duplication    Length = 89-89 lines in 2 locations

src/Converter/MutationFieldConverter.php 1 location

@@ 11-99 (lines=89) @@
8
use Portiny\GraphQL\Contract\Mutation\MutationFieldInterface;
9
10
11
class MutationFieldConverter
12
{
13
14
	public static function toArray(MutationFieldInterface $mutationField): array
15
	{
16
		return [
17
			$mutationField->getName() => [
18
				'type' => $mutationField->getType(),
19
				'description' => $mutationField->getDescription(),
20
				'args' => $mutationField->getArgs(),
21
				'resolve' => function ($root, $args, $context) use ($mutationField) {
22
					return call_user_func_array([$mutationField, 'resolve'], [$root, $args, $context]);
23
				}
24
			]
25
		];
26
	}
27
28
29
	public static function toObject(array $data): MutationFieldInterface
30
	{
31
		return (new class ($data) implements MutationFieldInterface
32
		{
33
34
			/**
35
			 * @var string
36
			 */
37
			private $name;
38
39
			/**
40
			 * @var array
41
			 */
42
			private $data;
43
44
45
			public function __construct(array $data)
46
			{
47
				$this->name = key($data);
48
				$this->data = reset($data);
49
			}
50
51
52
			/**
53
			 * {@inheritdoc}
54
			 */
55
			public function getName(): string
56
			{
57
				return $this->name;
58
			}
59
60
61
			/**
62
			 * {@inheritdoc}
63
			 */
64
			public function getType(): Type
65
			{
66
				return $this->data['type'];
67
			}
68
69
70
			/**
71
			 * {@inheritdoc}
72
			 */
73
			public function getDescription(): string
74
			{
75
				return $this->data['description'];
76
			}
77
78
79
			/**
80
			 * {@inheritdoc}
81
			 */
82
			public function getArgs(): array
83
			{
84
				return $this->data['args'];
85
			}
86
87
88
			/**
89
			 * {@inheritdoc}
90
			 */
91
			public function resolve(array $root, array $args, $context = NULL)
92
			{
93
				return $this->data['resolve']($root, $args, $context);
94
			}
95
96
		});
97
	}
98
99
}
100

src/Converter/QueryFieldConverter.php 1 location

@@ 11-99 (lines=89) @@
8
use Portiny\GraphQL\Contract\Field\QueryFieldInterface;
9
10
11
final class QueryFieldConverter
12
{
13
14
	public static function toArray(QueryFieldInterface $queryField): array
15
	{
16
		return [
17
			$queryField->getName() => [
18
				'type' => $queryField->getType(),
19
				'description' => $queryField->getDescription(),
20
				'args' => $queryField->getArgs(),
21
				'resolve' => function ($root, $args, $context) use ($queryField) {
22
					return call_user_func_array([$queryField, 'resolve'], [$root, $args, $context]);
23
				}
24
			]
25
		];
26
	}
27
28
29
	public static function toObject(array $data): QueryFieldInterface
30
	{
31
		return (new class ($data) implements QueryFieldInterface
32
		{
33
34
			/**
35
			 * @var string
36
			 */
37
			private $name;
38
39
			/**
40
			 * @var array
41
			 */
42
			private $data;
43
44
45
			public function __construct(array $data)
46
			{
47
				$this->name = key($data);
48
				$this->data = reset($data);
49
			}
50
51
52
			/**
53
			 * {@inheritdoc}
54
			 */
55
			public function getName(): string
56
			{
57
				return $this->name;
58
			}
59
60
61
			/**
62
			 * {@inheritdoc}
63
			 */
64
			public function getType(): Type
65
			{
66
				return $this->data['type'];
67
			}
68
69
70
			/**
71
			 * {@inheritdoc}
72
			 */
73
			public function getDescription(): string
74
			{
75
				return $this->data['description'];
76
			}
77
78
79
			/**
80
			 * {@inheritdoc}
81
			 */
82
			public function getArgs(): array
83
			{
84
				return $this->data['args'];
85
			}
86
87
88
			/**
89
			 * {@inheritdoc}
90
			 */
91
			public function resolve(array $root, array $args, $context = NULL)
92
			{
93
				return $this->data['resolve']($root, $args, $context);
94
			}
95
96
		});
97
	}
98
99
}
100