| Conditions | 25 | 
| Paths | 2800 | 
| Total Lines | 124 | 
| Code Lines | 84 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 1 | ||
| Bugs | 0 | Features | 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  | 
            ||
| 81 | public function getResourceData($instance)  | 
            ||
| 82 |     { | 
            ||
| 83 | //var_dump($instance);  | 
            ||
| 84 | |||
| 85 | $xpath = Cc1p3Convert::newxPath(Cc1p3Convert::$manifest, Cc1p3Convert::$namespaces);  | 
            ||
| 86 | $link = '';  | 
            ||
| 87 | |||
| 88 |         if ($instance['common_cartriedge_type'] == Cc1p3Convert::CC_TYPE_WEBCONTENT || $instance['common_cartriedge_type'] == Cc1p3Convert::CC_TYPE_ASSOCIATED_CONTENT) { | 
            ||
| 89 |             $resource = $xpath->query('/imscc:manifest/imscc:resources/imscc:resource[@identifier="'.$instance['resource_indentifier'].'"]/@href'); | 
            ||
| 90 |             if ($resource->length > 0) { | 
            ||
| 91 | $resource = !empty($resource->item(0)->nodeValue) ? $resource->item(0)->nodeValue : '';  | 
            ||
| 92 |             } else { | 
            ||
| 93 | $resource = '';  | 
            ||
| 94 | }  | 
            ||
| 95 | |||
| 96 |             if (empty($resource)) { | 
            ||
| 97 | unset($resource);  | 
            ||
| 98 |                 $resource = $xpath->query('/imscc:manifest/imscc:resources/imscc:resource[@identifier="'.$instance['resource_indentifier'].'"]/imscc:file/@href'); | 
            ||
| 99 |                 if ($resource->length > 0) { | 
            ||
| 100 | $resource = !empty($resource->item(0)->nodeValue) ? $resource->item(0)->nodeValue : '';  | 
            ||
| 101 |                 } else { | 
            ||
| 102 | $resource = '';  | 
            ||
| 103 | }  | 
            ||
| 104 | }  | 
            ||
| 105 |             if (!empty($resource)) { | 
            ||
| 106 | $link = $resource;  | 
            ||
| 107 | }  | 
            ||
| 108 | }  | 
            ||
| 109 | |||
| 110 |         if ($instance['common_cartriedge_type'] == Cc1p3Convert::CC_TYPE_WEBLINK) { | 
            ||
| 111 |             $external_resource = $xpath->query('/imscc:manifest/imscc:resources/imscc:resource[@identifier="'.$instance['resource_indentifier'].'"]/imscc:file/@href')->item(0)->nodeValue; | 
            ||
| 112 | |||
| 113 |             if ($external_resource) { | 
            ||
| 114 | $resource = $this->loadXmlResource(Cc1p3Convert::$pathToManifestFolder.DIRECTORY_SEPARATOR.$external_resource);  | 
            ||
| 115 | |||
| 116 |                 if (!empty($resource)) { | 
            ||
| 117 | $xpath = Cc1p3Convert::newxPath($resource, Cc1p3Convert::$resourcens);  | 
            ||
| 118 |                     $resource = $xpath->query('/wl:webLink/wl:url/@href'); | 
            ||
| 119 |                     if ($resource->length > 0) { | 
            ||
| 120 | $rawlink = $resource->item(0)->nodeValue;  | 
            ||
| 121 |                         if (!validateUrlSyntax($rawlink, 's+')) { | 
            ||
| 122 | $changed = rawurldecode($rawlink);  | 
            ||
| 123 |                             if (validateUrlSyntax($changed, 's+')) { | 
            ||
| 124 | $link = $changed;  | 
            ||
| 125 |                             } else { | 
            ||
| 126 | $link = 'http://invalidurldetected/';  | 
            ||
| 127 | }  | 
            ||
| 128 |                         } else { | 
            ||
| 129 | $link = htmlspecialchars(trim($rawlink), ENT_COMPAT, 'UTF-8', false);  | 
            ||
| 130 | }  | 
            ||
| 131 | }  | 
            ||
| 132 | }  | 
            ||
| 133 | }  | 
            ||
| 134 | }  | 
            ||
| 135 | |||
| 136 | $mod_type = 'file';  | 
            ||
| 137 | $mod_options = 'objectframe';  | 
            ||
| 138 | $mod_reference = $link;  | 
            ||
| 139 | //detected if we are dealing with html file  | 
            ||
| 140 |         if (!empty($link) && ($instance['common_cartriedge_type'] == Cc1p3Convert::CC_TYPE_WEBCONTENT)) { | 
            ||
| 141 | $ext = strtolower(pathinfo($link, PATHINFO_EXTENSION));  | 
            ||
| 142 |             if (in_array($ext, ['html', 'htm', 'xhtml'])) { | 
            ||
| 143 | $mod_type = 'html';  | 
            ||
| 144 | //extract the content of the file  | 
            ||
| 145 | $rootpath = realpath(Cc1p3Convert::$pathToManifestFolder);  | 
            ||
| 146 | $htmlpath = realpath($rootpath.DIRECTORY_SEPARATOR.$link);  | 
            ||
| 147 | $dirpath = dirname($htmlpath);  | 
            ||
| 148 |                 if (file_exists($htmlpath)) { | 
            ||
| 149 | $fcontent = file_get_contents($htmlpath);  | 
            ||
| 150 | $mod_alltext = $this->prepareContent($fcontent);  | 
            ||
| 151 | $mod_reference = '';  | 
            ||
| 152 | $mod_options = '';  | 
            ||
| 153 | /**  | 
            ||
| 154 | * try to handle embedded resources  | 
            ||
| 155 | * images, linked static resources, applets, videos.  | 
            ||
| 156 | */  | 
            ||
| 157 | $doc = new DOMDocument();  | 
            ||
| 158 | $cdir = getcwd();  | 
            ||
| 159 | chdir($dirpath);  | 
            ||
| 160 |                     try { | 
            ||
| 161 | $doc->loadHTML($mod_alltext);  | 
            ||
| 162 | $xpath = new DOMXPath($doc);  | 
            ||
| 163 | $attributes = ['href', 'src', 'background', 'archive', 'code'];  | 
            ||
| 164 | $qtemplate = "//*[@##][not(contains(@##,'://'))]/@##";  | 
            ||
| 165 | $query = '';  | 
            ||
| 166 |                         foreach ($attributes as $attrname) { | 
            ||
| 167 |                             if (!empty($query)) { | 
            ||
| 168 | $query .= " | ";  | 
            ||
| 169 | }  | 
            ||
| 170 |                             $query .= str_replace('##', $attrname, $qtemplate); | 
            ||
| 171 | }  | 
            ||
| 172 | $list = $xpath->query($query);  | 
            ||
| 173 | $searches = [];  | 
            ||
| 174 | $replaces = [];  | 
            ||
| 175 |                         foreach ($list as $resrc) { | 
            ||
| 176 | $rpath = $resrc->nodeValue;  | 
            ||
| 177 | $rtp = realpath($rpath);  | 
            ||
| 178 |                             if (($rtp !== false) && is_file($rtp)) { | 
            ||
| 179 | //file is there - we are in business  | 
            ||
| 180 |                                 $strip = str_replace("\\", "/", str_ireplace($rootpath, '', $rtp)); | 
            ||
| 181 |                                 $encoded_file = '$@FILEPHP@$'.str_replace('/', '$@SLASH@$', $strip); | 
            ||
| 182 | $searches[] = $resrc->nodeValue;  | 
            ||
| 183 | $replaces[] = $encoded_file;  | 
            ||
| 184 | }  | 
            ||
| 185 | }  | 
            ||
| 186 | $mod_alltext = str_replace($searches, $replaces, $mod_alltext);  | 
            ||
| 187 |                     } catch (Exception $e) { | 
            ||
| 188 | //silence the complaints  | 
            ||
| 189 | }  | 
            ||
| 190 | chdir($cdir);  | 
            ||
| 191 | $mod_alltext = self::safexml($mod_alltext);  | 
            ||
| 192 | }  | 
            ||
| 193 | }  | 
            ||
| 194 | }  | 
            ||
| 195 | |||
| 196 | $values = [$instance['instance'],  | 
            ||
| 197 | self::safexml($instance['title']),  | 
            ||
| 198 | $mod_type,  | 
            ||
| 199 | $mod_alltext,  | 
            ||
| 200 | $mod_reference,  | 
            ||
| 201 | $mod_options,  | 
            ||
| 202 | ];  | 
            ||
| 203 | |||
| 204 | return $values;  | 
            ||
| 205 | }  | 
            ||
| 207 |