Conditions | 9 |
Paths | 26 |
Total Lines | 57 |
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 |
||
94 | // Make sure we know the namespace IDs. |
||
95 | $this->retrieveNamespaces(); |
||
96 | |||
97 | $rootCatName = $rootCat->getPageIdentifier()->getTitle()->getText(); |
||
98 | if ( $currentPath === null ) { |
||
99 | $this->alreadyVisited = []; |
||
100 | $currentPath = new Pages(); |
||
101 | } |
||
102 | $this->alreadyVisited[] = $rootCatName; |
||
103 | $currentPath->addPage( $rootCat ); |
||
104 | |||
105 | // Start a list of child pages. |
||
106 | $descendants = new Pages(); |
||
107 | do { |
||
108 | $pageListGetter = new PageListGetter( $this->api ); |
||
109 | $members = $pageListGetter->getPageListFromCategoryName( $rootCatName ); |
||
110 | foreach ( $members->toArray() as $member ) { |
||
111 | /** @var Title */ |
||
112 | $memberTitle = $member->getPageIdentifier()->getTitle(); |
||
113 | |||
114 | // See if this page is a Category page. |
||
115 | $isCat = false; |
||
116 | if ( isset( $this->namespaces[ $memberTitle->getNs() ] ) ) { |
||
117 | $ns = $this->namespaces[ $memberTitle->getNs() ]; |
||
118 | $isCat = ( isset( $ns['canonical'] ) && $ns['canonical'] === 'Category' ); |
||
119 | } |
||
120 | // If it's a category, descend into it. |
||
121 | if ( $isCat ) { |
||
122 | // If this member has already been visited on this branch of the traversal, |
||
123 | // throw an Exception with information about which categories form the loop. |
||
124 | if ( $currentPath->hasPage( $member ) ) { |
||
125 | $currentPath->addPage( $member ); |
||
126 | $loop = new CategoryLoopException(); |
||
127 | $loop->setCategoryPath( $currentPath ); |
||
128 | throw $loop; |
||
129 | } |
||
130 | // Don't go any further if we've already visited this member |
||
131 | // (does not indicate a loop, however; we've already caught that above). |
||
132 | if ( in_array( $memberTitle->getText(), $this->alreadyVisited ) ) { |
||
133 | continue; |
||
134 | } |
||
135 | // Call any registered callbacked, and carry on to the next branch. |
||
136 | $this->call( self::CALLBACK_CATEGORY, [ $member, $rootCat ] ); |
||
137 | $newDescendants = $this->descend( $member, $currentPath ); |
||
138 | $descendants->addPages( $newDescendants ); |
||
139 | // Re-set the path. |
||
140 | $currentPath = new Pages(); |
||
141 | } else { |
||
142 | // If it's a page, add it to the list and carry on. |
||
143 | $descendants->addPage( $member ); |
||
144 | $this->call( self::CALLBACK_PAGE, [ $member, $rootCat ] ); |
||
145 | } |
||
146 | } |
||
147 | } while ( isset( $result['continue'] ) ); |
||
148 | return $descendants; |
||
149 | } |
||
150 | |||
151 | /** |
||
168 |