PythonRunner   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A pythonGrabber() 0 4 1
A run() 0 18 3
1
<?php
2
3
namespace Rakshitbharat\Pythoninphp;
4
5
class PythonRunner
6
{
7
    public $file_path = '';
8
9
    public $out_put = '';
10
11
    public function pythonGrabber($pythonFilePathLaravelFormat)
12
    {
13
        $this->file_path = base_path() . DIRECTORY_SEPARATOR . $pythonFilePathLaravelFormat;
14
    }
15
16
    public function run()
17
    {
18
        if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
19
            $pythonPath = exec("where python");
20
        } else {
21
            $pythonPath = exec("which python");
22
        }
23
        $command = $pythonPath . " " . $this->file_path . " 2>&1";
24
        $pid = popen($command, "r");
25
        while (!feof($pid)) {
26
            $this->out_put .= fread($pid, 256);
27
            flush();
28
            ob_flush();
29
            usleep(100000);
30
        }
31
        pclose($pid);
32
        return $this->out_put;
33
    }
34
}
35