| Total Lines | 63 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php declare(strict_types = 1); |
||
| 26 | public static function toObject(array $data): QueryFieldInterface |
||
| 27 | { |
||
| 28 | return new class($data) implements QueryFieldInterface { |
||
| 29 | /** |
||
| 30 | * @var string |
||
| 31 | */ |
||
| 32 | private $name; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var array |
||
| 36 | */ |
||
| 37 | private $data = []; |
||
| 38 | |||
| 39 | |||
| 40 | 1 | public function __construct(array $data) |
|
| 41 | { |
||
| 42 | 1 | $this->name = (string) key($data); |
|
| 43 | 1 | $this->data = (array) reset($data); |
|
| 44 | 1 | } |
|
| 45 | |||
| 46 | |||
| 47 | /** |
||
| 48 | * {@inheritdoc} |
||
| 49 | */ |
||
| 50 | 1 | public function getName(): string |
|
| 51 | { |
||
| 52 | 1 | return $this->name; |
|
| 53 | } |
||
| 54 | |||
| 55 | |||
| 56 | /** |
||
| 57 | * {@inheritdoc} |
||
| 58 | */ |
||
| 59 | 1 | public function getDescription(): string |
|
| 60 | { |
||
| 61 | 1 | return $this->data['description']; |
|
| 62 | } |
||
| 63 | |||
| 64 | |||
| 65 | /** |
||
| 66 | * {@inheritdoc} |
||
| 67 | */ |
||
| 68 | 1 | public function getArgs(): array |
|
| 69 | { |
||
| 70 | 1 | return $this->data['args']; |
|
| 71 | } |
||
| 72 | |||
| 73 | |||
| 74 | /** |
||
| 75 | * {@inheritdoc} |
||
| 76 | */ |
||
| 77 | 1 | public function getType(): Type |
|
| 78 | { |
||
| 79 | 1 | return $this->data['type']; |
|
| 80 | } |
||
| 81 | |||
| 82 | |||
| 83 | /** |
||
| 84 | * {@inheritdoc} |
||
| 85 | */ |
||
| 86 | 1 | public function resolve(array $root, array $args, $context = null) |
|
| 87 | { |
||
| 88 | 1 | return $this->data['resolve']($root, $args, $context); |
|
| 89 | } |
||
| 95 |