Passed
Pull Request — master (#90)
by Domenico
03:06
created
src/XliffUtils/CheckPipeline/CheckSDL.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -8,16 +8,16 @@
 block discarded – undo
8 8
      *
9 9
      * @return array|null
10 10
      */
11
-    public function check( ?array $tmp = [] ): ?array {
11
+    public function check(?array $tmp = []): ?array {
12 12
         $fileType = [];
13 13
 
14
-        if ( isset( $tmp[ 0 ] ) ) {
15
-            if ( stripos( $tmp[ 0 ], 'sdl:version' ) !== false ) {
14
+        if (isset($tmp[0])) {
15
+            if (stripos($tmp[0], 'sdl:version') !== false) {
16 16
                 //little trick, we consider not proprietary Sdlxliff files because we can handle them
17
-                $fileType[ 'proprietary' ]            = false;
18
-                $fileType[ 'proprietary_name' ]       = 'SDL Studio ';
19
-                $fileType[ 'proprietary_short_name' ] = 'trados';
20
-                $fileType[ 'converter_version' ]      = 'legacy';
17
+                $fileType['proprietary']            = false;
18
+                $fileType['proprietary_name']       = 'SDL Studio ';
19
+                $fileType['proprietary_short_name'] = 'trados';
20
+                $fileType['converter_version']      = 'legacy';
21 21
 
22 22
                 return $fileType;
23 23
             }
Please login to merge, or discard this patch.
src/XliffUtils/CheckPipeline/CheckGlobalSight.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -8,15 +8,15 @@
 block discarded – undo
8 8
      *
9 9
      * @return array|null
10 10
      */
11
-    public function check( ?array $tmp = [] ): ?array {
11
+    public function check(?array $tmp = []): ?array {
12 12
         $fileType = [];
13 13
 
14
-        if ( isset( $tmp[ 0 ] ) ) {
15
-            if ( stripos( $tmp[ 0 ], 'globalsight' ) !== false ) {
16
-                $fileType[ 'proprietary' ]            = true;
17
-                $fileType[ 'proprietary_name' ]       = 'GlobalSight Download File';
18
-                $fileType[ 'proprietary_short_name' ] = 'globalsight';
19
-                $fileType[ 'converter_version' ]      = 'legacy';
14
+        if (isset($tmp[0])) {
15
+            if (stripos($tmp[0], 'globalsight') !== false) {
16
+                $fileType['proprietary']            = true;
17
+                $fileType['proprietary_name']       = 'GlobalSight Download File';
18
+                $fileType['proprietary_short_name'] = 'globalsight';
19
+                $fileType['converter_version']      = 'legacy';
20 20
 
21 21
                 return $fileType;
22 22
             }
Please login to merge, or discard this patch.
src/XliffUtils/CheckPipeline/CheckMateCATConverter.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -8,20 +8,20 @@
 block discarded – undo
8 8
      *
9 9
      * @return array|null
10 10
      */
11
-    public function check( ?array $tmp = [] ): ?array {
11
+    public function check(?array $tmp = []): ?array {
12 12
         $fileType = [];
13 13
 
14
-        if ( isset( $tmp[ 0 ] ) ) {
15
-            preg_match( '#tool-id\s*=\s*"matecat-converter(\s+([^"]+))?"#i', $tmp[ 0 ], $matches );
16
-            if ( !empty( $matches ) ) {
17
-                $fileType[ 'proprietary' ]            = false;
18
-                $fileType[ 'proprietary_name' ]       = 'MateCAT Converter';
19
-                $fileType[ 'proprietary_short_name' ] = 'matecat_converter';
20
-                if ( isset( $matches[ 2 ] ) ) {
21
-                    $fileType[ 'converter_version' ] = $matches[ 2 ];
14
+        if (isset($tmp[0])) {
15
+            preg_match('#tool-id\s*=\s*"matecat-converter(\s+([^"]+))?"#i', $tmp[0], $matches);
16
+            if (!empty($matches)) {
17
+                $fileType['proprietary']            = false;
18
+                $fileType['proprietary_name']       = 'MateCAT Converter';
19
+                $fileType['proprietary_short_name'] = 'matecat_converter';
20
+                if (isset($matches[2])) {
21
+                    $fileType['converter_version'] = $matches[2];
22 22
                 } else {
23 23
                     // First converter release didn't specify version
24
-                    $fileType[ 'converter_version' ] = '1.0';
24
+                    $fileType['converter_version'] = '1.0';
25 25
                 }
26 26
 
27 27
                 return $fileType;
Please login to merge, or discard this patch.
src/XliffUtils/CheckPipeline/CheckXliffVersion2.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -8,22 +8,22 @@
 block discarded – undo
8 8
      *
9 9
      * @return array|null
10 10
      */
11
-    public function check( ?array $tmp = [] ): ?array {
11
+    public function check(?array $tmp = []): ?array {
12 12
         $fileType = [];
13 13
 
14
-        if ( isset( $tmp[ 0 ] ) ) {
15
-            preg_match( '|<xliff.*?\sversion\s?=\s?["\'](.*?)["\']|si', substr( $tmp[ 0 ], 0, 1000 ), $versionMatches );
16
-            preg_match( '|<xliff.*?\sxmlns\s?=\s?["\']urn:oasis:names:tc:xliff:document:(.*?)["\']|si', substr( $tmp[ 0 ], 0, 1000 ), $xmlnsMatches );
14
+        if (isset($tmp[0])) {
15
+            preg_match('|<xliff.*?\sversion\s?=\s?["\'](.*?)["\']|si', substr($tmp[0], 0, 1000), $versionMatches);
16
+            preg_match('|<xliff.*?\sxmlns\s?=\s?["\']urn:oasis:names:tc:xliff:document:(.*?)["\']|si', substr($tmp[0], 0, 1000), $xmlnsMatches);
17 17
 
18
-            if ( !empty( $versionMatches ) && !empty( $xmlnsMatches ) ) {
19
-                $version = $versionMatches[ 1 ];
20
-                $xmlns   = $xmlnsMatches[ 1 ];
18
+            if (!empty($versionMatches) && !empty($xmlnsMatches)) {
19
+                $version = $versionMatches[1];
20
+                $xmlns   = $xmlnsMatches[1];
21 21
 
22
-                if ( $version === $xmlns && $version >= 2 ) {
23
-                    $fileType[ 'proprietary' ]            = false;
24
-                    $fileType[ 'proprietary_name' ]       = 'Xliff v' . $version . ' File';
25
-                    $fileType[ 'proprietary_short_name' ] = 'xliff_v2';
26
-                    $fileType[ 'converter_version' ]      = '2.0';
22
+                if ($version === $xmlns && $version >= 2) {
23
+                    $fileType['proprietary']            = false;
24
+                    $fileType['proprietary_name']       = 'Xliff v' . $version . ' File';
25
+                    $fileType['proprietary_short_name'] = 'xliff_v2';
26
+                    $fileType['converter_version']      = '2.0';
27 27
 
28 28
                     return $fileType;
29 29
                 }
Please login to merge, or discard this patch.
src/XliffUtils/CheckPipeline/CheckInterface.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,5 +8,5 @@
 block discarded – undo
8 8
      *
9 9
      * @return array|null
10 10
      */
11
-    public function check( ?array $tmp = [] ): ?array;
11
+    public function check(?array $tmp = []): ?array;
12 12
 }
Please login to merge, or discard this patch.
src/XliffUtils/XliffVersionDetector.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -9,12 +9,12 @@  discard block
 block discarded – undo
9 9
     /**
10 10
      * @var array
11 11
      */
12
-    private static array $versions_1 = [ '1.0', '1.1', '1.2' ];
12
+    private static array $versions_1 = ['1.0', '1.1', '1.2'];
13 13
 
14 14
     /**
15 15
      * @var array
16 16
      */
17
-    private static array $versions_2 = [ '2.0', '2.1' ];
17
+    private static array $versions_2 = ['2.0', '2.1'];
18 18
 
19 19
     /**
20 20
      * @param string $xliffContent
@@ -23,16 +23,16 @@  discard block
 block discarded – undo
23 23
      * @throws NotSupportedVersionException
24 24
      * @throws NotValidFileException
25 25
      */
26
-    public static function detect( string $xliffContent ): int {
27
-        preg_match( '|<xliff.*?\sversion\s?=\s?["\'](.*?)["\']|si', substr( $xliffContent, 0, 1000 ), $versionMatches );
26
+    public static function detect(string $xliffContent): int {
27
+        preg_match('|<xliff.*?\sversion\s?=\s?["\'](.*?)["\']|si', substr($xliffContent, 0, 1000), $versionMatches);
28 28
 
29
-        if ( empty( $versionMatches ) ) {
30
-            throw new NotValidFileException( 'This is not a valid xliff file' );
29
+        if (empty($versionMatches)) {
30
+            throw new NotValidFileException('This is not a valid xliff file');
31 31
         }
32 32
 
33
-        $version = $versionMatches[ 1 ];
33
+        $version = $versionMatches[1];
34 34
 
35
-        return self::resolveVersion( $version );
35
+        return self::resolveVersion($version);
36 36
     }
37 37
 
38 38
     /**
@@ -41,15 +41,15 @@  discard block
 block discarded – undo
41 41
      * @return int
42 42
      * @throws NotSupportedVersionException
43 43
      */
44
-    private static function resolveVersion( string $version ): int {
45
-        if ( in_array( $version, self::$versions_1 ) ) {
44
+    private static function resolveVersion(string $version): int {
45
+        if (in_array($version, self::$versions_1)) {
46 46
             return 1;
47 47
         }
48 48
 
49
-        if ( in_array( $version, self::$versions_2 ) ) {
49
+        if (in_array($version, self::$versions_2)) {
50 50
             return 2;
51 51
         }
52 52
 
53
-        throw new NotSupportedVersionException( 'Not supported version' );
53
+        throw new NotSupportedVersionException('Not supported version');
54 54
     }
55 55
 }
Please login to merge, or discard this patch.
src/XliffUtils/XliffProprietaryDetect.php 1 patch
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -22,11 +22,11 @@  discard block
 block discarded – undo
22 22
      *
23 23
      * @return array
24 24
      */
25
-    public static function getInfoFromXliffContent( string $xliffContent ): array {
25
+    public static function getInfoFromXliffContent(string $xliffContent): array {
26 26
         self::reset();
27
-        $tmp = self::getFirst1024CharsFromXliff( $xliffContent, null );
27
+        $tmp = self::getFirst1024CharsFromXliff($xliffContent, null);
28 28
 
29
-        return self::getInfoFromTmp( $tmp );
29
+        return self::getInfoFromTmp($tmp);
30 30
     }
31 31
 
32 32
     /**
@@ -34,12 +34,12 @@  discard block
 block discarded – undo
34 34
      *
35 35
      * @return array
36 36
      */
37
-    public static function getInfo( string $fullPathToFile ): array {
37
+    public static function getInfo(string $fullPathToFile): array {
38 38
         self::reset();
39
-        $tmp                      = self::getFirst1024CharsFromXliff( null, $fullPathToFile );
40
-        self::$fileType[ 'info' ] = Files::pathInfo( $fullPathToFile );
39
+        $tmp                      = self::getFirst1024CharsFromXliff(null, $fullPathToFile);
40
+        self::$fileType['info'] = Files::pathInfo($fullPathToFile);
41 41
 
42
-        return self::getInfoFromTmp( $tmp );
42
+        return self::getInfoFromTmp($tmp);
43 43
     }
44 44
 
45 45
     /**
@@ -47,21 +47,21 @@  discard block
 block discarded – undo
47 47
      *
48 48
      * @return array
49 49
      */
50
-    private static function getInfoFromTmp( ?array $tmp = [] ): array {
50
+    private static function getInfoFromTmp(?array $tmp = []): array {
51 51
         try {
52
-            self::checkVersion( $tmp );
53
-        } catch ( Exception $ignore ) {
52
+            self::checkVersion($tmp);
53
+        } catch (Exception $ignore) {
54 54
             // do nothing
55 55
             // self::$fileType[ 'version' ] is left empty
56 56
         }
57 57
 
58 58
         // run CheckXliffProprietaryPipeline
59
-        $pipeline = self::runPipeline( $tmp );
59
+        $pipeline = self::runPipeline($tmp);
60 60
 
61
-        self::$fileType[ 'proprietary' ]            = $pipeline[ 'proprietary' ];
62
-        self::$fileType[ 'proprietary_name' ]       = $pipeline[ 'proprietary_name' ];
63
-        self::$fileType[ 'proprietary_short_name' ] = $pipeline[ 'proprietary_short_name' ];
64
-        self::$fileType[ 'converter_version' ]      = $pipeline[ 'converter_version' ];
61
+        self::$fileType['proprietary']            = $pipeline['proprietary'];
62
+        self::$fileType['proprietary_name']       = $pipeline['proprietary_name'];
63
+        self::$fileType['proprietary_short_name'] = $pipeline['proprietary_short_name'];
64
+        self::$fileType['converter_version']      = $pipeline['converter_version'];
65 65
 
66 66
         return self::$fileType;
67 67
     }
@@ -71,12 +71,12 @@  discard block
 block discarded – undo
71 71
      *
72 72
      * @return array
73 73
      */
74
-    private static function runPipeline( ?array $tmp = [] ): array {
75
-        $pipeline = new CheckXliffProprietaryPipeline( $tmp );
76
-        $pipeline->addCheck( new CheckSDL() );
77
-        $pipeline->addCheck( new CheckGlobalSight() );
78
-        $pipeline->addCheck( new CheckMateCATConverter() );
79
-        $pipeline->addCheck( new CheckXliffVersion2() );
74
+    private static function runPipeline(?array $tmp = []): array {
75
+        $pipeline = new CheckXliffProprietaryPipeline($tmp);
76
+        $pipeline->addCheck(new CheckSDL());
77
+        $pipeline->addCheck(new CheckGlobalSight());
78
+        $pipeline->addCheck(new CheckMateCATConverter());
79
+        $pipeline->addCheck(new CheckXliffVersion2());
80 80
 
81 81
         return $pipeline->run();
82 82
     }
@@ -99,29 +99,29 @@  discard block
 block discarded – undo
99 99
      *
100 100
      * @return ?array
101 101
      */
102
-    private static function getFirst1024CharsFromXliff( ?string $stringData = null, string $fullPathToFile = null ): ?array {
103
-        if ( !empty( $stringData ) && empty( $fullPathToFile ) ) {
102
+    private static function getFirst1024CharsFromXliff(?string $stringData = null, string $fullPathToFile = null): ?array {
103
+        if (!empty($stringData) && empty($fullPathToFile)) {
104 104
             $pathInfo   = [];
105
-            $stringData = substr( $stringData, 0, 1024 );
106
-        } elseif ( empty( $stringData ) && !empty( $fullPathToFile ) ) {
107
-            $pathInfo = Files::pathInfo( $fullPathToFile );
105
+            $stringData = substr($stringData, 0, 1024);
106
+        } elseif (empty($stringData) && !empty($fullPathToFile)) {
107
+            $pathInfo = Files::pathInfo($fullPathToFile);
108 108
 
109
-            if ( is_file( $fullPathToFile ) ) {
110
-                $file_pointer = fopen( "$fullPathToFile", 'r' );
109
+            if (is_file($fullPathToFile)) {
110
+                $file_pointer = fopen("$fullPathToFile", 'r');
111 111
                 // Checking Requirements (By specs, I know that xliff version is in the first 1KB)
112
-                $stringData = fread( $file_pointer, 1024 );
113
-                fclose( $file_pointer );
112
+                $stringData = fread($file_pointer, 1024);
113
+                fclose($file_pointer);
114 114
             }
115
-        } elseif ( !empty( $stringData ) && !empty( $fullPathToFile ) ) {
116
-            $pathInfo = Files::pathInfo( $fullPathToFile );
115
+        } elseif (!empty($stringData) && !empty($fullPathToFile)) {
116
+            $pathInfo = Files::pathInfo($fullPathToFile);
117 117
         }
118 118
 
119
-        if ( !empty( $pathInfo ) && !Files::isXliff( $fullPathToFile ) ) {
119
+        if (!empty($pathInfo) && !Files::isXliff($fullPathToFile)) {
120 120
             return null;
121 121
         }
122 122
 
123
-        if ( !empty( $stringData ) ) {
124
-            return [ $stringData ];
123
+        if (!empty($stringData)) {
124
+            return [$stringData];
125 125
         }
126 126
 
127 127
         return null;
@@ -133,9 +133,9 @@  discard block
 block discarded – undo
133 133
      * @throws NotSupportedVersionException
134 134
      * @throws NotValidFileException
135 135
      */
136
-    protected static function checkVersion( $tmp ) {
137
-        if ( isset( $tmp[ 0 ] ) ) {
138
-            self::$fileType[ 'version' ] = XliffVersionDetector::detect( $tmp[ 0 ] );
136
+    protected static function checkVersion($tmp) {
137
+        if (isset($tmp[0])) {
138
+            self::$fileType['version'] = XliffVersionDetector::detect($tmp[0]);
139 139
         }
140 140
     }
141 141
 
@@ -146,20 +146,20 @@  discard block
 block discarded – undo
146 146
      * @throws NotSupportedVersionException
147 147
      * @throws NotValidFileException
148 148
      */
149
-    public static function getInfoByStringData( string $stringData ): array {
149
+    public static function getInfoByStringData(string $stringData): array {
150 150
         self::reset();
151 151
 
152
-        $tmp                      = self::getFirst1024CharsFromXliff( $stringData );
153
-        self::$fileType[ 'info' ] = [];
154
-        self::checkVersion( $tmp );
152
+        $tmp                      = self::getFirst1024CharsFromXliff($stringData);
153
+        self::$fileType['info'] = [];
154
+        self::checkVersion($tmp);
155 155
 
156 156
         // run CheckXliffProprietaryPipeline
157
-        $pipeline = self::runPipeline( $tmp );
157
+        $pipeline = self::runPipeline($tmp);
158 158
 
159
-        self::$fileType[ 'proprietary' ]            = $pipeline[ 'proprietary' ];
160
-        self::$fileType[ 'proprietary_name' ]       = $pipeline[ 'proprietary_name' ];
161
-        self::$fileType[ 'proprietary_short_name' ] = $pipeline[ 'proprietary_short_name' ];
162
-        self::$fileType[ 'converter_version' ]      = $pipeline[ 'converter_version' ];
159
+        self::$fileType['proprietary']            = $pipeline['proprietary'];
160
+        self::$fileType['proprietary_name']       = $pipeline['proprietary_name'];
161
+        self::$fileType['proprietary_short_name'] = $pipeline['proprietary_short_name'];
162
+        self::$fileType['converter_version']      = $pipeline['converter_version'];
163 163
 
164 164
         return self::$fileType;
165 165
     }
@@ -171,21 +171,21 @@  discard block
 block discarded – undo
171 171
      *
172 172
      * @return bool|int
173 173
      */
174
-    public static function fileMustBeConverted( string $fullPath, ?bool $enforceOnXliff = false, ?string $filterAddress = null ) {
174
+    public static function fileMustBeConverted(string $fullPath, ?bool $enforceOnXliff = false, ?string $filterAddress = null) {
175 175
         $convert = true;
176 176
 
177
-        $fileType       = self::getInfo( $fullPath );
178
-        $memoryFileType = Files::getMemoryFileType( $fullPath );
177
+        $fileType       = self::getInfo($fullPath);
178
+        $memoryFileType = Files::getMemoryFileType($fullPath);
179 179
 
180
-        if ( Files::isXliff( $fullPath ) || $memoryFileType ) {
181
-            if ( !empty( $filterAddress ) ) {
180
+        if (Files::isXliff($fullPath) || $memoryFileType) {
181
+            if (!empty($filterAddress)) {
182 182
 
183 183
                 //conversion enforce
184
-                if ( !$enforceOnXliff ) {
184
+                if (!$enforceOnXliff) {
185 185
 
186 186
                     //if file is not proprietary AND Enforce is disabled
187 187
                     //we take it as is
188
-                    if ( !$fileType[ 'proprietary' ] || $memoryFileType ) {
188
+                    if (!$fileType['proprietary'] || $memoryFileType) {
189 189
                         $convert = false;
190 190
                         //ok don't convert a standard sdlxliff
191 191
                     }
@@ -193,16 +193,16 @@  discard block
 block discarded – undo
193 193
                     //if conversion enforce is active
194 194
                     //we force all xliff files but not files produced by SDL Studio because we can handle them
195 195
                     if (
196
-                            $fileType[ 'proprietary_short_name' ] == 'matecat_converter'
197
-                            || $fileType[ 'proprietary_short_name' ] == 'trados'
198
-                            || $fileType[ 'proprietary_short_name' ] == 'xliff_v2'
196
+                            $fileType['proprietary_short_name'] == 'matecat_converter'
197
+                            || $fileType['proprietary_short_name'] == 'trados'
198
+                            || $fileType['proprietary_short_name'] == 'xliff_v2'
199 199
                             || $memoryFileType
200 200
                     ) {
201 201
                         $convert = false;
202 202
                         //ok don't convert a standard sdlxliff
203 203
                     }
204 204
                 }
205
-            } elseif ( $fileType[ 'proprietary' ] ) {
205
+            } elseif ($fileType['proprietary']) {
206 206
 
207 207
                 /**
208 208
                  * Application misconfiguration.
Please login to merge, or discard this patch.
src/XliffReplacer/AbstractXliffReplacer.php 1 patch
Spacing   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -7,27 +7,27 @@  discard block
 block discarded – undo
7 7
 
8 8
 abstract class AbstractXliffReplacer {
9 9
     protected $originalFP;
10
-    protected $outputFP;                  // output stream pointer
10
+    protected $outputFP; // output stream pointer
11 11
 
12
-    protected string $tuTagName;                 // <trans-unit> (forXliff v 1.*) or <unit> (forXliff v 2.*)
13
-    protected bool   $inTU             = false;  // flag to check whether we are in a <trans-unit>
14
-    protected bool   $inTarget         = false;  // flag to check whether we are in a <target>, to ignore everything
15
-    protected bool   $isEmpty          = false;  // flag to check whether we are in an empty tag (<tag/>)
16
-    protected bool   $targetWasWritten = false;  // flag to check is <target> was written in the current unit
17
-    protected string $CDATABuffer      = "";       // buffer for special tag
18
-    protected bool   $bufferIsActive   = false;    // buffer for special tag
12
+    protected string $tuTagName; // <trans-unit> (forXliff v 1.*) or <unit> (forXliff v 2.*)
13
+    protected bool   $inTU             = false; // flag to check whether we are in a <trans-unit>
14
+    protected bool   $inTarget         = false; // flag to check whether we are in a <target>, to ignore everything
15
+    protected bool   $isEmpty          = false; // flag to check whether we are in an empty tag (<tag/>)
16
+    protected bool   $targetWasWritten = false; // flag to check is <target> was written in the current unit
17
+    protected string $CDATABuffer      = ""; // buffer for special tag
18
+    protected bool   $bufferIsActive   = false; // buffer for special tag
19 19
 
20
-    protected int $offset = 0;         // offset for SAX pointer
20
+    protected int $offset = 0; // offset for SAX pointer
21 21
 
22
-    protected string  $currentBuffer;             // the current piece of text it's been parsed
23
-    protected int     $len;                       // length of the currentBuffer
24
-    protected array   $segments;                  // array of translations
22
+    protected string  $currentBuffer; // the current piece of text it's been parsed
23
+    protected int     $len; // length of the currentBuffer
24
+    protected array   $segments; // array of translations
25 25
     protected array   $lastTransUnit                  = [];
26 26
     protected int     $segmentInUnitPosition          = 0;
27
-    protected ?string $currentTransUnitId             = null;        // id of current <trans-unit>
27
+    protected ?string $currentTransUnitId             = null; // id of current <trans-unit>
28 28
     protected ?string $currentTransUnitIsTranslatable = null; // 'translate' attribute of current <trans-unit>
29
-    protected bool    $unitContainsMda                = false;   // check if <unit> already contains a <mda:metadata> (forXliff v 2.*)
30
-    protected bool    $hasWrittenCounts               = false;  // check if <unit> already wrote segment counts (forXliff v 2.*)
29
+    protected bool    $unitContainsMda                = false; // check if <unit> already contains a <mda:metadata> (forXliff v 2.*)
30
+    protected bool    $hasWrittenCounts               = false; // check if <unit> already wrote segment counts (forXliff v 2.*)
31 31
     protected string  $targetLang;
32 32
     protected bool    $sourceInTarget                 = false;
33 33
 
@@ -77,10 +77,10 @@  discard block
 block discarded – undo
77 77
             XliffReplacerCallbackInterface $callback = null
78 78
     ) {
79 79
         self::$INTERNAL_TAG_PLACEHOLDER = $this->getInternalTagPlaceholder();
80
-        $this->createOutputFileIfDoesNotExist( $outputFilePath );
81
-        $this->setFileDescriptors( $originalXliffPath, $outputFilePath );
80
+        $this->createOutputFileIfDoesNotExist($outputFilePath);
81
+        $this->setFileDescriptors($originalXliffPath, $outputFilePath);
82 82
         $this->xliffVersion   = $xliffVersion;
83
-        $this->tuTagName      = ( $this->xliffVersion === 2 ) ? 'unit' : 'trans-unit';
83
+        $this->tuTagName      = ($this->xliffVersion === 2) ? 'unit' : 'trans-unit';
84 84
         $this->segments       = $segments;
85 85
         $this->targetLang     = $trgLang;
86 86
         $this->sourceInTarget = $setSourceInTarget;
@@ -90,17 +90,17 @@  discard block
 block discarded – undo
90 90
     }
91 91
 
92 92
     public function replaceTranslation() {
93
-        fwrite( $this->outputFP, '<?xml version="1.0" encoding="UTF-8"?>' );
93
+        fwrite($this->outputFP, '<?xml version="1.0" encoding="UTF-8"?>');
94 94
 
95 95
         //create Sax parser
96 96
         $xmlParser = $this->initSaxParser();
97 97
 
98
-        while ( $this->currentBuffer = fread( $this->originalFP, 4096 ) ) {
98
+        while ($this->currentBuffer = fread($this->originalFP, 4096)) {
99 99
             /*
100 100
                preprocess file
101 101
              */
102 102
             // obfuscate entities because sax automatically does html_entity_decode
103
-            $temporary_check_buffer = preg_replace( "/&(.*?);/", self::$INTERNAL_TAG_PLACEHOLDER . '$1' . self::$INTERNAL_TAG_PLACEHOLDER, $this->currentBuffer );
103
+            $temporary_check_buffer = preg_replace("/&(.*?);/", self::$INTERNAL_TAG_PLACEHOLDER . '$1' . self::$INTERNAL_TAG_PLACEHOLDER, $this->currentBuffer);
104 104
 
105 105
             //avoid cutting entities in half:
106 106
             //the last fread could have truncated an entity (say, '&lt;' in '&l'), thus invalidating the escaping
@@ -108,36 +108,36 @@  discard block
 block discarded – undo
108 108
             // 9 is the max length of an entity. So, suppose that the & is at the end of buffer,
109 109
             // add 9 Bytes and substitute the entities, if the & is present, and it is not at the end
110 110
             //it can't be an entity, exit the loop
111
-            while ( true ) {
112
-                $_ampPos = strpos( $temporary_check_buffer, '&' );
111
+            while (true) {
112
+                $_ampPos = strpos($temporary_check_buffer, '&');
113 113
 
114 114
                 //check for real entity or escape it to safely exit from the loop!!!
115
-                if ( $_ampPos === false || strlen( substr( $temporary_check_buffer, $_ampPos ) ) > 9 ) {
115
+                if ($_ampPos === false || strlen(substr($temporary_check_buffer, $_ampPos)) > 9) {
116 116
                     break;
117 117
                 }
118 118
 
119 119
                 //if an entity is still present, fetch some more and repeat the escaping
120
-                $this->currentBuffer    .= fread( $this->originalFP, 9 );
121
-                $temporary_check_buffer = preg_replace( "/&(.*?);/", self::$INTERNAL_TAG_PLACEHOLDER . '$1' . self::$INTERNAL_TAG_PLACEHOLDER, $this->currentBuffer );
120
+                $this->currentBuffer .= fread($this->originalFP, 9);
121
+                $temporary_check_buffer = preg_replace("/&(.*?);/", self::$INTERNAL_TAG_PLACEHOLDER . '$1' . self::$INTERNAL_TAG_PLACEHOLDER, $this->currentBuffer);
122 122
             }
123 123
 
124 124
             //free stuff outside the loop
125
-            unset( $temporary_check_buffer );
125
+            unset($temporary_check_buffer);
126 126
 
127
-            $this->currentBuffer = preg_replace( "/&(.*?);/", self::$INTERNAL_TAG_PLACEHOLDER . '$1' . self::$INTERNAL_TAG_PLACEHOLDER, $this->currentBuffer );
128
-            $this->currentBuffer = str_replace( "&", self::$INTERNAL_TAG_PLACEHOLDER . 'amp' . self::$INTERNAL_TAG_PLACEHOLDER, $this->currentBuffer );
127
+            $this->currentBuffer = preg_replace("/&(.*?);/", self::$INTERNAL_TAG_PLACEHOLDER . '$1' . self::$INTERNAL_TAG_PLACEHOLDER, $this->currentBuffer);
128
+            $this->currentBuffer = str_replace("&", self::$INTERNAL_TAG_PLACEHOLDER . 'amp' . self::$INTERNAL_TAG_PLACEHOLDER, $this->currentBuffer);
129 129
 
130 130
             //get length of chunk
131
-            $this->len = strlen( $this->currentBuffer );
131
+            $this->len = strlen($this->currentBuffer);
132 132
 
133 133
             //parse chunk of text
134
-            if ( !xml_parse( $xmlParser, $this->currentBuffer, feof( $this->originalFP ) ) ) {
134
+            if (!xml_parse($xmlParser, $this->currentBuffer, feof($this->originalFP))) {
135 135
                 //if unable, raise an exception
136
-                throw new RuntimeException( sprintf(
136
+                throw new RuntimeException(sprintf(
137 137
                         "XML error: %s at line %d",
138
-                        xml_error_string( xml_get_error_code( $xmlParser ) ),
139
-                        xml_get_current_line_number( $xmlParser )
140
-                ) );
138
+                        xml_error_string(xml_get_error_code($xmlParser)),
139
+                        xml_get_current_line_number($xmlParser)
140
+                ));
141 141
             }
142 142
             /*
143 143
             * Get the accumulated this->offset in the document:
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
         }
149 149
 
150 150
         // close Sax parser
151
-        $this->closeSaxParser( $xmlParser );
151
+        $this->closeSaxParser($xmlParser);
152 152
 
153 153
     }
154 154
 
@@ -157,24 +157,24 @@  discard block
 block discarded – undo
157 157
      *
158 158
      * @return string
159 159
      */
160
-    protected function getLastCharacter( $parser ): string {
160
+    protected function getLastCharacter($parser): string {
161 161
 
162 162
         //this logic helps detecting empty tags
163 163
         //get current position of SAX pointer in all the stream of data is has read so far:
164 164
         //it points at the end of current tag
165
-        $idx = xml_get_current_byte_index( $parser );
165
+        $idx = xml_get_current_byte_index($parser);
166 166
 
167 167
         //check whether the bounds of current tag are entirely in current buffer or the end of the current tag
168 168
         //is outside current buffer (in the latter case, it's in next buffer to be read by the while loop);
169 169
         //this check is necessary because we may have truncated a tag in half with current read,
170 170
         //and the other half may be encountered in the next buffer it will be passed
171
-        if ( isset( $this->currentBuffer[ $idx - $this->offset ] ) ) {
171
+        if (isset($this->currentBuffer[$idx - $this->offset])) {
172 172
             //if this tag entire lenght fitted in the buffer, the last char must be the last
173 173
             //symbol before the '>'; if it's an empty tag, it is assumed that it's a '/'
174
-            $lastChar = $this->currentBuffer[ $idx - $this->offset ];
174
+            $lastChar = $this->currentBuffer[$idx - $this->offset];
175 175
         } else {
176 176
             //if it's out, simple use the last character of the chunk
177
-            $lastChar = $this->currentBuffer[ $this->len - 1 ];
177
+            $lastChar = $this->currentBuffer[$this->len - 1];
178 178
         }
179 179
 
180 180
         return $lastChar;
@@ -188,19 +188,19 @@  discard block
 block discarded – undo
188 188
         return "§" .
189 189
                 substr(
190 190
                         str_replace(
191
-                                [ '+', '/' ],
191
+                                ['+', '/'],
192 192
                                 '',
193
-                                base64_encode( openssl_random_pseudo_bytes( 10, $_crypto_strong ) )
193
+                                base64_encode(openssl_random_pseudo_bytes(10, $_crypto_strong))
194 194
                         ),
195 195
                         0,
196 196
                         4
197 197
                 );
198 198
     }
199 199
 
200
-    private function createOutputFileIfDoesNotExist( string $outputFilePath ) {
200
+    private function createOutputFileIfDoesNotExist(string $outputFilePath) {
201 201
         // create output file
202
-        if ( !file_exists( $outputFilePath ) ) {
203
-            touch( $outputFilePath );
202
+        if (!file_exists($outputFilePath)) {
203
+            touch($outputFilePath);
204 204
         }
205 205
     }
206 206
 
@@ -208,13 +208,13 @@  discard block
 block discarded – undo
208 208
      * @param string $originalXliffPath
209 209
      * @param string $outputFilePath
210 210
      */
211
-    private function setFileDescriptors( string $originalXliffPath, string $outputFilePath ) {
212
-        $this->outputFP = fopen( $outputFilePath, 'w+' );
211
+    private function setFileDescriptors(string $originalXliffPath, string $outputFilePath) {
212
+        $this->outputFP = fopen($outputFilePath, 'w+');
213 213
 
214 214
         $streamArgs = null;
215 215
 
216
-        if ( !( $this->originalFP = fopen( $originalXliffPath, "r", false, stream_context_create( $streamArgs ) ) ) ) {
217
-            throw new RuntimeException( "could not open XML input" );
216
+        if (!($this->originalFP = fopen($originalXliffPath, "r", false, stream_context_create($streamArgs)))) {
217
+            throw new RuntimeException("could not open XML input");
218 218
         }
219 219
     }
220 220
 
@@ -224,8 +224,8 @@  discard block
 block discarded – undo
224 224
     public function __destruct() {
225 225
         //this stream can be closed outside the class
226 226
         //to permit multiple concurrent downloads, so suppress warnings
227
-        @fclose( $this->originalFP );
228
-        fclose( $this->outputFP );
227
+        @fclose($this->originalFP);
228
+        fclose($this->outputFP);
229 229
     }
230 230
 
231 231
     /**
@@ -234,11 +234,11 @@  discard block
 block discarded – undo
234 234
      * @return resource
235 235
      */
236 236
     protected function initSaxParser() {
237
-        $xmlSaxParser = xml_parser_create( 'UTF-8' );
238
-        xml_set_object( $xmlSaxParser, $this );
239
-        xml_parser_set_option( $xmlSaxParser, XML_OPTION_CASE_FOLDING, false );
240
-        xml_set_element_handler( $xmlSaxParser, 'tagOpen', 'tagClose' );
241
-        xml_set_character_data_handler( $xmlSaxParser, 'characterData' );
237
+        $xmlSaxParser = xml_parser_create('UTF-8');
238
+        xml_set_object($xmlSaxParser, $this);
239
+        xml_parser_set_option($xmlSaxParser, XML_OPTION_CASE_FOLDING, false);
240
+        xml_set_element_handler($xmlSaxParser, 'tagOpen', 'tagClose');
241
+        xml_set_character_data_handler($xmlSaxParser, 'characterData');
242 242
 
243 243
         return $xmlSaxParser;
244 244
     }
@@ -246,8 +246,8 @@  discard block
 block discarded – undo
246 246
     /**
247 247
      * @param resource $xmlSaxParser
248 248
      */
249
-    protected function closeSaxParser( $xmlSaxParser ) {
250
-        xml_parser_free( $xmlSaxParser );
249
+    protected function closeSaxParser($xmlSaxParser) {
250
+        xml_parser_free($xmlSaxParser);
251 251
     }
252 252
 
253 253
     /**
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
      *
258 258
      * @return mixed
259 259
      */
260
-    abstract protected function tagOpen( $parser, string $name, array $attr );
260
+    abstract protected function tagOpen($parser, string $name, array $attr);
261 261
 
262 262
     /**
263 263
      * @param resource $parser
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
      *
266 266
      * @return mixed
267 267
      */
268
-    abstract protected function tagClose( $parser, string $name );
268
+    abstract protected function tagClose($parser, string $name);
269 269
 
270 270
     /**
271 271
      * @param resource $parser
@@ -273,11 +273,11 @@  discard block
 block discarded – undo
273 273
      *
274 274
      * @return mixed
275 275
      */
276
-    protected function characterData( $parser, string $data ): void {
276
+    protected function characterData($parser, string $data): void {
277 277
         // don't write <target> data
278
-        if ( !$this->inTarget && !$this->bufferIsActive ) {
279
-            $this->postProcAndFlush( $this->outputFP, $data );
280
-        } elseif ( $this->bufferIsActive ) {
278
+        if (!$this->inTarget && !$this->bufferIsActive) {
279
+            $this->postProcAndFlush($this->outputFP, $data);
280
+        } elseif ($this->bufferIsActive) {
281 281
             $this->CDATABuffer .= $data;
282 282
         }
283 283
     }
@@ -289,19 +289,19 @@  discard block
 block discarded – undo
289 289
      * @param string   $data
290 290
      * @param ?bool    $treatAsCDATA
291 291
      */
292
-    protected function postProcAndFlush( $fp, string $data, ?bool $treatAsCDATA = false ) {
292
+    protected function postProcAndFlush($fp, string $data, ?bool $treatAsCDATA = false) {
293 293
         //postprocess string
294
-        $data = preg_replace( "/" . self::$INTERNAL_TAG_PLACEHOLDER . '(.*?)' . self::$INTERNAL_TAG_PLACEHOLDER . "/", '&$1;', $data );
295
-        $data = str_replace( '&nbsp;', ' ', $data );
296
-        if ( !$treatAsCDATA ) {
294
+        $data = preg_replace("/" . self::$INTERNAL_TAG_PLACEHOLDER . '(.*?)' . self::$INTERNAL_TAG_PLACEHOLDER . "/", '&$1;', $data);
295
+        $data = str_replace('&nbsp;', ' ', $data);
296
+        if (!$treatAsCDATA) {
297 297
             //unix2dos
298
-            $data = str_replace( "\r\n", "\r", $data );
299
-            $data = str_replace( "\n", "\r", $data );
300
-            $data = str_replace( "\r", "\r\n", $data );
298
+            $data = str_replace("\r\n", "\r", $data);
299
+            $data = str_replace("\n", "\r", $data);
300
+            $data = str_replace("\r", "\r\n", $data);
301 301
         }
302 302
 
303 303
         //flush to disk
304
-        fwrite( $fp, $data );
304
+        fwrite($fp, $data);
305 305
     }
306 306
 
307 307
     /**
@@ -310,19 +310,19 @@  discard block
 block discarded – undo
310 310
      *
311 311
      * @return void
312 312
      */
313
-    protected function handleOpenUnit( string $name, array $attr ) {
313
+    protected function handleOpenUnit(string $name, array $attr) {
314 314
 
315 315
         // check if we are entering into a <trans-unit> (xliff v1.*) or <unit> (xliff v2.*)
316
-        if ( $this->tuTagName === $name ) {
316
+        if ($this->tuTagName === $name) {
317 317
             $this->inTU = true;
318 318
 
319 319
             // get id
320 320
             // trim to first 100 characters because this is the limit on Matecat's DB
321
-            $this->currentTransUnitId = substr( $attr[ 'id' ], 0, 100 );
321
+            $this->currentTransUnitId = substr($attr['id'], 0, 100);
322 322
 
323 323
             // `translate` attribute can be only yes or no
324 324
             // current 'translate' attribute of the current trans-unit
325
-            $this->currentTransUnitIsTranslatable = empty( $attr[ 'translate' ] ) ? 'yes' : $attr[ 'translate' ];
325
+            $this->currentTransUnitIsTranslatable = empty($attr['translate']) ? 'yes' : $attr['translate'];
326 326
 
327 327
             $this->setLastTransUnitSegments();
328 328
 
@@ -336,15 +336,15 @@  discard block
 block discarded – undo
336 336
      *
337 337
      * @return string
338 338
      */
339
-    protected function handleOpenXliffTag( string $name, array $attr, string $tag ): string {
339
+    protected function handleOpenXliffTag(string $name, array $attr, string $tag): string {
340 340
 
341 341
         // Add MateCat specific namespace.
342 342
         // Add trgLang
343
-        if ( $name === 'xliff' ) {
344
-            if ( !array_key_exists( 'xmlns:mtc', $attr ) ) {
343
+        if ($name === 'xliff') {
344
+            if (!array_key_exists('xmlns:mtc', $attr)) {
345 345
                 $tag .= ' xmlns:mtc="https://www.matecat.com" ';
346 346
             }
347
-            $tag = preg_replace( '/trgLang="(.*?)"/', 'trgLang="' . $this->targetLang . '"', $tag );
347
+            $tag = preg_replace('/trgLang="(.*?)"/', 'trgLang="' . $this->targetLang . '"', $tag);
348 348
         }
349 349
 
350 350
         return $tag;
@@ -356,10 +356,10 @@  discard block
 block discarded – undo
356 356
      *
357 357
      * @return void
358 358
      */
359
-    protected function checkSetInTarget( string $name ) {
359
+    protected function checkSetInTarget(string $name) {
360 360
         // check if we are entering into a <target>
361
-        if ( 'target' === $name ) {
362
-            if ( $this->currentTransUnitIsTranslatable === 'no' ) {
361
+        if ('target' === $name) {
362
+            if ($this->currentTransUnitIsTranslatable === 'no') {
363 363
                 $this->inTarget = false;
364 364
             } else {
365 365
                 $this->inTarget = true;
@@ -372,8 +372,8 @@  discard block
 block discarded – undo
372 372
      *
373 373
      * @return void
374 374
      */
375
-    protected function setInBuffer( string $name ) {
376
-        if ( in_array( $name, $this->nodesToBuffer ) ) {
375
+    protected function setInBuffer(string $name) {
376
+        if (in_array($name, $this->nodesToBuffer)) {
377 377
             $this->bufferIsActive = true;
378 378
         }
379 379
     }
@@ -381,24 +381,24 @@  discard block
 block discarded – undo
381 381
     /**
382 382
      * @param array $seg
383 383
      */
384
-    protected function updateSegmentCounts( array $seg = [] ) {
384
+    protected function updateSegmentCounts(array $seg = []) {
385 385
 
386
-        $raw_word_count = $seg[ 'raw_word_count' ];
387
-        $eq_word_count  = ( floor( $seg[ 'eq_word_count' ] * 100 ) / 100 );
386
+        $raw_word_count = $seg['raw_word_count'];
387
+        $eq_word_count  = (floor($seg['eq_word_count'] * 100) / 100);
388 388
 
389
-        $this->counts[ 'segments_count_array' ][ $seg[ 'sid' ] ] = [
389
+        $this->counts['segments_count_array'][$seg['sid']] = [
390 390
                 'raw_word_count' => $raw_word_count,
391 391
                 'eq_word_count'  => $eq_word_count,
392 392
         ];
393 393
 
394
-        $this->counts[ 'raw_word_count' ] += $raw_word_count;
395
-        $this->counts[ 'eq_word_count' ]  += $eq_word_count;
394
+        $this->counts['raw_word_count'] += $raw_word_count;
395
+        $this->counts['eq_word_count']  += $eq_word_count;
396 396
     }
397 397
 
398 398
     protected function resetCounts() {
399
-        $this->counts[ 'segments_count_array' ] = [];
400
-        $this->counts[ 'raw_word_count' ]       = 0;
401
-        $this->counts[ 'eq_word_count' ]        = 0;
399
+        $this->counts['segments_count_array'] = [];
400
+        $this->counts['raw_word_count']       = 0;
401
+        $this->counts['eq_word_count']        = 0;
402 402
     }
403 403
 
404 404
     /**
@@ -407,16 +407,16 @@  discard block
 block discarded – undo
407 407
      *
408 408
      * @return void
409 409
      */
410
-    protected function checkForSelfClosedTagAndFlush( $parser, string $tag ) {
410
+    protected function checkForSelfClosedTagAndFlush($parser, string $tag) {
411 411
 
412
-        $lastChar = $this->getLastCharacter( $parser );
412
+        $lastChar = $this->getLastCharacter($parser);
413 413
 
414 414
         //trim last space
415
-        $tag = rtrim( $tag );
415
+        $tag = rtrim($tag);
416 416
 
417 417
         //detect empty tag
418 418
         $this->isEmpty = $lastChar == '/';
419
-        if ( $this->isEmpty ) {
419
+        if ($this->isEmpty) {
420 420
             $tag .= $lastChar;
421 421
         }
422 422
 
@@ -424,11 +424,11 @@  discard block
 block discarded – undo
424 424
         $tag .= ">";
425 425
 
426 426
         //set a Buffer for the segSource Source tag
427
-        if ( $this->bufferIsActive ) { // we are opening a critical CDATA section
427
+        if ($this->bufferIsActive) { // we are opening a critical CDATA section
428 428
             //these are NOT source/seg-source/value empty tags, THERE IS A CONTENT, write it in buffer
429 429
             $this->CDATABuffer .= $tag;
430 430
         } else {
431
-            $this->postProcAndFlush( $this->outputFP, $tag );
431
+            $this->postProcAndFlush($this->outputFP, $tag);
432 432
         }
433 433
 
434 434
     }
@@ -453,18 +453,18 @@  discard block
 block discarded – undo
453 453
          */
454 454
         $this->lastTransUnit = [];
455 455
 
456
-        if ( !isset( $this->transUnits[ $this->currentTransUnitId ] ) ) {
456
+        if (!isset($this->transUnits[$this->currentTransUnitId])) {
457 457
             return;
458 458
         }
459 459
 
460
-        $listOfSegmentsIds = $this->transUnits[ $this->currentTransUnitId ];
460
+        $listOfSegmentsIds = $this->transUnits[$this->currentTransUnitId];
461 461
         $last_value        = null;
462
-        $segmentsCount     = count( $listOfSegmentsIds );
463
-        for ( $i = 0; $i < $segmentsCount; $i++ ) {
464
-            $id = $listOfSegmentsIds[ $i ];
465
-            if ( isset( $this->segments[ $id ] ) && ( $i == 0 || $last_value + 1 == $listOfSegmentsIds[ $i ] ) ) {
466
-                $last_value            = $listOfSegmentsIds[ $i ];
467
-                $this->lastTransUnit[] = $this->segments[ $id ];
462
+        $segmentsCount     = count($listOfSegmentsIds);
463
+        for ($i = 0; $i < $segmentsCount; $i++) {
464
+            $id = $listOfSegmentsIds[$i];
465
+            if (isset($this->segments[$id]) && ($i == 0 || $last_value + 1 == $listOfSegmentsIds[$i])) {
466
+                $last_value            = $listOfSegmentsIds[$i];
467
+                $this->lastTransUnit[] = $this->segments[$id];
468 468
             }
469 469
         }
470 470
 
@@ -474,8 +474,8 @@  discard block
 block discarded – undo
474 474
      * @return array
475 475
      */
476 476
     protected function getCurrentSegment(): array {
477
-        if ( $this->currentTransUnitIsTranslatable !== 'no' && isset( $this->transUnits[ $this->currentTransUnitId ] ) ) {
478
-            return $this->segments[ $this->segmentInUnitPosition ];
477
+        if ($this->currentTransUnitIsTranslatable !== 'no' && isset($this->transUnits[$this->currentTransUnitId])) {
478
+            return $this->segments[$this->segmentInUnitPosition];
479 479
         }
480 480
 
481 481
         return [];
Please login to merge, or discard this patch.
src/XliffReplacer/XliffReplacerFactory.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -28,14 +28,14 @@
 block discarded – undo
28 28
             ?LoggerInterface                $logger = null,
29 29
             ?XliffReplacerCallbackInterface $callback = null
30 30
     ): AbstractXliffReplacer {
31
-        $info = XliffProprietaryDetect::getInfo( $originalXliffPath );
31
+        $info = XliffProprietaryDetect::getInfo($originalXliffPath);
32 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 );
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 37
         }
38 38
 
39
-        return new XliffSdl( $originalXliffPath, $info[ 'version' ], $data, $transUnits, $targetLang, $outputFilePath, $setSourceInTarget, $logger, $callback );
39
+        return new XliffSdl($originalXliffPath, $info['version'], $data, $transUnits, $targetLang, $outputFilePath, $setSourceInTarget, $logger, $callback);
40 40
     }
41 41
 }
Please login to merge, or discard this patch.