| Conditions | 15 |
| Total Lines | 71 |
| Code Lines | 36 |
| 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:
Complex classes like item_validator.ItemValidator.get_issues() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | # SPDX-License-Identifier: LGPL-3.0-only |
||
| 43 | def get_issues( |
||
| 44 | self, item, skip=None, document_hook=None, item_hook=None |
||
| 45 | ): # pylint: disable=unused-argument |
||
| 46 | """Yield all the item's issues. |
||
| 47 | |||
| 48 | :param skip: list of document prefixes to skip |
||
| 49 | |||
| 50 | :return: generator of :class:`~doorstop.common.DoorstopError`, |
||
| 51 | :class:`~doorstop.common.DoorstopWarning`, |
||
| 52 | :class:`~doorstop.common.DoorstopInfo` |
||
| 53 | |||
| 54 | """ |
||
| 55 | assert document_hook is None |
||
| 56 | assert item_hook is None |
||
| 57 | skip = [] if skip is None else skip |
||
| 58 | |||
| 59 | log.info("checking item %s...", item) |
||
| 60 | |||
| 61 | # Verify the file can be parsed |
||
| 62 | item.load() |
||
| 63 | |||
| 64 | # Skip inactive items |
||
| 65 | if not item.active: |
||
| 66 | log.info("skipped inactive item: %s", item) |
||
| 67 | return |
||
| 68 | |||
| 69 | # Delay item save if reformatting |
||
| 70 | if settings.REFORMAT: |
||
| 71 | item.auto = False |
||
| 72 | |||
| 73 | # Check text |
||
| 74 | if not item.text: |
||
| 75 | yield DoorstopWarning("no text") |
||
| 76 | |||
| 77 | # Check external refs and references |
||
| 78 | if settings.CHECK_REF: |
||
| 79 | try: |
||
| 80 | item.find_ref() |
||
| 81 | item.find_references() |
||
| 82 | except DoorstopError as exc: |
||
| 83 | yield exc |
||
| 84 | |||
| 85 | # Check links |
||
| 86 | if not item.normative and item.links: |
||
| 87 | yield DoorstopWarning("non-normative, but has links") |
||
| 88 | |||
| 89 | # Check links against the document |
||
| 90 | yield from self._get_issues_document(item, item.document, skip) |
||
| 91 | |||
| 92 | if item.tree: |
||
| 93 | # Check links against the tree |
||
| 94 | yield from self._get_issues_tree(item, item.tree) |
||
| 95 | |||
| 96 | # Check links against both document and tree |
||
| 97 | yield from self._get_issues_both(item, item.document, item.tree, skip) |
||
| 98 | |||
| 99 | # Check review status |
||
| 100 | if not item.reviewed: |
||
| 101 | if settings.CHECK_REVIEW_STATUS: |
||
| 102 | if not item.is_reviewed(): |
||
| 103 | if settings.REVIEW_NEW_ITEMS: |
||
| 104 | item.review() |
||
| 105 | else: |
||
| 106 | yield DoorstopInfo("needs initial review") |
||
| 107 | else: |
||
| 108 | yield DoorstopWarning("unreviewed changes") |
||
| 109 | |||
| 110 | # Reformat the file |
||
| 111 | if settings.REFORMAT: |
||
| 112 | log.debug("reformatting item %s...", item) |
||
| 113 | item.save() |
||
| 114 | |||
| 222 |