| Conditions | 19 |
| Paths | 1561 |
| Total Lines | 77 |
| Code Lines | 64 |
| 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 |
||
| 96 | public function text() { |
||
| 97 | $data = $this->text; |
||
| 98 | if ( $data ) { |
||
|
|
|||
| 99 | $score = 0; |
||
| 100 | $count = $data['count']; |
||
| 101 | switch ( true ) { |
||
| 102 | case ( $count < 200 ): |
||
| 103 | $score -= 10; |
||
| 104 | break; |
||
| 105 | case ( $count > 200 ): |
||
| 106 | $score += 25; |
||
| 107 | break; |
||
| 108 | } |
||
| 109 | $ratio = $data['ratio']; |
||
| 110 | switch ( true ) { |
||
| 111 | case ( $ratio <= 15 ): |
||
| 112 | $score -= 10; |
||
| 113 | break; |
||
| 114 | case ( $ratio <= 70 ): |
||
| 115 | $score += 25; |
||
| 116 | break; |
||
| 117 | case ( $ratio > 70 ): |
||
| 118 | $score -= 10; |
||
| 119 | break; |
||
| 120 | } |
||
| 121 | if ( $data['links'] ) { |
||
| 122 | $links = $data['links']; |
||
| 123 | if ( $count > 0 ) { |
||
| 124 | $link_ratio = ( ( $links['count'] / $count ) * 100 ); |
||
| 125 | switch ( true ) { |
||
| 126 | case ( $link_ratio <= 50 ): |
||
| 127 | $score += 10; |
||
| 128 | break; |
||
| 129 | case ( $link_ratio > 50 ): |
||
| 130 | $score -= 5; |
||
| 131 | break; |
||
| 132 | } |
||
| 133 | } |
||
| 134 | switch ( true ) { |
||
| 135 | case ( $links['no_text'] < 2 ): |
||
| 136 | $score += 10; |
||
| 137 | break; |
||
| 138 | case ( $links['no_text'] > 2 ): |
||
| 139 | $score -= 5; |
||
| 140 | break; |
||
| 141 | } |
||
| 142 | } |
||
| 143 | |||
| 144 | //Check for keywords in various area: 60, 0 |
||
| 145 | $anch = $links['anchors']; |
||
| 146 | $htags = $data['htags']['content']; |
||
| 147 | $hds = ''; |
||
| 148 | foreach ($htags as $value) { |
||
| 149 | $hds .= ' ' . implode(' ', $value); |
||
| 150 | } |
||
| 151 | $snip_data = $this->snippet; |
||
| 152 | $design_data = $this->design; |
||
| 153 | $img_data = $design_data['image']; |
||
| 154 | $alts = implode(' ', $img_data['alt_value']); |
||
| 155 | $url = implode( " ", explode( "-", $snip_data['url'] ) ); |
||
| 156 | $arr = array( $snip_data['title'], $snip_data['desc'], $alts, $url, $anch, $hds ); |
||
| 157 | foreach ( $arr as $val ) { |
||
| 158 | if ( $val && $val != '' ) { |
||
| 159 | $find_key = $this->key_chk( $val ); |
||
| 160 | switch ( true ) { |
||
| 161 | case ( ! $find_key ): |
||
| 162 | $score += 0; |
||
| 163 | break; |
||
| 164 | case ( $find_key > 0 ): |
||
| 165 | $score += 10; |
||
| 166 | break; |
||
| 167 | } |
||
| 168 | } |
||
| 169 | } |
||
| 170 | return $score; |
||
| 171 | } else { |
||
| 172 | return 0; |
||
| 173 | } |
||
| 334 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.