FileStream   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 5
c 1
b 0
f 0
dl 0
loc 19
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 3
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