Passed
Push — master ( 3491f1...e1ceb1 )
by Chris
40:32
created

PsrPrinterFactory   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 13
c 0
b 0
f 0
dl 0
loc 30
ccs 0
cts 9
cp 0
rs 10
wmc 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A hp$0 ➔ compat3() 0 8 1
compat4() 0 8 ?
compat3() 0 8 ?
A hp$1 ➔ compat4() 0 8 1
A create() 0 7 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Leonidas\Console\Library\Printer\Model;
6
7
use Composer\InstalledVersions;
8
use Nette\PhpGenerator\Printer;
9
10
class PsrPrinterFactory
11
{
12
    public static function create(): Printer
13
    {
14
        $version = InstalledVersions::getVersion('nette/php-generator');
15
16
        return version_compare($version, '4.0', '>=')
0 ignored issues
show
Bug introduced by
It seems like $version can also be of type null; however, parameter $version1 of version_compare() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

16
        return version_compare(/** @scrutinizer ignore-type */ $version, '4.0', '>=')
Loading history...
17
            ? self::compat4()
18
            : self::compat3();
19
    }
20
21
    protected static function compat3(): Printer
22
    {
23
        return new class () extends Printer {
24
            protected $indentation = '    ';
25
26
            protected $linesBetweenMethods = 1;
27
28
            protected $linesBetweenProperties = 1;
29
        };
30
    }
31
32
    protected static function compat4(): Printer
33
    {
34
        return new class () extends Printer {
35
            public string $indentation = '    ';
36
37
            public int $linesBetweenMethods = 1;
38
39
            public int $linesBetweenProperties = 1;
40
        };
41
    }
42
}
43