| Conditions | 8 |
| Paths | 5 |
| Total Lines | 82 |
| 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 |
||
| 111 | public function execute(): void { |
||
| 112 | $lookup = $this->revisionLookup; |
||
| 113 | |||
| 114 | $params = $this->extractRequestParams(); |
||
| 115 | $this->validateParameters( $params ); |
||
| 116 | |||
| 117 | // Sites are already tested through allowed params ;) |
||
| 118 | $sites = $this->siteLinkTargetProvider->getSiteList( $this->siteLinkGroups ); |
||
| 119 | |||
| 120 | /** @var Site $fromSite */ |
||
| 121 | list( $fromSite, $fromPage ) = $this->getSiteAndNormalizedPageName( |
||
| 122 | $sites, |
||
| 123 | $params['fromsite'], |
||
| 124 | $params['fromtitle'] |
||
| 125 | ); |
||
| 126 | /** @var Site $toSite */ |
||
| 127 | list( $toSite, $toPage ) = $this->getSiteAndNormalizedPageName( |
||
| 128 | $sites, |
||
| 129 | $params['tosite'], |
||
| 130 | $params['totitle'] |
||
| 131 | ); |
||
| 132 | |||
| 133 | $siteLinkStore = WikibaseRepo::getDefaultInstance()->getStore()->newSiteLinkStore(); |
||
| 134 | $fromId = $siteLinkStore->getItemIdForLink( $fromSite->getGlobalId(), $fromPage ); |
||
| 135 | $toId = $siteLinkStore->getItemIdForLink( $toSite->getGlobalId(), $toPage ); |
||
| 136 | |||
| 137 | $siteLinkList = new SiteLinkList(); |
||
| 138 | $flags = 0; |
||
| 139 | $item = null; |
||
| 140 | |||
| 141 | $summary = new Summary( $this->getModuleName() ); |
||
| 142 | $summary->addAutoSummaryArgs( |
||
| 143 | $fromSite->getGlobalId() . ':' . $fromPage, |
||
| 144 | $toSite->getGlobalId() . ':' . $toPage ); |
||
| 145 | |||
| 146 | //FIXME: use ChangeOps for consistency! |
||
| 147 | |||
| 148 | // Figure out which parts to use and what to create anew |
||
| 149 | if ( $fromId === null && $toId === null ) { |
||
| 150 | // create new item |
||
| 151 | $item = new Item(); |
||
| 152 | $toLink = new SiteLink( $toSite->getGlobalId(), $toPage ); |
||
| 153 | $item->addSiteLink( $toLink ); |
||
| 154 | $siteLinkList->addSiteLink( $toLink ); |
||
| 155 | $fromLink = new SiteLink( $fromSite->getGlobalId(), $fromPage ); |
||
| 156 | $item->addSiteLink( $fromLink ); |
||
| 157 | $siteLinkList->addSiteLink( $fromLink ); |
||
| 158 | |||
| 159 | $flags |= EDIT_NEW; |
||
| 160 | $summary->setAction( 'create' ); |
||
| 161 | } elseif ( $fromId === null && $toId !== null ) { |
||
| 162 | // reuse to-site's item |
||
| 163 | /** @var Item $item */ |
||
| 164 | $itemRev = $lookup->getEntityRevision( $toId, 0, LookupConstants::LATEST_FROM_MASTER ); |
||
| 165 | $item = $itemRev->getEntity(); |
||
| 166 | '@phan-var Item $item'; |
||
| 167 | $fromLink = new SiteLink( $fromSite->getGlobalId(), $fromPage ); |
||
| 168 | $item->addSiteLink( $fromLink ); |
||
| 169 | $siteLinkList->addSiteLink( $fromLink ); |
||
| 170 | $summary->setAction( 'connect' ); |
||
| 171 | } elseif ( $fromId !== null && $toId === null ) { |
||
| 172 | // reuse from-site's item |
||
| 173 | /** @var Item $item */ |
||
| 174 | $itemRev = $lookup->getEntityRevision( $fromId, 0, LookupConstants::LATEST_FROM_MASTER ); |
||
| 175 | $item = $itemRev->getEntity(); |
||
| 176 | '@phan-var Item $item'; |
||
| 177 | $toLink = new SiteLink( $toSite->getGlobalId(), $toPage ); |
||
| 178 | $item->addSiteLink( $toLink ); |
||
| 179 | $siteLinkList->addSiteLink( $toLink ); |
||
| 180 | $summary->setAction( 'connect' ); |
||
| 181 | } elseif ( $fromId->equals( $toId ) ) { |
||
| 182 | // no-op |
||
| 183 | $this->errorReporter->dieError( 'Common item detected, sitelinks are both on the same item', 'common-item' ); |
||
|
|
|||
| 184 | } else { |
||
| 185 | // dissimilar items |
||
| 186 | $this->errorReporter->dieError( 'No common item detected, unable to link titles', 'no-common-item' ); |
||
| 187 | } |
||
| 188 | |||
| 189 | $this->resultBuilder->addSiteLinkList( $siteLinkList, 'entity' ); |
||
| 190 | $status = $this->getAttemptSaveStatus( $item, $summary, $flags ); |
||
| 191 | $this->buildResult( $item, $status ); |
||
| 192 | } |
||
| 193 | |||
| 300 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.