| Total Complexity | 63 |
| Total Lines | 199 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like Loader 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 Loader, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 15 | final class Loader |
||
| 16 | { |
||
| 17 | //public |
||
| 18 | |||
| 19 | /* @var null|string */ |
||
| 20 | public static $error; |
||
| 21 | |||
| 22 | public const EXCLUDE_DIRECTIVES = 1;//DONT include_directive |
||
| 23 | public const IGNORE_COMMENTS = 2;//DONT include_comments |
||
| 24 | public const NO_PARSING_EXCEPTIONS = 4;//THROW Exception on parsing Errors |
||
| 25 | public const NO_OBJECT_FOR_DATE = 8;//DONT import date strings as dateTime Object |
||
| 26 | //privates |
||
| 27 | /* @var null|string */ |
||
| 28 | private $content; |
||
| 29 | /* @var null|string */ |
||
| 30 | private $filePath; |
||
| 31 | /* @var integer */ |
||
| 32 | private $debug = 0;///TODO: determine levels |
||
| 33 | /* @var integer */ |
||
| 34 | private $options = 0; |
||
| 35 | //Exceptions messages |
||
| 36 | private const INVALID_VALUE = self::class.": at line %d"; |
||
| 37 | private const EXCEPTION_NO_FILE = self::class.": file '%s' does not exists (or path is incorrect?)"; |
||
| 38 | private const EXCEPTION_READ_ERROR = self::class.": file '%s' failed to be loaded (permission denied ?)"; |
||
| 39 | private const EXCEPTION_LINE_SPLIT = self::class.": content is not a string(maybe a file error?)"; |
||
| 40 | |||
| 41 | public function __construct($absolutePath = null, $options = null, $debug = 0) |
||
| 42 | { |
||
| 43 | $this->debug = is_int($debug) ? min($debug, 3) : 1; |
||
| 44 | $this->options = is_int($options) ? $options : $this->options; |
||
| 45 | if (is_string($absolutePath)) { |
||
| 46 | $this->load($absolutePath); |
||
| 47 | } |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Load a file and save its content as $content |
||
| 52 | * |
||
| 53 | * @param string $absolutePath The absolute path of a file |
||
| 54 | * |
||
| 55 | * @throws \Exception if file don't exist OR reading failed |
||
| 56 | * |
||
| 57 | * @return self ( returns the same Loader ) |
||
| 58 | */ |
||
| 59 | public function load(string $absolutePath):Loader |
||
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Parse Yaml lines into a hierarchy of Node |
||
| 79 | * |
||
| 80 | * @param string $strContent The Yaml string or null to parse loaded content |
||
| 81 | * |
||
| 82 | * @throws \Exception if content is not available as $strContent or as $this->content (from file) |
||
| 83 | * @throws \ParseError if any error during parsing or building |
||
| 84 | * |
||
| 85 | * @return array|YamlObject|null null on errors if NO_PARSING_EXCEPTIONS is set, otherwise an array of YamlObject or just YamlObject |
||
| 86 | */ |
||
| 87 | public function parse($strContent = null) |
||
| 160 | } |
||
| 161 | } |
||
| 162 | |||
| 163 | private function onSpecialType(Node &$n, Node &$previous, &$emptyLines, $lineString):bool |
||
| 190 | } |
||
| 191 | |||
| 192 | private function onContextType(Node &$n, Node &$previous, $lineString):bool |
||
| 216 |