| Total Complexity | 51 | 
| Total Lines | 324 | 
| Duplicated Lines | 0 % | 
| Changes | 1 | ||
| Bugs | 0 | Features | 0 | 
Complex classes like CcManifest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use CcManifest, and based on these observations, apply Extract Interface, too.
| 1 | <?php  | 
            ||
| 4 | class CcManifest extends XMLGenericDocument implements CcIManifest  | 
            ||
| 5 | { | 
            ||
| 6 | private $ccversion = null;  | 
            ||
| 7 | private $ccobj = null;  | 
            ||
| 8 | private $rootmanifest = null;  | 
            ||
| 9 | private $activemanifest = null;  | 
            ||
| 10 | private $parentmanifest = null;  | 
            ||
| 11 | private $parentparentmanifest = null;  | 
            ||
| 12 | private $ares = [];  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 13 | private $mainidentifier = null;  | 
            ||
| 14 | |||
| 15 | public function __construct($ccver = 13, $activemanifest = null,  | 
            ||
| 16 | $parentmanifest = null, $parentparentmanifest = null)  | 
            ||
| 17 |     { | 
            ||
| 18 | $this->ccversion = $ccver;  | 
            ||
| 19 | $this->ccobj = new CcVersion13();  | 
            ||
| 20 |         parent::__construct('UTF-8', true); | 
            ||
| 21 | }  | 
            ||
| 22 | |||
| 23 | /**  | 
            ||
| 24 | * Register Namespace for use XPATH.  | 
            ||
| 25 | */  | 
            ||
| 26 | public function registerNamespacesForXpath()  | 
            ||
| 27 |     { | 
            ||
| 28 | $scnam = $this->activemanifest->getCcNamespaces();  | 
            ||
| 29 |         foreach ($scnam as $key => $value) { | 
            ||
| 30 | $this->registerNS($key, $value);  | 
            ||
| 31 | }  | 
            ||
| 32 | }  | 
            ||
| 33 | |||
| 34 | /**  | 
            ||
| 35 | * Add Metadata For Manifest.  | 
            ||
| 36 | */  | 
            ||
| 37 | public function addMetadataManifest(CcIMetadataManifest $met)  | 
            ||
| 38 |     { | 
            ||
| 39 |         $metanode = $this->node("//imscc:manifest[@identifier='". | 
            ||
| 40 | $this->activemanifest->manifestID().  | 
            ||
| 41 | "']/imscc:metadata");  | 
            ||
| 42 | $nmeta = $this->activemanifest->createMetadataNode($met, $this->doc, $metanode);  | 
            ||
| 43 | $metanode->appendChild($nmeta);  | 
            ||
| 44 | }  | 
            ||
| 45 | |||
| 46 | /**  | 
            ||
| 47 | * Add Metadata For Resource.  | 
            ||
| 48 | *  | 
            ||
| 49 | * @param string $identifier  | 
            ||
| 50 | */  | 
            ||
| 51 | public function addMetadataResource(CcIMetadataResource $met, $identifier)  | 
            ||
| 52 |     { | 
            ||
| 53 |         $metanode = $this->node("//imscc:resource". | 
            ||
| 54 | "[@identifier='".  | 
            ||
| 55 | $identifier.  | 
            ||
| 56 | "']");  | 
            ||
| 57 |         $metanode2 = $this->node("//imscc:resource". | 
            ||
| 58 | "[@identifier='".  | 
            ||
| 59 | $identifier.  | 
            ||
| 60 | "']/imscc:file");  | 
            ||
| 61 | $nspaces = $this->activemanifest->getCcNamespaces();  | 
            ||
| 62 | $dnode = $this->appendNewElementNs($metanode2, $nspaces['imscc'], 'metadata');  | 
            ||
| 63 | $this->activemanifest->createMetadataResourceNode($met, $this->doc, $dnode);  | 
            ||
| 64 | }  | 
            ||
| 65 | |||
| 66 | /**  | 
            ||
| 67 | * Add Metadata For File.  | 
            ||
| 68 | *  | 
            ||
| 69 | * @param string $identifier  | 
            ||
| 70 | * @param string $filename  | 
            ||
| 71 | */  | 
            ||
| 72 | public function addMetadataFile(CcIMetadataFile $met, $identifier, $filename)  | 
            ||
| 73 |     { | 
            ||
| 74 |         if (empty($met) || empty($identifier) || empty($filename)) { | 
            ||
| 75 |             throw new Exception('Try to add a metadata file with nulls values given!'); | 
            ||
| 76 | }  | 
            ||
| 77 | |||
| 78 |         $metanode = $this->node("//imscc:resource". | 
            ||
| 79 | "[@identifier='".  | 
            ||
| 80 | $identifier.  | 
            ||
| 81 | "']/imscc:file".  | 
            ||
| 82 | "[@href='".  | 
            ||
| 83 | $filename.  | 
            ||
| 84 | "']");  | 
            ||
| 85 | |||
| 86 | $nspaces = $this->activemanifest->getCcNamespaces();  | 
            ||
| 87 | $dnode = $this->doc->createElementNS($nspaces['imscc'], "metadata");  | 
            ||
| 88 | |||
| 89 | $metanode->appendChild($dnode);  | 
            ||
| 90 | |||
| 91 | $this->activemanifest->createMetadataFileNode($met, $this->doc, $dnode);  | 
            ||
| 92 | }  | 
            ||
| 93 | |||
| 94 | public function onCreate()  | 
            ||
| 95 |     { | 
            ||
| 96 | $this->activemanifest = new CcVersion13();  | 
            ||
| 97 | $this->rootmanifest = $this->activemanifest;  | 
            ||
| 98 | $result = $this->activemanifest->createManifest($this->doc);  | 
            ||
| 99 | $this->registerNamespacesForXpath();  | 
            ||
| 100 | |||
| 101 | return $result;  | 
            ||
| 102 | }  | 
            ||
| 103 | |||
| 104 | public function getRelativeBasePath()  | 
            ||
| 105 |     { | 
            ||
| 106 | return $this->activemanifest->base();  | 
            ||
| 107 | }  | 
            ||
| 108 | |||
| 109 | public function parentManifest()  | 
            ||
| 110 |     { | 
            ||
| 111 | return new CcManifest($this, $this->parentmanifest, $this->parentparentmanifest);  | 
            ||
| 112 | }  | 
            ||
| 113 | |||
| 114 | public function rootManifest()  | 
            ||
| 115 |     { | 
            ||
| 116 | return new CcManifest($this, $this->rootmanifest);  | 
            ||
| 117 | }  | 
            ||
| 118 | |||
| 119 | public function manifestID()  | 
            ||
| 120 |     { | 
            ||
| 121 | return $this->activemanifest->manifestID();  | 
            ||
| 122 | }  | 
            ||
| 123 | |||
| 124 | public function getManifestNamespaces()  | 
            ||
| 125 |     { | 
            ||
| 126 | return $this->rootmanifest->getCcNamespaces();  | 
            ||
| 127 | }  | 
            ||
| 128 | |||
| 129 | /**  | 
            ||
| 130 | * Add a new organization.  | 
            ||
| 131 | */  | 
            ||
| 132 | public function addNewOrganization(CcIOrganization &$org)  | 
            ||
| 133 |     { | 
            ||
| 134 | $norg = $this->activemanifest->createOrganizationNode($org, $this->doc);  | 
            ||
| 135 |         $orgnode = $this->node("//imscc:manifest[@identifier='". | 
            ||
| 136 | $this->activemanifest->manifestID().  | 
            ||
| 137 | "']/imscc:organizations");  | 
            ||
| 138 | $orgnode->appendChild($norg);  | 
            ||
| 139 | }  | 
            ||
| 140 | |||
| 141 | public function getResources($searchspecific = '')  | 
            ||
| 142 |     { | 
            ||
| 143 | $reslist = $this->getResourceList($searchspecific);  | 
            ||
| 144 | $resourcelist = [];  | 
            ||
| 145 |         foreach ($reslist as $resourceitem) { | 
            ||
| 146 | $resourcelist[] = new CcResources($this, $resourceitem);  | 
            ||
| 147 | }  | 
            ||
| 148 | |||
| 149 | return $resourcelist;  | 
            ||
| 150 | }  | 
            ||
| 151 | |||
| 152 | public function getCcNamespacePath($nsname)  | 
            ||
| 153 |     { | 
            ||
| 154 |         if (is_string($nsname) && (!empty($nsname))) { | 
            ||
| 155 | $scnam = $this->activemanifest->getCcNamespaces();  | 
            ||
| 156 | |||
| 157 | return $scnam[$nsname];  | 
            ||
| 158 | }  | 
            ||
| 159 | |||
| 160 | return null;  | 
            ||
| 161 | }  | 
            ||
| 162 | |||
| 163 | public function getResourceList($searchspecific = '')  | 
            ||
| 164 |     { | 
            ||
| 165 |         return $this->nodeList("//imscc:manifest[@identifier='". | 
            ||
| 166 | $this->activemanifest->manifestID().  | 
            ||
| 167 | "']/imscc:resources/imscc:resource".$searchspecific);  | 
            ||
| 168 | }  | 
            ||
| 169 | |||
| 170 | public function onLoad()  | 
            ||
| 176 | }  | 
            ||
