| Conditions | 17 |
| Paths | 27 |
| Total Lines | 68 |
| Lines | 28 |
| Ratio | 41.18 % |
| 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 |
||
| 38 | public function run($request) |
||
| 39 | { |
||
| 40 | ini_set('max_execution_time', 3000); |
||
| 41 | require_once 'thirdparty/spyc/spyc.php'; |
||
| 42 | $filesArray = Config::inst()->get("DataIntegrityTestYML", "config_files"); |
||
| 43 | $classesToSkip = Config::inst()->get("DataIntegrityTestYML", "classes_to_skip"); |
||
| 44 | $variablesToSkip = Config::inst()->get("DataIntegrityTestYML", "variables_to_skip"); |
||
| 45 | foreach ($filesArray as $folderAndFileLocation) { |
||
|
|
|||
| 46 | db::alteration_message("<h2>Checking $folderAndFileLocation</h2>"); |
||
| 47 | $fixtureFolderAndFile = Director::baseFolder().'/'. $folderAndFileLocation; |
||
| 48 | if (!file_exists($fixtureFolderAndFile)) { |
||
| 49 | user_error('No custom configuration has been setup here : "' . $fixtureFolderAndFile . '" set the files here: DataIntegrityTestYML::config_files', E_USER_NOTICE); |
||
| 50 | } |
||
| 51 | $parser = new Spyc(); |
||
| 52 | $arrayOfSettings = $parser->loadFile($fixtureFolderAndFile); |
||
| 53 | foreach ($arrayOfSettings as $className => $variables) { |
||
| 54 | if (in_array(strtolower($className), $classesToSkip)) { |
||
| 55 | db::alteration_message("$className : skipped"); |
||
| 56 | } else { |
||
| 57 | echo "<br /><br />"; |
||
| 58 | if (!class_exists($className)) { |
||
| 59 | db::alteration_message("$className does not exist", "deleted"); |
||
| 60 | } else { |
||
| 61 | db::alteration_message("$className", "created"); |
||
| 62 | foreach ($variables as $variable => $setting) { |
||
| 63 | if ($variable == "icon") { |
||
| 64 | $fileLocationForOthers = Director::baseFolder().'/'.$setting; |
||
| 65 | $fileLocationForSiteTree = Director::baseFolder().'/'.$setting.'-file.gif'; |
||
| 66 | if ($className::create() instanceof SiteTree) { |
||
| 67 | View Code Duplication | if (!file_exists($fileLocationForSiteTree)) { |
|
| 68 | db::alteration_message(" <u>$className.$variable</u> icon $fileLocationForSiteTree can not be found", "deleted"); |
||
| 69 | } else { |
||
| 70 | db::alteration_message(" <u>$className.$variable</u> icon $fileLocationForSiteTree exists", "created"); |
||
| 71 | } |
||
| 72 | View Code Duplication | } else { |
|
| 73 | if (!file_exists($fileLocationForOthers)) { |
||
| 74 | db::alteration_message(" <u>$className.$variable</u> icon $fileLocationForOthers can not be found", "deleted"); |
||
| 75 | } else { |
||
| 76 | db::alteration_message(" <u>$className.$variable</u> icon $fileLocationForOthers exists", "created"); |
||
| 77 | } |
||
| 78 | } |
||
| 79 | } elseif ($variable == "extensions") { |
||
| 80 | if (!is_array($setting)) { |
||
| 81 | db::alteration_message(" <u>$className.$variable</u> extensions should be set as an array.", "deleted"); |
||
| 82 | View Code Duplication | } else { |
|
| 83 | foreach ($setting as $extensionClassName) { |
||
| 84 | if (!class_exists($extensionClassName)) { |
||
| 85 | db::alteration_message(" <u>$className.$variable</u> extension class <u>$extensionClassName</u> does not exist", "deleted"); |
||
| 86 | } else { |
||
| 87 | db::alteration_message(" <u>$className.$variable</u> extension class <u>$extensionClassName</u> found", "created"); |
||
| 88 | } |
||
| 89 | } |
||
| 90 | } |
||
| 91 | } elseif (in_array($variable, $variablesToSkip)) { |
||
| 92 | db::alteration_message(" <u>$className.$variable</u> skipped"); |
||
| 93 | View Code Duplication | } else { |
|
| 94 | if (!property_exists($className, $variable)) { |
||
| 95 | db::alteration_message(" <u>$className.$variable</u> does not exist", "deleted"); |
||
| 96 | } else { |
||
| 97 | db::alteration_message(" <u>$className.$variable</u> found", "created"); |
||
| 98 | } |
||
| 99 | } |
||
| 100 | } |
||
| 101 | } |
||
| 102 | } |
||
| 103 | } |
||
| 104 | } |
||
| 105 | } |
||
| 106 | } |
||
| 107 |
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.