Completed
Push — feature/EVO-5751-text-index-mo... ( 0ab3ac...8fecb1 )
by
unknown
62:16 queued 57:01
created

ConstraintNormalizer   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 24
Duplicated Lines 62.5 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 1
c 1
b 1
f 0
lcom 0
cbo 2
dl 15
loc 24
rs 10
ccs 11
cts 11
cp 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A normalize() 15 15 1

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
 * ConstraintNormalizer class file
4
 */
5
namespace Graviton\GeneratorBundle\Definition\Utils;
6
7
use Graviton\GeneratorBundle\Definition\Schema\Constraint;
8
use Graviton\GeneratorBundle\Definition\Schema\ConstraintOption;
9
10
/**
11
 * Constraint normalizer
12
 *
13
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
14
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
15
 * @link     http://swisscom.ch
16
 */
17
class ConstraintNormalizer
0 ignored issues
show
Coding Style introduced by
ConstraintNormalizer does not seem to conform to the naming convention (Utils?$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
18
{
19
    /**
20
     * Convert constraint to array to selerialile it via json_encode
21
     *
22
     * @param Constraint $constraint Constraint
23
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,string|array>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
24
     */
25 6 View Code Duplication
    public static function normalize(Constraint $constraint)
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...
26
    {
27
        return [
28 6
            'name'      => $constraint->getName(),
29 6
            'options'   => array_map(
30 6
                function (ConstraintOption $option) {
31
                    return [
32 6
                        'name'  => $option->getName(),
33 6
                        'value' => $option->getValue(),
34 3
                    ];
35 6
                },
36 6
                $constraint->getOptions()
37 3
            ),
38 3
        ];
39
    }
40
}
41