Code Duplication    Length = 77-77 lines in 2 locations

php5/Objects/TmpObject.inc 1 location

@@ 30-106 (lines=77) @@
27
use \HOWI3\libhowi\Filesystem\Commons\TraitForResponse;
28
use \HOWI3\libhowi\Filesystem\php5\TraitForSharedMethods;
29
30
class TmpObject implements TmpInterface
31
{
32
    
33
    use TraitForResponse;
34
    use TraitForSharedMethods;
35
36
    private $tmp_path;
37
38
    /**
39
     *
40
     * {@inheritDoc}
41
     *
42
     */
43
    public function setTmp($path = false)
44
    {
45
        if (! empty($path)) {
46
            $tmp = $this->makeAbsolute($path);
47
            $isWritable = $this->isWritable($tmp);
48
            $this->tmp_path = $isWritable ? $tmp : $this->tmp_path;
49
            
50
            ! empty($isWritable) ? $this->debug(803) : $this->warning(501, $tmp);
51
            $this->response()->setStatus($isWritable);
52
        } else {
53
            $this->tmp_path = sys_get_temp_dir();
54
            
55
            $this->debug(804);
56
            $this->response()->setStatus(true);
57
            $isWritable = true;
58
        }
59
        return $isWritable;
60
    }
61
62
    /**
63
     *
64
     * {@inheritDoc}
65
     *
66
     */
67
    public function getTmp()
68
    {
69
        if (empty($this->tmp_path))
70
            $this->tmp_path = $this->setTmp();
71
        
72
        $this->debug(805, $this->tmp_path);
73
        $this->response()->setStatus(true);
74
        return $this->tmp_path;
75
    }
76
77
    /**
78
     *
79
     * {@inheritDoc}
80
     *
81
     */
82
    public function tempnam($dir = false, $prefix = 'howi-fs-tmp-')
83
    {
84
        $dir = empty($dir) ? $this->getTmp() : $this->makeAbsolute($dir);
85
        
86
        $tmpname = tempnam($dir, $prefix);
87
        
88
        $this->debug(806, $tmpname);
89
        $this->response()->setStatus(true);
90
        
91
        return $tmpname;
92
    }
93
94
    /**
95
     *
96
     * {@inheritDoc}
97
     *
98
     */
99
    public function tmpfile()
100
    {
101
        $this->debug(807);
102
        $tmpfie = tmpfile();
103
        $this->response()->setStatus(! empty($tmpfie) ? true : false);
104
        return $tmpfie;
105
    }
106
}
107

php7/Objects/TmpObject.inc 1 location

@@ 30-106 (lines=77) @@
27
use \HOWI3\libhowi\Filesystem\Commons\TraitForResponse;
28
use \HOWI3\libhowi\Filesystem\php7\TraitForSharedMethods;
29
30
class TmpObject implements TmpInterface
31
{
32
    
33
    use TraitForResponse;
34
    use TraitForSharedMethods;
35
36
    private $tmp_path;
37
38
    /**
39
     *
40
     * {@inheritDoc}
41
     *
42
     */
43
    public function setTmp($path = false)
44
    {
45
        if (! empty($path)) {
46
            $tmp = $this->makeAbsolute($path);
47
            $isWritable = $this->isWritable($tmp);
48
            $this->tmp_path = $isWritable ? $tmp : $this->tmp_path;
49
            
50
            ! empty($isWritable) ? $this->debug(803) : $this->warning(501, $tmp);
51
            $this->response()->setStatus($isWritable);
52
        } else {
53
            $this->tmp_path = sys_get_temp_dir();
54
            
55
            $this->debug(804);
56
            $this->response()->setStatus(true);
57
            $isWritable = true;
58
        }
59
        return $isWritable;
60
    }
61
62
    /**
63
     *
64
     * {@inheritDoc}
65
     *
66
     */
67
    public function getTmp()
68
    {
69
        if (empty($this->tmp_path))
70
            $this->tmp_path = $this->setTmp();
71
        
72
        $this->debug(805, $this->tmp_path);
73
        $this->response()->setStatus(true);
74
        return $this->tmp_path;
75
    }
76
77
    /**
78
     *
79
     * {@inheritDoc}
80
     *
81
     */
82
    public function tempnam($dir = false, $prefix = 'howi-fs-tmp-')
83
    {
84
        $dir = empty($dir) ? $this->getTmp() : $this->makeAbsolute($dir);
85
        
86
        $tmpname = tempnam($dir, $prefix);
87
        
88
        $this->debug(806, $tmpname);
89
        $this->response()->setStatus(true);
90
        
91
        return $tmpname;
92
    }
93
94
    /**
95
     *
96
     * {@inheritDoc}
97
     *
98
     */
99
    public function tmpfile()
100
    {
101
        $this->debug(807);
102
        $tmpfie = tmpfile();
103
        $this->response()->setStatus(! empty($tmpfie) ? true : false);
104
        return $tmpfie;
105
    }
106
}
107