| Total Complexity | 6 |
| Total Lines | 105 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 12 | final class Yaml |
||
| 13 | { |
||
| 14 | const BLANK = 1; |
||
| 15 | const COMMENT = 2; |
||
| 16 | const COMPACT_MAPPING = 4; |
||
| 17 | const COMPACT_SEQUENCE = 8; |
||
| 18 | const DIRECTIVE = 16; |
||
| 19 | const DOC_END = 32; |
||
| 20 | const DOC_START = 64; |
||
| 21 | const ITEM = 128; |
||
| 22 | const JSON = 256; |
||
| 23 | const KEY = 512; |
||
| 24 | const LITT = 1024;//litteral |
||
| 25 | const LITT_FOLDED = 2048;//litteral |
||
| 26 | const MAPPING = 4096; |
||
| 27 | const PARTIAL = 8192; |
||
| 28 | const QUOTED = 16384; |
||
| 29 | const RAW = 32768; |
||
| 30 | const REF_CALL = 65536;//reference |
||
| 31 | const REF_DEF = 131072;//reference |
||
| 32 | const ROOT = 262144; |
||
| 33 | const SCALAR = 524288; |
||
| 34 | const SEQUENCE = 1048576; |
||
| 35 | const SET = 2097152; |
||
| 36 | const SET_KEY = 4194304; |
||
| 37 | const SET_VALUE = 8388608; |
||
| 38 | const TAG = 16777216; |
||
| 39 | |||
| 40 | const LITTERALS = self::LITT|self::LITT_FOLDED; |
||
| 41 | |||
| 42 | /* @var null|array */ |
||
| 43 | public static $TYPE_NAMES = null; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Gets the name for a given constant declared in the Dallgoot\Yaml namespace |
||
| 47 | * @param integer $typeInteger The constant value |
||
|
3 ignored issues
–
show
|
|||
| 48 | * |
||
| 49 | * @return string The name. |
||
|
1 ignored issue
–
show
|
|||
| 50 | */ |
||
| 51 | public static function getName(int $typeInteger):string |
||
| 52 | { |
||
| 53 | if (is_null(self::$TYPE_NAMES)) { |
||
| 54 | $oClass = new \ReflectionClass(__CLASS__); |
||
| 55 | self::$TYPE_NAMES = array_flip($oClass->getConstants()); |
||
| 56 | // $f = function ($v) { return str_replace('Dallgoot\Yaml\\', '', $v);}; |
||
| 57 | // self::$TYPE_NAMES = array_map($f, array_flip(get_defined_constants(true)['user'])); |
||
| 58 | } |
||
| 59 | return self::$TYPE_NAMES[$typeInteger]; |
||
| 60 | } |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Parse the given Yaml string to a PHP type |
||
| 64 | * |
||
| 65 | * @param string $someYaml Some yaml |
||
|
3 ignored issues
–
show
|
|||
| 66 | * |
||
| 67 | * @return YamlObject|array ( return a PHP type representation with Yaml document as YamlObject and multiple |
||
|
1 ignored issue
–
show
|
|||
| 68 | * documents as an array of YamlObject ) |
||
| 69 | */ |
||
| 70 | public static function parse(string $someYaml, $options = null, $debug = null) |
||
| 71 | { |
||
| 72 | return (new Loader(null, $options, $debug))->parse($someYaml); |
||
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Load the given file and parse its content (assumed YAML) to a PHP type |
||
| 77 | * |
||
| 78 | * @param string $someYaml Some yaml |
||
|
2 ignored issues
–
show
|
|||
| 79 | * |
||
| 80 | * @return Yaml\YamlObject|array ( return a PHP type representation with Yaml document as YamlObject and multiple |
||
| 81 | * documents as an array of YamlObject ) |
||
| 82 | */ |
||
| 83 | public static function parseFile(string $fileName, $options = null, $debug = null) |
||
| 84 | { |
||
| 85 | return (new Loader($fileName, $options, $debug))->parse(); |
||
| 86 | } |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Returns the YAML representation corresponding to given PHP variable |
||
| 90 | * |
||
| 91 | * @param mixed $somePhpVar Some php variable |
||
|
2 ignored issues
–
show
|
|||
| 92 | * @param int|null $options Dumper::constants as options |
||
|
1 ignored issue
–
show
|
|||
| 93 | * |
||
| 94 | * @return string ( the representation of $somePhpVar as a YAML content (single or multiple document according to argument) ) |
||
|
1 ignored issue
–
show
|
|||
| 95 | * @throws Exception on errors during building YAML string |
||
|
1 ignored issue
–
show
|
|||
| 96 | * @see Dumper::toString |
||
|
1 ignored issue
–
show
|
|||
| 97 | */ |
||
| 98 | public static function dump($somePhpVar, $options = null):string |
||
| 101 | } |
||
| 102 | |||
| 103 | /** |
||
| 104 | * Builds the YAML representation corresponding to given PHP variable ($somePhpVar) |
||
| 105 | * AND save it as file with the $fileName provided. |
||
| 106 | * |
||
| 107 | * @param string $fileName The file name |
||
|
1 ignored issue
–
show
|
|||
| 108 | * @param mixed $somePhpVar Some php variable |
||
|
2 ignored issues
–
show
|
|||
| 109 | * @param int|null $options Dumper::constants as options |
||
|
1 ignored issue
–
show
|
|||
| 110 | * |
||
| 111 | * @return boolean true if YAML built and saved , false otherwise |
||
|
1 ignored issue
–
show
|
|||
| 112 | * @throws Exception on errors during building YAML string |
||
|
1 ignored issue
–
show
|
|||
| 113 | */ |
||
| 114 | public static function dumpFile(string $fileName, $somePhpVar, $options = null):bool |
||
| 119 |