| Conditions | 33 | 
| Paths | 6534 | 
| Total Lines | 107 | 
| Code Lines | 72 | 
| 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  | 
            ||
| 90 | public function PerfectCMSImageLink(  | 
            ||
| 91 | $name,  | 
            ||
| 92 | $backupObject = null,  | 
            ||
| 93 | $backupField = '',  | 
            ||
| 94 | $useRetina = null  | 
            ||
| 95 |     ) { | 
            ||
| 96 |         if(isset($_GET['flush'])) { | 
            ||
| 97 |             if (! Config::inst()->get('Image', 'force_resample')) { | 
            ||
| 98 |                 Config::inst()->update('Image', 'force_resample', true); | 
            ||
| 99 | }  | 
            ||
| 100 | }  | 
            ||
| 101 | $image = $this->owner;  | 
            ||
| 102 |         if ($image && $image->exists()) { | 
            ||
| 103 | //we are all good ...  | 
            ||
| 104 |         } else { | 
            ||
| 105 |             if (!$backupObject) { | 
            ||
| 106 | $backupObject = SiteConfig::current_site_config();  | 
            ||
| 107 | }  | 
            ||
| 108 |             if (!$backupField) { | 
            ||
| 109 | $backupField = $name;  | 
            ||
| 110 | }  | 
            ||
| 111 |             if ($backupObject->hasMethod($backupField)) { | 
            ||
| 112 | $image = $backupObject->$backupField();  | 
            ||
| 113 | }  | 
            ||
| 114 | }  | 
            ||
| 115 | |||
| 116 | $perfectWidth = self::get_width($name, true);  | 
            ||
| 117 | $perfectHeight = self::get_height($name, true);  | 
            ||
| 118 | |||
| 119 |         if ($image) { | 
            ||
| 120 |             if ($image instanceof Image) { | 
            ||
| 121 |                 if ($image->exists()) { | 
            ||
| 122 | //work out perfect with and height  | 
            ||
| 123 |                     if(!$useRetina) { | 
            ||
| 124 | $useRetina = PerfectCMSImageDataExtension::use_retina($name);  | 
            ||
| 125 |                     } else { | 
            ||
| 126 | $useRetina = $useRetina;  | 
            ||
| 127 | }  | 
            ||
| 128 | $multiplier = 1;  | 
            ||
| 129 |                     if ($useRetina) { | 
            ||
| 130 | $multiplier = 2;  | 
            ||
| 131 | }  | 
            ||
| 132 | $perfectWidth = $perfectWidth * $multiplier;  | 
            ||
| 133 | $perfectHeight = $perfectHeight * $multiplier;  | 
            ||
| 134 | |||
| 135 | //get current width and height  | 
            ||
| 136 | $myWidth = $image->getWidth();  | 
            ||
| 137 | $myHeight = $image->getHeight();  | 
            ||
| 138 | // $backEndString = Image::get_backend();  | 
            ||
| 139 | // $backend = Injector::inst()->get($backEndString);  | 
            ||
| 140 |                     if ($perfectWidth && $perfectHeight) { | 
            ||
| 141 |                         if ($myWidth == $perfectWidth || $myHeight ==  $perfectHeight) { | 
            ||
| 142 | $link = $image->ScaleWidth($myWidth)->Link();  | 
            ||
| 143 |                         } elseif ($myWidth < $perfectWidth || $myHeight < $perfectHeight) { | 
            ||
| 144 | $link = $image->Pad(  | 
            ||
| 145 | $perfectWidth,  | 
            ||
| 146 | $perfectHeight,  | 
            ||
| 147 | PerfectCMSImageDataExtension::get_padding_bg_colour($name)  | 
            ||
| 148 | )->Link();  | 
            ||
| 149 |                         } elseif ($myWidth > $perfectWidth || $myHeight > $perfectHeight) { | 
            ||
| 150 | $link = $image->FitMax($perfectWidth, $perfectHeight)->Link();  | 
            ||
| 151 | }  | 
            ||
| 152 |                     } elseif ($perfectWidth) { | 
            ||
| 153 | $link = $image->ScaleWidth($perfectWidth)->Link();  | 
            ||
| 154 |                     } elseif ($perfectHeight) { | 
            ||
| 155 | $link = $image->ScaleHeight($perfectHeight)->Link();  | 
            ||
| 156 |                     } else { | 
            ||
| 157 | $link = $image->ScaleWidth($myWidth)->Link();  | 
            ||
| 158 | }  | 
            ||
| 159 | $path_parts = pathinfo($link);  | 
            ||
| 160 | |||
| 161 |                     if (class_exists('HashPathExtension')) { | 
            ||
| 162 |                         if ($curr = Controller::curr()) { | 
            ||
| 163 |                             if ($curr->hasMethod('HashPath')) { | 
            ||
| 164 | $link = $curr->HashPath($link, false);  | 
            ||
| 165 | }  | 
            ||
| 166 | }  | 
            ||
| 167 | }  | 
            ||
| 168 |                     $imageClasses = Config::inst()->get('PerfectCMSImageDataExtension', 'perfect_cms_images_append_title_to_image_links_classes'); | 
            ||
| 169 |                     if(in_array($image->ClassName, $imageClasses) && $image->Title){ | 
            ||
| 170 | $link = $this->replaceLastInstance(  | 
            ||
| 171 | '.'.$path_parts['extension'],  | 
            ||
| 172 | '.pci/'.$image->Title.'.'.$path_parts['extension'],  | 
            ||
| 173 | $link  | 
            ||
| 174 | );  | 
            ||
| 175 | }  | 
            ||
| 176 | return $link;  | 
            ||
| 177 | }  | 
            ||
| 178 | }  | 
            ||
| 179 | }  | 
            ||
| 180 | // no image -> provide placeholder if in DEV MODE only!!!  | 
            ||
| 181 |         if(Director::isDev()) { | 
            ||
| 182 |             if ($perfectWidth || $perfectHeight) { | 
            ||
| 183 |                 if (!$perfectWidth) { | 
            ||
| 184 | $perfectWidth = $perfectHeight;  | 
            ||
| 185 | }  | 
            ||
| 186 |                 if (!$perfectHeight) { | 
            ||
| 187 | $perfectHeight = $perfectWidth;  | 
            ||
| 188 | }  | 
            ||
| 189 | $text = "$perfectWidth x $perfectHeight /2 = ".round($perfectWidth/2)." x ".round($perfectHeight/2)."";  | 
            ||
| 190 | |||
| 191 | return 'https://placehold.it/'.($perfectWidth).'x'.($perfectHeight).'?text='.urlencode($text);  | 
            ||
| 192 |             } else { | 
            ||
| 193 |                 return 'https://placehold.it/500x500?text='.urlencode('no size set'); | 
            ||
| 194 | }  | 
            ||
| 195 | }  | 
            ||
| 196 | }  | 
            ||
| 197 | |||
| 362 | 
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.