XliffReplacerFactory::getInstance()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 19
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 6
nc 3
nop 8
dl 0
loc 19
rs 10
c 1
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace Matecat\XliffParser\XliffReplacer;
4
5
use Matecat\XliffParser\XliffUtils\XliffProprietaryDetect;
6
use Psr\Log\LoggerInterface;
7
8
class XliffReplacerFactory {
9
    /**
10
     * @param string                              $originalXliffPath
11
     * @param array                               $data
12
     * @param array                               $transUnits
13
     * @param string                              $targetLang
14
     * @param string                              $outputFilePath
15
     * @param bool                                $setSourceInTarget
16
     * @param LoggerInterface|null                $logger
17
     * @param XliffReplacerCallbackInterface|null $callback
18
     *
19
     * @return Xliff12|Xliff20|XliffSdl
20
     */
21
    public static function getInstance(
22
            string                         $originalXliffPath,
23
            array                          $data,
24
            array                          $transUnits,
25
            string                         $targetLang,
26
            string                         $outputFilePath,
27
            bool                           $setSourceInTarget,
28
            ?LoggerInterface                $logger = null,
29
            ?XliffReplacerCallbackInterface $callback = null
30
    ): AbstractXliffReplacer {
31
        $info = XliffProprietaryDetect::getInfo( $originalXliffPath );
32
33
        if ( $info[ 'version' ] == 1 && $info[ 'proprietary_short_name' ] !== 'trados' ) {
34
            return new Xliff12( $originalXliffPath, $info[ 'version' ], $data, $transUnits, $targetLang, $outputFilePath, $setSourceInTarget, $logger, $callback );
35
        } elseif ( $info[ 'version' ] == 2 ) {
36
            return new Xliff20( $originalXliffPath, $info[ 'version' ], $data, $transUnits, $targetLang, $outputFilePath, $setSourceInTarget, $logger, $callback );
37
        }
38
39
        return new XliffSdl( $originalXliffPath, $info[ 'version' ], $data, $transUnits, $targetLang, $outputFilePath, $setSourceInTarget, $logger, $callback );
40
    }
41
}
42