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.
Completed
Push — master ( 6d0cfa...78d09e )
by Denis
04:52
created

Writer   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 0
dl 0
loc 102
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 2
A write() 0 7 2
A purge() 0 7 2
A close() 0 8 2
A __destruct() 0 4 1
A fTell() 0 10 2
A fSeek() 0 10 2
1
<?php
2
namespace Ellumilel;
3
4
/**
5
 * Class Writer
6
 * @package xlsxWriter
7
 */
8
class Writer
9
{
10
    /** @var null|resource */
11
    protected $fd = null;
12
    /** @var string */
13
    protected $buffer = '';
14
    /** @var int */
15
    protected $bufferSize;
16
    /** @var bool */
17
    protected $check_utf8 = false;
18
19
    /**
20
     * Writer constructor.
21
     *
22
     * @param string $filename
23
     * @param string $openFlags
24
     * @param int $bufferSize
25
     *
26
     * @throws \Exception
27
     */
28
    public function __construct($filename, $openFlags = 'w', $bufferSize = 8191)
29
    {
30
        $this->fd = fopen($filename, $openFlags);
31
        $this->bufferSize = $bufferSize;
32
33
        if ($this->fd === false) {
34
            throw new \Exception("Unable to open $filename for writing.");
35
        }
36
    }
37
38
    /**
39
     * @param $string
40
     */
41
    public function write($string)
42
    {
43
        $this->buffer .= $string;
44
        if (isset($this->buffer[$this->bufferSize])) {
45
            $this->purge();
46
        }
47
    }
48
49
    /**
50
     * add to file
51
     */
52
    protected function purge()
53
    {
54
        if ($this->fd) {
55
            fwrite($this->fd, $this->buffer);
56
            $this->buffer = '';
57
        }
58
    }
59
60
    /**
61
     * close writing
62
     */
63
    public function close()
64
    {
65
        $this->purge();
66
        if ($this->fd) {
67
            fclose($this->fd);
68
            $this->fd = null;
69
        }
70
    }
71
72
    /**
73
     * close after end
74
     */
75
    public function __destruct()
76
    {
77
        $this->close();
78
    }
79
80
    /**
81
     * @return int
82
     */
83
    public function fTell()
84
    {
85
        if ($this->fd) {
86
            $this->purge();
87
88
            return ftell($this->fd);
89
        }
90
91
        return -1;
92
    }
93
94
    /**
95
     * @param $pos
96
     *
97
     * @return int
98
     */
99
    public function fSeek($pos)
100
    {
101
        if ($this->fd) {
102
            $this->purge();
103
104
            return fseek($this->fd, $pos);
105
        }
106
107
        return -1;
108
    }
109
}
110