| 177 | |||
| 178 | public function onSave()  | 
            ||
| 179 |     { | 
            ||
| 180 | return true;  | 
            ||
| 181 | }  | 
            ||
| 182 | |||
| 183 | /**  | 
            ||
| 184 | * Add a resource to the manifest.  | 
            ||
| 185 | *  | 
            ||
| 186 | * @param string $identifier  | 
            ||
| 187 | * @param string $type  | 
            ||
| 188 | *  | 
            ||
| 189 | * @return array  | 
            ||
| 190 | */  | 
            ||
| 191 | public function addResource(CcIResource $res, $identifier = null, $type = 'webcontent')  | 
            ||
| 231 | }  | 
            ||
| 232 | |||
| 233 | public function updateInstructoronly($identifier, $value = false)  | 
            ||
| 234 |     { | 
            ||
| 235 |         if (isset($this->activemanifest->resources[$identifier])) { | 
            ||
| 236 | $resource = $this->activemanifest->resources[$identifier];  | 
            ||
| 237 | $resource->instructoronly = $value;  | 
            ||
| 238 | }  | 
            ||
| 239 | }  | 
            ||
| 240 | |||
| 241 | /**  | 
            ||
| 242 | * Append the resources nodes in the Manifest.  | 
            ||
| 243 | *  | 
            ||
| 244 | * @return DOMNode  | 
            ||
| 245 | */  | 
            ||
