Conditions | 10 |
Paths | 174 |
Total Lines | 116 |
Code Lines | 76 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
77 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
78 | { |
||
79 | $io = new SymfonyStyle(input: $input, output: $output); |
||
80 | |||
81 | $tree_name = $this->stringArgument(input: $input, name: 'tree-name'); |
||
82 | $gedcom_file = $this->stringArgument(input: $input, name: 'gedcom-file'); |
||
83 | $keep_media = $this->boolOption(input: $input, name: 'keep-media'); |
||
84 | $word_wrapped_notes = $this->boolOption(input: $input, name: 'conc-spaces'); |
||
85 | $gedcom_media_path = $this->stringOption(input: $input, name: 'gedcom-media-path'); |
||
86 | $encoding = $this->stringOption(input: $input, name: 'encoding'); |
||
87 | |||
88 | $tree = $this->tree_service->all()[$tree_name] ?? null; |
||
89 | |||
90 | if ($tree === null) { |
||
91 | $io->error(message: 'Tree "' . $tree_name . '" not found.'); |
||
92 | |||
93 | return self::FAILURE; |
||
94 | } |
||
95 | |||
96 | if (!file_exists($gedcom_file)) { |
||
97 | $io->error(message: 'File "' . $gedcom_file . '" does not exist.'); |
||
98 | |||
99 | return self::FAILURE; |
||
100 | } |
||
101 | |||
102 | try { |
||
103 | DB::connection()->beginTransaction(); |
||
104 | |||
105 | $tree->setPreference('imported', '0'); |
||
106 | $tree->setPreference('keep_media', $keep_media ? '1' : '0'); |
||
107 | $tree->setPreference('WORD_WRAPPED_NOTES', $word_wrapped_notes ? '1' : '0'); |
||
108 | $tree->setPreference('GEDCOM_MEDIA_PATH', $gedcom_media_path); |
||
109 | |||
110 | $queries = [ |
||
111 | 'individuals' => DB::table('individuals')->where('i_file', '=', $tree->id()), |
||
112 | 'families' => DB::table('families')->where('f_file', '=', $tree->id()), |
||
113 | 'sources' => DB::table('sources')->where('s_file', '=', $tree->id()), |
||
114 | 'other' => DB::table('other')->where('o_file', '=', $tree->id()), |
||
115 | 'places' => DB::table('places')->where('p_file', '=', $tree->id()), |
||
116 | 'placelinks' => DB::table('placelinks')->where('pl_file', '=', $tree->id()), |
||
117 | 'name' => DB::table('name')->where('n_file', '=', $tree->id()), |
||
118 | 'dates' => DB::table('dates')->where('d_file', '=', $tree->id()), |
||
119 | 'change' => DB::table('change')->where('gedcom_id', '=', $tree->id()), |
||
120 | ]; |
||
121 | |||
122 | |||
123 | if ($keep_media) { |
||
124 | $queries['link'] = DB::table('link') |
||
125 | ->where('l_file', '=', $tree->id()) |
||
126 | ->where('l_type', '<>', 'OBJE'); |
||
127 | } else { |
||
128 | $queries += [ |
||
129 | 'link' => DB::table('link')->where('l_file', '=', $tree->id()), |
||
130 | 'media_file' => DB::table('media_file')->where('m_file', '=', $tree->id()), |
||
131 | 'media' => DB::table('media')->where('m_file', '=', $tree->id()), |
||
132 | ]; |
||
133 | } |
||
134 | |||
135 | $io->info('Deleting old genealogy data.'); |
||
136 | |||
137 | $progress_bar = new ProgressBar($output, count($queries)); |
||
138 | $progress_bar->setFormat(' %current%/%max% [%bar%] %percent%% %memory%, %elapsed% elapsed'); |
||
139 | $progress_bar->setRedrawFrequency(1); |
||
140 | $progress_bar->start(); |
||
141 | |||
142 | foreach ($queries as $name => $query) { |
||
143 | $query->delete(); |
||
144 | $progress_bar->advance(); |
||
145 | } |
||
146 | |||
147 | $progress_bar->finish(); |
||
148 | $output->writeln(''); |
||
149 | |||
150 | $io->info('Importing new genealogy data.'); |
||
151 | |||
152 | $total_bytes = filesize($gedcom_file); |
||
153 | |||
154 | $bytes_loaded = 0; |
||
155 | |||
156 | $fp = fopen($gedcom_file, 'rb'); |
||
157 | $buffer = ''; |
||
158 | |||
159 | $progress_bar = new ProgressBar($output, $total_bytes); |
||
160 | $progress_bar->setFormat(' %current%/%max% [%bar%] %percent%%, %memory%, %elapsed% elapsed, %remaining% remaining'); |
||
161 | $progress_bar->setRedrawFrequency(1); |
||
162 | $progress_bar->minSecondsBetweenRedraws(0.1); |
||
163 | |||
164 | while ($bytes_loaded < $total_bytes) { |
||
165 | $tmp = fread($fp, 8192); |
||
166 | $buffer .= $tmp; |
||
167 | $bytes_loaded += strlen($buffer); |
||
168 | |||
169 | $records = preg_split('/[\r\n]+(?=0)/', $buffer); |
||
170 | $buffer = array_pop($records); |
||
171 | |||
172 | foreach ($records as $record) { |
||
173 | $this->gedcom_import_service->importRecord($record, $tree, false); |
||
174 | } |
||
175 | |||
176 | $progress_bar->setProgress($bytes_loaded); |
||
177 | } |
||
178 | $progress_bar->finish(); |
||
179 | |||
180 | $output->writeln(''); |
||
181 | |||
182 | $tree->setPreference('imported', '1'); |
||
183 | |||
184 | DB::connection()->commit(); |
||
185 | } catch (Throwable $ex) { |
||
186 | $io->error(message: $ex->getMessage()); |
||
187 | DB::connection()->rollBack(); |
||
188 | |||
189 | return self::FAILURE; |
||
190 | } |
||
191 | |||
192 | return self::SUCCESS; |
||
193 | } |
||
195 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths