GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

CsvFile::readFile()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 12
nc 4
nop 2
dl 0
loc 22
rs 9.8666
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the O2System Framework package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author         Steeve Andrian Salim
9
 * @copyright      Copyright (c) Steeve Andrian Salim
10
 */
11
12
// ------------------------------------------------------------------------
13
14
namespace O2System\Filesystem\Files;
15
16
// ------------------------------------------------------------------------
17
18
use O2System\Filesystem\File;
19
use O2System\Filesystem\Files\Abstracts\AbstractFile;
20
21
/**
22
 * Class CsvFile
23
 *
24
 * @package O2System\Filesystem\Factory
25
 */
26
class CsvFile extends AbstractFile
27
{
28
    /**
29
     * CsvFile::$fileExtension
30
     *
31
     * @var string
32
     */
33
    protected $fileExtension = '.csv';
34
35
    // ------------------------------------------------------------------------
36
37
    /**
38
     * CsvFile::readFile
39
     *
40
     * @param string $filePath Path to the file.
41
     * @param array  $options  Read file options.
42
     *
43
     * @return mixed
44
     */
45
    public function readFile($filePath = null, array $options = [])
46
    {
47
        $filePath = empty($filePath)
48
            ? $this->filePath
49
            : $filePath;
50
51
        $defaultOptions = [
52
            'length'    => 1000,
53
            'delimiter' => ',',
54
        ];
55
56
        $options = array_merge($defaultOptions, $options);
57
58
        $result = [];
59
60
        if (false !== ($handle = fopen($filePath, 'r'))) {
61
            while (false !== ($data = fgetcsv($handle, $options[ 'length' ], $options[ 'delimiter' ]))) {
0 ignored issues
show
Unused Code introduced by
The assignment to $data is dead and can be removed.
Loading history...
62
                $result[] = fgetcsv($handle);
63
            }
64
        }
65
66
        return $result;
67
    }
68
69
    // ------------------------------------------------------------------------
70
71
    /**
72
     * CsvFile::writeFile
73
     *
74
     * @param string $filePath Path to the file.
75
     * @param array  $options  Write file options.
76
     *
77
     * @return bool Returns TRUE on success or FALSE on failure.
78
     */
79
    public function writeFile($filePath = null, array $options = [])
80
    {
81
        $filePath = empty($filePath)
82
            ? $this->filePath
83
            : $filePath;
84
85
        $handle = (new File())->create($filePath);
86
87
        foreach ($this->getArrayCopy() as $key => $value) {
88
            if ( ! is_array($value)) {
89
                $list = [$key, $value];
90
            } else {
91
                $list = $value;
92
            }
93
            fputcsv($handle, $list);
94
        }
95
96
        return fclose($handle);
97
    }
98
}