| Total Complexity | 6 |
| Total Lines | 73 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 42 | class Yaml |
||
| 43 | { |
||
| 44 | /* @var null|array */ |
||
| 45 | private static $TYPE_NAMES = null; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Gets the name for a given constant declared in the Dallgoot\Yaml namespace |
||
| 49 | * @param integer $typeInteger The constant value |
||
|
3 ignored issues
–
show
|
|||
| 50 | * |
||
| 51 | * @return string The name. |
||
|
1 ignored issue
–
show
|
|||
| 52 | */ |
||
| 53 | public static function getName($typeInteger) |
||
| 54 | { |
||
| 55 | if(is_null(self::$TYPE_NAMES)) { |
||
| 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) |
||
| 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 |
||
|
3 ignored issues
–
show
|
|||
| 79 | * |
||
| 80 | * @return YamlObject|array ( return a PHP type representation with Yaml document as YamlObject and multiple |
||
|
1 ignored issue
–
show
|
|||
| 81 | * documents as an array of YamlObject ) |
||
| 82 | */ |
||
| 83 | public static function parseFile(string $fileName) |
||
| 84 | { |
||
| 85 | return (new Yaml\Loader($fileName))->parse(); |
||
| 86 | } |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Returns the YAML representation corresponding to given PHP variable |
||
| 90 | * |
||
| 91 | * @param mixed $somePhpVar Some php variable |
||
|
3 ignored issues
–
show
|
|||
| 92 | * |
||
| 93 | * @return string ( the representation of $somePhpVar as a YAML content (single or multiple document according to argument) ) |
||
|
1 ignored issue
–
show
|
|||
| 94 | * @throws Exception on errors during building YAML string |
||
|
1 ignored issue
–
show
|
|||
| 95 | * @see Dumper::toString |
||
|
1 ignored issue
–
show
|
|||
| 96 | */ |
||
| 97 | public static function dump($somePhpVar):string |
||
| 98 | { |
||
| 99 | return Yaml\Dumper::toString($somePhpVar); |
||
| 100 | } |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Builds the YAML representation corresponding to given PHP variable ($somePhpVar) |
||
| 104 | * AND save it as file with the $fileName provided. |
||
| 105 | * |
||
| 106 | * @param string $fileName The file name |
||
|
3 ignored issues
–
show
|
|||
| 107 | * @param mixed $somePhpVar Some php variable |
||
|
3 ignored issues
–
show
|
|||
| 108 | * |
||
| 109 | * @return boolean true if YAML built and saved , false otherwise |
||
|
1 ignored issue
–
show
|
|||
| 110 | * @throws Exception on errors during building YAML string |
||
|
1 ignored issue
–
show
|
|||
| 111 | */ |
||
| 112 | public static function dumpFile(string $fileName, $somePhpVar):boolean |
||
| 115 | } |
||
| 116 | } |
||
| 117 |