Completed
Push — master ( 945442...621107 )
by Oscar
05:33
created

CsvTrait::supportsCsvEscapeChar()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 8
rs 9.4285
1
<?php
2
3
namespace Gettext\Utils;
4
5
use Gettext\Translations;
6
7
/*
8
 * Trait to provide the functionality of read/write csv.
9
 */
10
trait CsvTrait
11
{
12
    private static $csvEscapeChar;
13
14
    /**
15
     * Check whether support the escape_char argument to fgetcsv/fputcsv or not
16
     *
17
     * @return bool
18
     */
19
    private static function supportsCsvEscapeChar()
20
    {
21
        if (self::$csvEscapeChar === null) {
22
            self::$csvEscapeChar = version_compare(PHP_VERSION, '5.5.4') >= 0;
23
        }
24
25
        return self::$csvEscapeChar;
26
    }
27
28
    /**
29
     * @param resource $handle
30
     * @param array $options
31
     *
32
     * @return array
33
     */
34 View Code Duplication
    private static function fgetcsv($handle, $options)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
    {
36
        if (self::supportsCsvEscapeChar()) {
37
            return fgetcsv($handle, 0, $options['delimiter'], $options['enclosure'], $options['escape_char']);
38
        }
39
40
        return fgetcsv($handle, 0, $options['delimiter'], $options['enclosure']);
41
    }
42
43
    /**
44
     * @param resource $handle
45
     * @param array $fields
46
     * @param array $options
47
     *
48
     * @return bool|int
49
     */
50 View Code Duplication
    private static function fputcsv($handle, $fields, $options)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
    {
52
        if (self::supportsCsvEscapeChar()) {
53
            return fputcsv($handle, $fields, $options['delimiter'], $options['enclosure'], $options['escape_char']);
54
        }
55
56
        return fputcsv($handle, $fields, $options['delimiter'], $options['enclosure']);
57
    }
58
}
59