CheckXliffVersion2   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
A check() 0 23 6
1
<?php
2
3
namespace Matecat\XliffParser\XliffUtils\CheckPipeline;
4
5
class CheckXliffVersion2 implements CheckInterface {
6
    /**
7
     * @param array|null $tmp
8
     *
9
     * @return array|null
10
     */
11
    public function check( ?array $tmp = [] ): ?array {
12
        $fileType = [];
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 );
17
18
            if ( !empty( $versionMatches ) && !empty( $xmlnsMatches ) ) {
19
                $version = $versionMatches[ 1 ];
20
                $xmlns   = $xmlnsMatches[ 1 ];
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';
27
28
                    return $fileType;
29
                }
30
            }
31
        }
32
33
        return null;
34
    }
35
}
36