FileStream::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 9
rs 10
cc 3
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 (!filter_var($file, FILTER_VALIDATE_URL) && !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
}
41