Completed
Push — master ( 55caa0...3f2e9b )
by Oscar
02:05
created

Yaml   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 20
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 20
loc 20
rs 10
wmc 1
lcom 1
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A toString() 6 6 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
namespace Gettext\Generators;
4
5
use Gettext\Translations;
6
use Gettext\Utils\MultidimensionalArrayTrait;
7
use Symfony\Component\Yaml\Yaml as YamlDumper;
8
9 View Code Duplication
class Yaml extends Generator implements GeneratorInterface
0 ignored issues
show
Duplication introduced by
This class 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...
10
{
11
    use MultidimensionalArrayTrait;
12
13
    public static $options = [
14
        'includeHeaders' => true,
15
        'inline' => 3,
16
        'indent' => 2,
17
    ];
18
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public static function toString(Translations $translations, array $options = [])
23
    {
24
        $options += static::$options;
25
26
        return YamlDumper::dump(static::toArray($translations, $options['includeHeaders']), $options['inline'], $options['indent']);
0 ignored issues
show
Bug introduced by
Since toArray() is declared private, calling it with static will lead to errors in possible sub-classes. You can either use self, or increase the visibility of toArray() to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
}

public static function getSomeVariable()
{
    return static::getTemperature();
}

}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass {
      private static function getTemperature() {
        return "-182 °C";
    }
}

print YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class YourClass
{
    private static function getTemperature() {
        return "3422 °C";
    }

    public static function getSomeVariable()
    {
        return self::getTemperature();
    }
}
Loading history...
27
    }
28
}
29