Completed
Push — master ( 6b8416...c520c0 )
by Filipe
02:12
created

FileStream::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
/**
4
 * This file is part of slick/http
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Slick\Http\Message\Stream;
11
12
use Psr\Http\Message\StreamInterface;
13
use Slick\Http\Message\Exception\InvalidArgumentException;
14
15
/**
16
 * File Stream
17
 *
18
 * @package Slick\Http\Message\Stream
19
 */
20
class FileStream extends AbstractStream implements StreamInterface
21
{
22
23
    /**
24
     * Creates a File Stream
25
     *
26
     * @param string $file The file FQ name to create the stream from
27
     *
28
     * @throws InvalidArgumentException If provided file does not exists
29
     */
30
    public function __construct($file)
31
    {
32
        if (! is_file($file)) {
33
            throw new InvalidArgumentException(
34
                "Cannot create stream: given file is not found."
35
            );
36
        }
37
38
        $this->stream = fopen($file, 'r');
39
    }
40
}