| Conditions | 4 | 
| Total Lines | 59 | 
| Code Lines | 48 | 
| 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:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
| 1 | """  | 
            ||
| 20 | workspace (and the input files defined therein) as well as optional  | 
            ||
| 21 | parameter.  | 
            ||
| 22 | """  | 
            ||
| 23 | |||
| 24 | def __init__(  | 
            ||
| 25 | self,  | 
            ||
| 26 | workspace,  | 
            ||
| 27 | ocrd_tool=None,  | 
            ||
| 28 | parameter=None,  | 
            ||
| 29 | # TODO OCR-D/core#274  | 
            ||
| 30 | # input_file_grp=None,  | 
            ||
| 31 | # output_file_grp=None,  | 
            ||
| 32 | input_file_grp="INPUT",  | 
            ||
| 33 | output_file_grp="OUTPUT",  | 
            ||
| 34 | page_id=None,  | 
            ||
| 35 | show_help=False,  | 
            ||
| 36 | show_version=False,  | 
            ||
| 37 | dump_json=False,  | 
            ||
| 38 | version=None  | 
            ||
| 39 | ):  | 
            ||
| 40 | if parameter is None:  | 
            ||
| 41 |             parameter = {} | 
            ||
| 42 | if dump_json:  | 
            ||
| 43 | print(json.dumps(ocrd_tool, indent=True))  | 
            ||
| 44 | return  | 
            ||
| 45 | self.ocrd_tool = ocrd_tool  | 
            ||
| 46 | if show_help:  | 
            ||
| 47 | self.show_help()  | 
            ||
| 48 | return  | 
            ||
| 49 | self.version = version  | 
            ||
| 50 | if show_version:  | 
            ||
| 51 | self.show_version()  | 
            ||
| 52 | return  | 
            ||
| 53 | self.workspace = workspace  | 
            ||
| 54 | # FIXME HACK would be better to use pushd_popd(self.workspace.directory)  | 
            ||
| 55 | # but there is no way to do that in process here since it's an  | 
            ||
| 56 | # overridden method. chdir is almost always an anti-pattern.  | 
            ||
| 57 | if self.workspace:  | 
            ||
| 58 | os.chdir(self.workspace.directory)  | 
            ||
| 59 | self.input_file_grp = input_file_grp  | 
            ||
| 60 | self.output_file_grp = output_file_grp  | 
            ||
| 61 | self.page_id = None if page_id == [] or page_id is None else page_id  | 
            ||
| 62 | parameterValidator = ParameterValidator(ocrd_tool)  | 
            ||
| 63 | report = parameterValidator.validate(parameter)  | 
            ||
| 64 | if not report.is_valid:  | 
            ||
| 65 |             raise Exception("Invalid parameters %s" % report.errors) | 
            ||
| 66 | self.parameter = parameter  | 
            ||
| 67 | |||
| 68 | def show_help(self):  | 
            ||
| 69 | print(generate_processor_help(self.ocrd_tool))  | 
            ||
| 70 | |||
| 71 | def show_version(self):  | 
            ||
| 72 |         print("Version %s, ocrd/core %s" % (self.version, OCRD_VERSION)) | 
            ||
| 73 | |||
| 74 | def verify(self):  | 
            ||
| 75 | """  | 
            ||
| 76 | Verify that the input fulfills the processor's requirements.  | 
            ||
| 77 | """  | 
            ||
| 78 | return True  | 
            ||
| 79 | |||
| 112 |