PhpParser   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 67.65 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 23
loc 34
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B setData() 23 23 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
}