Conditions | 4 |
Paths | 4 |
Total Lines | 56 |
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 |
||
41 | public function handle(): int |
||
42 | { |
||
43 | $indexName = $this->argument('index-name'); |
||
44 | $mappingFilePath = $this->argument('mapping-file-path'); |
||
45 | |||
46 | if (!$this->argumentsAreValid( |
||
47 | $indexName, |
||
48 | $mappingFilePath |
||
49 | )) { |
||
50 | return self::FAILURE; |
||
51 | } |
||
52 | |||
53 | if (!$this->client->indices()->exists([ |
||
54 | 'index' => $indexName, |
||
55 | ])) { |
||
56 | $this->output->writeln( |
||
57 | sprintf( |
||
58 | '<error>Index %s doesn\'t exists and mapping cannot be created or updated.</error>', |
||
59 | $indexName |
||
60 | ) |
||
61 | ); |
||
62 | |||
63 | return self::FAILURE; |
||
64 | } |
||
65 | |||
66 | try { |
||
67 | $this->client->indices()->putMapping([ |
||
68 | 'index' => $indexName, |
||
69 | 'body' => json_decode( |
||
70 | $mappingFilePath, |
||
71 | true |
||
72 | ), |
||
73 | ]); |
||
74 | } catch (Throwable $exception) { |
||
75 | $this->output->writeln( |
||
76 | sprintf( |
||
77 | '<error>Error creating or updating mapping for index %s, given mapping file: %s - error message: %s.</error>', |
||
78 | $indexName, |
||
79 | $mappingFilePath, |
||
80 | $exception->getMessage() |
||
81 | ) |
||
82 | ); |
||
83 | |||
84 | return self::FAILURE; |
||
85 | } |
||
86 | |||
87 | $this->output->writeln( |
||
88 | sprintf( |
||
89 | '<info>Mapping created or updated for index %s using file %s.</info>', |
||
90 | $indexName, |
||
91 | $mappingFilePath |
||
92 | ) |
||
93 | ); |
||
94 | |||
95 | return self::SUCCESS; |
||
96 | } |
||
97 | |||
126 |