PhpParser::setData()   B
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 23
Code Lines 14

Duplication

Lines 23
Ratio 100 %

Code Coverage

Tests 15
CRAP Score 4

Importance

Changes 0
Metric Value
dl 23
loc 23
ccs 15
cts 15
cp 1
rs 8.7972
c 0
b 0
f 0
cc 4
eloc 14
nc 4
nop 1
crap 4
1
<?php
2
3
/**
4
 * This file is part of slick/form package
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Slick\Form\Parser;
11
12
use Slick\Form\Exception\InvalidArgumentException;
13
use Slick\Form\Exception\ParserErrorException;
14
15
/**
16
 * Php form definitions Parser
17
 *
18
 * @package Slick\Form\Parser
19
 * @author  Filipe Silva <[email protected]>
20
 */
21
class PhpParser extends YamlParser
22
{
23
24
    /**
25
     * Sets definition data for form creation
26
     *
27
     * @param mixed $definitions
28
     *
29
     * @return self|$this|ParserInterface
30
     */
31 14 View Code Duplication
    public function setData($definitions)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
32
    {
33 14
        if (is_array($definitions)) {
34 4
            $this->parsedData = $definitions;
35 4
            return;
36
        }
37
38 14
        if (!is_file($definitions)) {
39 2
            throw new InvalidArgumentException(
40 2
                "The form definition file '{$definitions}' does not exists."
41 2
            );
42
        }
43
44
        try {
45 14
            $this->parsedData = include $definitions;
46 14
        } catch (\Exception $caught) {
47 2
            throw new ParserErrorException(
48 2
                'Error parsing form definitions: '.$caught->getMessage(),
49 2
                0,
50
                $caught
51 2
            );
52
        }
53
    }
54
}