| Conditions | 9 |
| Paths | 144 |
| Total Lines | 72 |
| Code Lines | 47 |
| 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 |
||
| 62 | public function selectFormattingStandard($name) |
||
| 63 | { |
||
| 64 | parent::setRightTitle(''); |
||
| 65 | $widthRecommendation = PerfectCMSImageDataExtension::get_width($name); |
||
| 66 | $heightRecommendation = PerfectCMSImageDataExtension::get_height($name); |
||
| 67 | $folderName = PerfectCMSImageDataExtension::get_folder($name); |
||
| 68 | if (!$folderName) { |
||
| 69 | $folderName = 'other-images'; |
||
| 70 | } |
||
| 71 | $recommendedFileType = PerfectCMSImageDataExtension::get_file_type($name); |
||
| 72 | if (!$recommendedFileType) { |
||
| 73 | $recommendedFileType = 'jpg'; |
||
| 74 | } |
||
| 75 | $folderName = 'Uploads/'.$folderName.'/'; |
||
| 76 | if ($widthRecommendation) { |
||
| 77 | if (intval($widthRecommendation)) { |
||
| 78 | //cater for retina |
||
| 79 | $widthRecommendation = $widthRecommendation * 2; |
||
| 80 | $actualWidthDescription = $widthRecommendation.'px'; |
||
| 81 | } else { |
||
| 82 | $actualWidthDescription = $widthRecommendation; |
||
| 83 | } |
||
| 84 | } else { |
||
| 85 | $actualWidthDescription = 'flexible'; |
||
| 86 | } |
||
| 87 | if ($heightRecommendation) { |
||
| 88 | if (intval($heightRecommendation)) { |
||
| 89 | //cater for retina |
||
| 90 | $heightRecommendation = $heightRecommendation * 2; |
||
| 91 | $actualHeightDescription = $heightRecommendation.'px'; |
||
| 92 | } else { |
||
| 93 | $actualHeightDescription = $heightRecommendation; |
||
| 94 | } |
||
| 95 | } else { |
||
| 96 | $actualHeightDescription = 'flexible'; |
||
| 97 | } |
||
| 98 | |||
| 99 | |||
| 100 | $rightTitle = ""; |
||
| 101 | |||
| 102 | if ($actualWidthDescription == 'flexible') { |
||
| 103 | $rightTitle .= 'Image width is flexible, and '; |
||
| 104 | } else { |
||
| 105 | $rightTitle .= "Image should be <strong>$actualWidthDescription</strong> wide and "; |
||
| 106 | } |
||
| 107 | |||
| 108 | |||
| 109 | if ($actualHeightDescription == 'flexible') { |
||
| 110 | $rightTitle .= 'image height is flexible, and '; |
||
| 111 | } else { |
||
| 112 | $rightTitle .= "image should be <strong>$actualHeightDescription</strong> high and "; |
||
| 113 | } |
||
| 114 | |||
| 115 | $rightTitle .= 'the image should be less than 1MB in size. <br/> |
||
| 116 | The recommend file type (file extension) is <strong>'.$recommendedFileType.'</strong>. |
||
| 117 | '; |
||
| 118 | |||
| 119 | |||
| 120 | parent::setRightTitle($rightTitle); |
||
| 121 | |||
| 122 | //create folder |
||
| 123 | Folder::find_or_make($folderName); |
||
| 124 | //set folder |
||
| 125 | $this->setFolderName($folderName); |
||
| 126 | $this->setAllowedFileCategories('image'); |
||
| 127 | $alreadyAllowed = $this->getAllowedExtensions(); |
||
| 128 | $this->setAllowedExtensions($alreadyAllowed + array('svg')); |
||
| 129 | //keep the size reasonable |
||
| 130 | $this->getValidator()->setAllowedMaxFileSize(1 * 1024 * Config::inst()->get('PerfectCMSImagesUploadFieldeProvider', 'max_size_in_kilobytes')); |
||
| 131 | $this->getValidator()->setFieldName($name); |
||
| 132 | return $this; |
||
| 133 | } |
||
| 134 | |||
| 161 |
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.