| 246 | public function putNodes()  | 
            ||
| 274 | }  | 
            ||
| 275 | |||
| 276 | /**  | 
            ||
| 277 | * TODO - implement this method - critical  | 
            ||
| 278 | */  | 
            ||
| 279 | private function fillManifest()  | 
            ||
| 280 |     { | 
            ||
| 281 | }  | 
            ||
| 282 | |||
| 283 | private function checkIfExistInOther($name, $identifier)  | 
            ||
| 284 |     { | 
            ||
| 285 | $status = [];  | 
            ||
| 286 |         foreach ($this->activemanifest->resources as $value) { | 
            ||
| 287 |             if (($value->identifier != $identifier) && isset($value->files[$name])) { | 
            ||
| 288 | $status[] = $value->identifier;  | 
            ||
| 289 | }  | 
            ||
| 290 | }  | 
            ||
| 291 | |||
| 292 | return $status;  | 
            ||
| 293 | }  | 
            ||
| 294 | |||
| 295 | private function replaceFileXDependency($depen, $name)  | 
            ||
| 308 | }  | 
            ||
| 309 | |||
| 310 | private function getIdentifierByFilename($name)  | 
            ||
| 311 |     { | 
            ||
| 312 | $result = null;  | 
            ||
| 313 |         if (isset($this->activemanifest->resourcesInd[$name])) { | 
            ||
| 314 | $result = $this->activemanifest->resourcesInd[$name];  | 
            ||
| 315 | }  | 
            ||
| 316 | |||
| 317 | return $result;  | 
            ||
| 318 | }  | 
            ||
| 319 | |||
| 320 | private function arrayRemoveByValue($arr, $value)  | 
            ||
| 323 | }  | 
            ||
| 324 | |||
| 325 | private function arrayRemoveByKey($arr, $key)  | 
            ||
| 328 | }  | 
            ||
| 329 | }  | 
            ||
| 330 |