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

Yaml::toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 1
eloc 3
c 2
b 0
f 1
nc 1
nop 2
dl 6
loc 6
rs 9.4285
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