CheckXliffProprietaryPipeline   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 23
dl 0
loc 67
rs 10
c 2
b 1
f 0
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 9 1
A __construct() 0 3 1
A run() 0 19 5
A addCheck() 0 2 1
1
<?php
2
3
namespace Matecat\XliffParser\XliffUtils;
4
5
use Matecat\XliffParser\XliffUtils\CheckPipeline\CheckInterface;
6
7
class CheckXliffProprietaryPipeline {
8
    /**
9
     * @var array|null
10
     */
11
    private ?array $tmp;
12
13
    /**
14
     * @var array|null
15
     */
16
    private ?array $steps;
17
18
    /**
19
     * CheckXliffProprietaryPipeline constructor.
20
     *
21
     * @param array|null $tmp
22
     */
23
    public function __construct( ?array $tmp = [] ) {
24
        $this->tmp   = $tmp;
25
        $this->steps = [];
26
    }
27
28
    /**
29
     * @param CheckInterface $step
30
     */
31
    public function addCheck( CheckInterface $step ) {
32
        $this->steps[] = $step;
33
    }
34
35
    /**
36
     * @return array
37
     */
38
    public function run(): array {
39
        $fileType = [];
40
41
        /** @var CheckInterface $step */
42
        foreach ( $this->steps as $step ) {
43
            if ( null !== $step->check( $this->tmp ) ) {
44
                $fileType = $step->check( $this->tmp );
45
            }
46
        }
47
48
        if ( !empty( $fileType ) && $this->isValid( $fileType ) ) {
49
            return $fileType;
50
        }
51
52
        return [
53
                'proprietary'            => false,
54
                'proprietary_name'       => null,
55
                'proprietary_short_name' => null,
56
                'converter_version'      => null,
57
        ];
58
    }
59
60
    /**
61
     * @param $fileType
62
     *
63
     * @return bool
64
     */
65
    private function isValid( $fileType ): bool {
66
        $mandatoryKeys = [
67
                'proprietary',
68
                'proprietary_name',
69
                'proprietary_short_name',
70
                'converter_version',
71
        ];
72
73
        return array_keys( $fileType ) === $mandatoryKeys;
74
    }
75
}
76