Completed
Push — master ( d38a64...a65b20 )
by stéphane
03:22
created

Yaml::parseFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Dallgoot\Yaml;
4
5
/**
6
 * TODO
7
 * @category tag in class comment
0 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
Coding Style introduced by
Category name "tag in class comment" is not valid; consider "Tag_In_Class_Comment" instead
Loading history...
8
 * @package tag in class comment
1 ignored issue
show
Coding Style introduced by
Package name "tag in class comment" is not valid; consider "Tag_In_Class_Comment" instead
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
9
 * @author tag in class comment
1 ignored issue
show
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 3 spaces but found 1
Loading history...
10
 * @license tag in class comment
1 ignored issue
show
Coding Style introduced by
Tag value indented incorrectly; expected 2 spaces but found 1
Loading history...
11
 */
0 ignored issues
show
Coding Style introduced by
Missing @link tag in class comment
Loading history...
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
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 7 found
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 1 spaces but found 6
Loading history...
48
     *
49
     * @return     string    The name.
1 ignored issue
show
Coding Style introduced by
Tag value indented incorrectly; expected 1 spaces but found 5
Loading history...
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
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $options should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $debug should have a doc-comment as per coding-style.
Loading history...
63
     * Parse the given Yaml string to a PHP type
64
     *
65
     * @param      string  $someYaml        Some yaml
3 ignored issues
show
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
Coding Style introduced by
Tag value indented incorrectly; expected 1 spaces but found 6
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 8 found
Loading history...
66
     *
67
     * @return     YamlObject|array    ( return a PHP type representation with Yaml document as YamlObject and multiple
1 ignored issue
show
Coding Style introduced by
Tag value indented incorrectly; expected 1 spaces but found 5
Loading history...
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
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $fileName should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $options should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $debug should have a doc-comment as per coding-style.
Loading history...
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
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
Coding Style introduced by
Doc comment for parameter $someYaml does not match actual variable name $fileName
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 6 found
Loading history...
79
     *
80
     * @return Yaml\YamlObject|array    ( return a PHP type representation with Yaml document as YamlObject and multiple
0 ignored issues
show
Bug introduced by
The type Dallgoot\Yaml\Yaml\YamlObject was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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();
0 ignored issues
show
Bug Best Practice introduced by
The expression return new Dallgoot\Yaml...tions, $debug)->parse() also could return the type Dallgoot\Yaml\YamlObject which is incompatible with the documented return type array|Dallgoot\Yaml\Yaml\YamlObject.
Loading history...
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
Coding Style introduced by
Expected 4 spaces after parameter type; 2 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 7 found
Loading history...
92
     * @param int|null $options       Dumper::constants as options
1 ignored issue
show
Coding Style introduced by
Expected 4 spaces after parameter name; 7 found
Loading history...
93
     *
94
     * @return     string  ( the representation of $somePhpVar as a YAML content (single or multiple document according to argument) )
1 ignored issue
show
Coding Style introduced by
Tag value indented incorrectly; expected 1 spaces but found 5
Loading history...
95
     * @throws   Exception on errors during building YAML string
1 ignored issue
show
Coding Style introduced by
Tag value indented incorrectly; expected 1 spaces but found 3
Loading history...
96
     * @see Dumper::toString
1 ignored issue
show
Coding Style introduced by
Tag value indented incorrectly; expected 4 spaces but found 1
Loading history...
97
     */
98
    public static function dump($somePhpVar, $options = null):string
99
    {
100
        return Dumper::toString($somePhpVar, $options);
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
Coding Style introduced by
Expected 3 spaces after parameter name; 7 found
Loading history...
108
     * @param mixed   $somePhpVar     Some php variable
2 ignored issues
show
Coding Style introduced by
Expected 4 spaces after parameter type; 3 found
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter name; 5 found
Loading history...
109
     * @param int|null $options       Dumper::constants as options
1 ignored issue
show
Coding Style introduced by
Expected 4 spaces after parameter name; 7 found
Loading history...
110
     *
111
     * @return     boolean  true if YAML built and saved , false otherwise
1 ignored issue
show
Coding Style introduced by
Tag value indented incorrectly; expected 1 spaces but found 5
Loading history...
112
     * @throws   Exception on errors during building YAML string
1 ignored issue
show
Coding Style introduced by
Tag value indented incorrectly; expected 1 spaces but found 3
Loading history...
113
     */
114
    public static function dumpFile(string $fileName, $somePhpVar, $options = null):bool
115
    {
116
        return Dumper::toFile($fileName, $somePhpVar, $options);
117
    }
118
}
119