| Total Lines | 72 |
| Code Lines | 22 |
| 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 |
||
| 79 | protected function getTypeMapper() |
||
| 80 | { |
||
| 81 | if ($this->typeMapper === null) { |
||
| 82 | $this->typeMapper = new RecursiveTypeMapper(new class($this->getTestObjectType(), $this->getTestObjectType2(), $this->getInputTestObjectType()) implements TypeMapperInterface { |
||
| 83 | /** |
||
| 84 | * @var ObjectType |
||
| 85 | */ |
||
| 86 | private $testObjectType; |
||
| 87 | /** |
||
| 88 | * @var ObjectType |
||
| 89 | */ |
||
| 90 | private $testObjectType2; |
||
| 91 | /** |
||
| 92 | * @var InputObjectType |
||
| 93 | */ |
||
| 94 | private $inputTestObjectType; |
||
| 95 | |||
| 96 | public function __construct(ObjectType $testObjectType, ObjectType $testObjectType2, InputObjectType $inputTestObjectType) |
||
| 97 | { |
||
| 98 | $this->testObjectType = $testObjectType; |
||
| 99 | $this->testObjectType2 = $testObjectType2; |
||
| 100 | $this->inputTestObjectType = $inputTestObjectType; |
||
| 101 | } |
||
| 102 | |||
| 103 | public function mapClassToType(string $className, RecursiveTypeMapperInterface $recursiveTypeMapper): ObjectType |
||
| 104 | { |
||
| 105 | if ($className === TestObject::class) { |
||
| 106 | return $this->testObjectType; |
||
| 107 | } elseif ($className === TestObject2::class) { |
||
| 108 | return $this->testObjectType2; |
||
| 109 | } else { |
||
| 110 | throw CannotMapTypeException::createForType($className); |
||
| 111 | } |
||
| 112 | } |
||
| 113 | |||
| 114 | public function mapClassToInputType(string $className): InputType |
||
| 115 | { |
||
| 116 | if ($className === TestObject::class) { |
||
| 117 | return $this->inputTestObjectType; |
||
| 118 | } else { |
||
| 119 | throw CannotMapTypeException::createForInputType($className); |
||
| 120 | } |
||
| 121 | } |
||
| 122 | |||
| 123 | public function canMapClassToType(string $className): bool |
||
| 124 | { |
||
| 125 | return $className === TestObject::class || $className === TestObject2::class; |
||
| 126 | } |
||
| 127 | |||
| 128 | /** |
||
| 129 | * Returns true if this type mapper can map the $className FQCN to a GraphQL input type. |
||
| 130 | * |
||
| 131 | * @param string $className |
||
| 132 | * @return bool |
||
| 133 | */ |
||
| 134 | public function canMapClassToInputType(string $className): bool |
||
| 135 | { |
||
| 136 | return $className === TestObject::class || $className === TestObject2::class; |
||
| 137 | } |
||
| 138 | |||
| 139 | /** |
||
| 140 | * Returns the list of classes that have matching input GraphQL types. |
||
| 141 | * |
||
| 142 | * @return string[] |
||
| 143 | */ |
||
| 144 | public function getSupportedClasses(): array |
||
| 145 | { |
||
| 146 | return [TestObject::class, TestObject2::class]; |
||
| 147 | } |
||
| 148 | }); |
||
| 149 | } |
||
| 150 | return $this->typeMapper; |
||
| 151 | } |
||
| 224 |