Conditions | 15 |
Paths | 104 |
Total Lines | 72 |
Code Lines | 47 |
Lines | 5 |
Ratio | 6.94 % |
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 |
||
58 | public function run( $resultPageSet = null ) { |
||
59 | $params = $this->extractRequestParams(); |
||
60 | $result = $this->getResult(); |
||
61 | |||
62 | /** @var $qp QueryPage */ |
||
63 | $qp = new $this->qpMap[$params['page']](); |
||
64 | if ( !$qp->userCanExecute( $this->getUser() ) ) { |
||
65 | $this->dieUsageMsg( 'specialpage-cantexecute' ); |
||
66 | } |
||
67 | |||
68 | $r = [ 'name' => $params['page'] ]; |
||
69 | if ( $qp->isCached() ) { |
||
70 | if ( !$qp->isCacheable() ) { |
||
71 | $r['disabled'] = true; |
||
72 | } else { |
||
73 | $r['cached'] = true; |
||
74 | $ts = $qp->getCachedTimestamp(); |
||
75 | if ( $ts ) { |
||
76 | $r['cachedtimestamp'] = wfTimestamp( TS_ISO_8601, $ts ); |
||
77 | } |
||
78 | $r['maxresults'] = $this->getConfig()->get( 'QueryCacheLimit' ); |
||
79 | } |
||
80 | } |
||
81 | $result->addValue( [ 'query' ], $this->getModuleName(), $r ); |
||
82 | |||
83 | if ( $qp->isCached() && !$qp->isCacheable() ) { |
||
84 | // Disabled query page, don't run the query |
||
85 | return; |
||
86 | } |
||
87 | |||
88 | $res = $qp->doQuery( $params['offset'], $params['limit'] + 1 ); |
||
89 | $count = 0; |
||
90 | $titles = []; |
||
91 | foreach ( $res as $row ) { |
||
92 | View Code Duplication | if ( ++$count > $params['limit'] ) { |
|
93 | // We've had enough |
||
94 | $this->setContinueEnumParameter( 'offset', $params['offset'] + $params['limit'] ); |
||
95 | break; |
||
96 | } |
||
97 | |||
98 | $title = Title::makeTitle( $row->namespace, $row->title ); |
||
99 | if ( is_null( $resultPageSet ) ) { |
||
100 | $data = [ 'value' => $row->value ]; |
||
101 | if ( $qp->usesTimestamps() ) { |
||
102 | $data['timestamp'] = wfTimestamp( TS_ISO_8601, $row->value ); |
||
103 | } |
||
104 | self::addTitleInfo( $data, $title ); |
||
105 | |||
106 | foreach ( $row as $field => $value ) { |
||
107 | if ( !in_array( $field, [ 'namespace', 'title', 'value', 'qc_type' ] ) ) { |
||
108 | $data['databaseResult'][$field] = $value; |
||
109 | } |
||
110 | } |
||
111 | |||
112 | $fit = $result->addValue( [ 'query', $this->getModuleName(), 'results' ], null, $data ); |
||
113 | if ( !$fit ) { |
||
114 | $this->setContinueEnumParameter( 'offset', $params['offset'] + $count - 1 ); |
||
115 | break; |
||
116 | } |
||
117 | } else { |
||
118 | $titles[] = $title; |
||
119 | } |
||
120 | } |
||
121 | if ( is_null( $resultPageSet ) ) { |
||
122 | $result->addIndexedTagName( |
||
123 | [ 'query', $this->getModuleName(), 'results' ], |
||
124 | 'page' |
||
125 | ); |
||
126 | } else { |
||
127 | $resultPageSet->populateFromTitles( $titles ); |
||
128 | } |
||
129 | } |
||
130 | |||
172 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.