CheckMateCATConverter::check()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 13
nc 4
nop 1
dl 0
loc 21
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
namespace Matecat\XliffParser\XliffUtils\CheckPipeline;
4
5
class CheckMateCATConverter 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( '#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
                } else {
23
                    // First converter release didn't specify version
24
                    $fileType[ 'converter_version' ] = '1.0';
25
                }
26
27
                return $fileType;
28
            }
29
        }
30
31
        return null;
32
33
    }
34
}
35