| Total Lines | 62 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 71 | protected function getTypeMapper() |
||
| 72 | { |
||
| 73 | if ($this->typeMapper === null) { |
||
| 74 | $this->typeMapper = new class($this->getTestObjectType(), $this->getTestObjectType2(), $this->getInputTestObjectType()) implements TypeMapperInterface { |
||
| 75 | /** |
||
| 76 | * @var ObjectType |
||
| 77 | */ |
||
| 78 | private $testObjectType; |
||
| 79 | /** |
||
| 80 | * @var ObjectType |
||
| 81 | */ |
||
| 82 | private $testObjectType2; |
||
| 83 | /** |
||
| 84 | * @var InputObjectType |
||
| 85 | */ |
||
| 86 | private $inputTestObjectType; |
||
| 87 | |||
| 88 | public function __construct(ObjectType $testObjectType, ObjectType $testObjectType2, InputObjectType $inputTestObjectType) |
||
| 89 | { |
||
| 90 | $this->testObjectType = $testObjectType; |
||
| 91 | $this->testObjectType2 = $testObjectType2; |
||
| 92 | $this->inputTestObjectType = $inputTestObjectType; |
||
| 93 | } |
||
| 94 | |||
| 95 | public function mapClassToType(string $className): OutputType |
||
| 96 | { |
||
| 97 | if ($className === TestObject::class) { |
||
| 98 | return $this->testObjectType; |
||
| 99 | } elseif ($className === TestObject2::class) { |
||
| 100 | return $this->testObjectType2; |
||
| 101 | } else { |
||
| 102 | throw CannotMapTypeException::createForType($className); |
||
| 103 | } |
||
| 104 | } |
||
| 105 | |||
| 106 | public function mapClassToInputType(string $className): InputType |
||
| 107 | { |
||
| 108 | if ($className === TestObject::class) { |
||
| 109 | return $this->inputTestObjectType; |
||
| 110 | } else { |
||
| 111 | throw CannotMapTypeException::createForInputType($className); |
||
| 112 | } |
||
| 113 | } |
||
| 114 | |||
| 115 | public function canMapClassToType(string $className): bool |
||
| 116 | { |
||
| 117 | return $className === TestObject::class; |
||
| 118 | } |
||
| 119 | |||
| 120 | /** |
||
| 121 | * Returns true if this type mapper can map the $className FQCN to a GraphQL input type. |
||
| 122 | * |
||
| 123 | * @param string $className |
||
| 124 | * @return bool |
||
| 125 | */ |
||
| 126 | public function canMapClassToInputType(string $className): bool |
||
| 127 | { |
||
| 128 | return $className === TestObject::class; |
||
| 129 | } |
||
| 130 | }; |
||
| 131 | } |
||
| 132 | return $this->typeMapper; |
||
| 133 | } |
||
| 167 |