ReadFile   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A readFile() 0 13 2
1
<?php
2
/*
3
 * This file is part of the phpflo/phpflo package.
4
 *
5
 * (c) Henri Bergius <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace PhpFlo\Component;
12
13
use PhpFlo\Component;
14
15
/**
16
 * Class ReadFile
17
 *
18
 * @package PhpFlo\Component
19
 * @author Henri Bergius <[email protected]>
20
 */
21
class ReadFile extends Component
22
{
23
    public function __construct()
24
    {
25
        $this->inPorts()->add('source', ['datatype' => 'string']);
26
        $this->outPorts()
27
            ->add('out', ['datatype' => 'string'])
28
            ->add('error', []); // use defaults, datatype = all
29
30
        $this->inPorts()->source->on('data', [$this, 'readFile']);
31
    }
32
33
    /**
34
     * @param string $data
35
     */
36
    public function readFile($data)
37
    {
38
        if (!file_exists($data)) {
39
            $this->outPorts()->error->send("File {$data} doesn't exist");
40
41
            return;
42
        }
43
44
        $this->outPorts()
45
            ->out
46
            ->send(file_get_contents($data))
47
            ->disconnect();
48
    }
49
}
50