Total Complexity | 14 |
Total Lines | 109 |
Duplicated Lines | 0 % |
Changes | 4 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
18 | trait FileHandlerTrait |
||
19 | { |
||
20 | /** |
||
21 | * @var resource |
||
22 | */ |
||
23 | protected $handle; |
||
24 | |||
25 | /** |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $encoding; |
||
29 | |||
30 | /** |
||
31 | * @var bool |
||
32 | */ |
||
33 | protected $useBom; |
||
34 | |||
35 | /** |
||
36 | * make sure we do not hold un-necessary handles |
||
37 | */ |
||
38 | public function __destruct() |
||
39 | { |
||
40 | $this->releaseHandle(); |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * @return string|null |
||
45 | */ |
||
46 | public function getEncoding(): ?string |
||
47 | { |
||
48 | return $this->encoding; |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * @param string $encoding |
||
53 | * |
||
54 | * @return static |
||
55 | */ |
||
56 | public function setEncoding(string $encoding): self |
||
57 | { |
||
58 | $this->encoding = $encoding; |
||
59 | |||
60 | return $this; |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * @param bool $useBom |
||
65 | * |
||
66 | * @return static |
||
67 | */ |
||
68 | public function setUseBom(bool $useBom): self |
||
69 | { |
||
70 | $this->useBom = $useBom; |
||
71 | |||
72 | return $this; |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * @param string $string |
||
77 | * |
||
78 | * @return string |
||
79 | */ |
||
80 | public function prependBom(string $string): string |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * release handle |
||
91 | * |
||
92 | * @return static |
||
93 | */ |
||
94 | public function releaseHandle(): self |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * @param resource|string $input |
||
107 | * @param string $mode |
||
108 | * |
||
109 | * @throws YaEtlException |
||
110 | * |
||
111 | * @return static |
||
112 | */ |
||
113 | protected function initHandle($input, string $mode): self |
||
127 | } |
||
128 | } |
||
129 |