| Conditions | 10 |
| Paths | 42 |
| Total Lines | 46 |
| 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 |
||
| 61 | public function __construct($name, $client, $documentUniqueFieldConfig, $fieldsConfig, $configEntityFields) |
||
| 62 | { |
||
| 63 | $this->name = $name; |
||
| 64 | $this->client = $client; |
||
| 65 | $this->documentUniqueField = new DocumentUniqueField($documentUniqueFieldConfig, $this); |
||
| 66 | $fieldFactory = new FieldFactory(); |
||
| 67 | |||
| 68 | foreach ($fieldsConfig as $fieldConfig) { |
||
| 69 | $field = $fieldFactory->buildField($fieldConfig); |
||
| 70 | $this->fields[$field->getEntityFieldName()] = $field; |
||
| 71 | if ($field->getSuggester()) { |
||
| 72 | $this->suggesterFieldMap[$field->getSuggester()] = $field; |
||
| 73 | } |
||
| 74 | |||
| 75 | if ($field->isPrimaryKey()) { |
||
| 76 | if ($this->getEntityPrimaryKeyField()) { |
||
| 77 | throw new SchemaConfigException('You have already defined one field as "primary key". It can be only one primary field in schema'); |
||
| 78 | } |
||
| 79 | $this->entityPrimaryKeyField = $field; |
||
| 80 | } |
||
| 81 | } |
||
| 82 | |||
| 83 | if (!$this->getEntityPrimaryKeyField()) { |
||
| 84 | throw new SchemaConfigException('You have to define one field as "entity_primary_key" with true value'); |
||
| 85 | } |
||
| 86 | |||
| 87 | foreach ($configEntityFields as $configField) { |
||
| 88 | $configField = new ConfigEntityField( |
||
| 89 | $configField['config_field_name'], |
||
| 90 | $configField['document_field_name'], |
||
| 91 | $configField['discriminator'], |
||
|
|
|||
| 92 | $configField['priority'] |
||
| 93 | ); |
||
| 94 | $this->configEntityFields[$configField->getConfigFieldName()] = $configField; |
||
| 95 | |||
| 96 | if ($configField->isDiscriminator()) { |
||
| 97 | if ($this->getDiscriminatorConfigField()) { |
||
| 98 | throw new SchemaConfigException('You have already defined one config field as "discriminator". It can be only one discriminator config field in schema'); |
||
| 99 | } |
||
| 100 | $this->discriminatorConfigField = $configField; |
||
| 101 | } |
||
| 102 | } |
||
| 103 | |||
| 104 | if (!$this->getDiscriminatorConfigField()) { |
||
| 105 | throw new SchemaConfigException( |
||
| 106 | 'You have to define one config field in schema with flag "discriminator" having true value' |
||
| 107 | ); |
||
| 212 | } |