| Conditions | 17 | 
| Paths | 259 | 
| Total Lines | 72 | 
| Code Lines | 39 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 2 | ||
| Bugs | 2 | Features | 1 | 
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 declare(strict_types=1);  | 
            ||
| 38 | public static function load($actual, bool $isHtml = false, string $filename = '', bool $xinclude = false, bool $strict = false): \DOMDocument  | 
            ||
| 39 |     { | 
            ||
| 40 |         if ($actual instanceof \DOMDocument) { | 
            ||
| 41 | return $actual;  | 
            ||
| 42 | }  | 
            ||
| 43 | |||
| 44 |         if (!\is_string($actual)) { | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 45 |             throw new Exception('Could not load XML from ' . \gettype($actual)); | 
            ||
| 46 | }  | 
            ||
| 47 | |||
| 48 |         if ($actual === '') { | 
            ||
| 49 |             throw new Exception('Could not load XML from empty string'); | 
            ||
| 50 | }  | 
            ||
| 51 | |||
| 52 | // Required for XInclude on Windows.  | 
            ||
| 53 |         if ($xinclude) { | 
            ||
| 54 | $cwd = \getcwd();  | 
            ||
| 55 | @\chdir(\dirname($filename));  | 
            ||
| 56 | }  | 
            ||
| 57 | |||
| 58 | $document = new \DOMDocument();  | 
            ||
| 59 | $document->preserveWhiteSpace = false;  | 
            ||
| 60 | |||
| 61 | $internal = \libxml_use_internal_errors(true);  | 
            ||
| 62 | $message = '';  | 
            ||
| 63 | $reporting = \error_reporting(0);  | 
            ||
| 64 | |||
| 65 |         if ($filename !== '') { | 
            ||
| 66 | // Required for XInclude  | 
            ||
| 67 | $document->documentURI = $filename;  | 
            ||
| 68 | }  | 
            ||
| 69 | |||
| 70 |         if ($isHtml) { | 
            ||
| 71 | $loaded = $document->loadHTML($actual);  | 
            ||
| 72 |         } else { | 
            ||
| 73 | $loaded = $document->loadXML($actual);  | 
            ||
| 74 | }  | 
            ||
| 75 | |||
| 76 |         if (!$isHtml && $xinclude) { | 
            ||
| 77 | $document->xinclude();  | 
            ||
| 78 | }  | 
            ||
| 79 | |||
| 80 |         foreach (\libxml_get_errors() as $error) { | 
            ||
| 81 | $message .= "\n" . $error->message;  | 
            ||
| 82 | }  | 
            ||
| 83 | |||
| 84 | \libxml_use_internal_errors($internal);  | 
            ||
| 85 | \error_reporting($reporting);  | 
            ||
| 86 | |||
| 87 |         if (isset($cwd)) { | 
            ||
| 88 | @\chdir($cwd);  | 
            ||
| 89 | }  | 
            ||
| 90 | |||
| 91 |         if ($loaded === false || ($strict && $message !== '')) { | 
            ||
| 92 |             if ($filename !== '') { | 
            ||
| 93 | throw new Exception(  | 
            ||
| 94 | \sprintf(  | 
            ||
| 95 | 'Could not load "%s".%s',  | 
            ||
| 96 | $filename,  | 
            ||
| 97 | $message !== '' ? "\n" . $message : ''  | 
            ||
| 98 | )  | 
            ||
| 99 | );  | 
            ||
| 100 | }  | 
            ||
| 101 | |||
| 102 |             if ($message === '') { | 
            ||
| 103 | $message = 'Could not load XML for unknown reason';  | 
            ||
| 104 | }  | 
            ||
| 105 | |||
| 106 | throw new Exception($message);  | 
            ||
| 107 | }  | 
            ||
| 108 | |||
| 109 | return $document;  | 
            ||
| 110 | }  | 
            ||
| 136 |