Completed
Push — master ( f97e7d...942adb )
by Aurimas
02:25
created

BaseStream::close()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2
Metric Value
dl 0
loc 13
ccs 8
cts 8
cp 1
rs 9.4286
cc 2
eloc 8
nc 2
nop 0
crap 2
1
<?php
2
3
namespace Thruster\Component\Stream;
4
5
use Thruster\Component\EventEmitter\EventEmitterTrait;
6
7
/**
8
 * Class BaseStream
9
 *
10
 * @package Thruster\Component\Stream
11
 * @author  Aurimas Niekis <[email protected]>
12
 */
13
class BaseStream implements StreamInterface
14
{
15
    use EventEmitterTrait;
16
    use UtilsTrait;
17
18
    /**
19
     * @var bool
20
     */
21
    protected $closed;
22
23
    /**
24
     * {@inheritDoc}
25
     */
26 10
    public function close() : self
27
    {
28 10
        if ($this->closed) {
29 6
            return $this;
30
        }
31
32 10
        $this->closed = true;
33 10
        $this->emit('end', [$this]);
34 10
        $this->emit('close', [$this]);
35 10
        $this->removeListeners();
36
37 10
        return $this;
38
    }
39
}
40