Passed
Push — master ( d64961...dc496c )
by Tom
04:20
created

DestructibleString::rm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
/* this file is part of pipelines */
4
5
namespace Ktomk\Pipelines;
6
7
/**
8
 * Class DestructibleString
9
 *
10
 * Representative String w/ lifetime. E.g. representing a path to a temporary
11
 * directory which is getting removed on destruction.
12
 *
13
 * @package Ktomk\Pipelines
14
 */
15
class DestructibleString
16
{
17
    /**
18
     * @var string
19
     */
20
    private $string;
21
22
    /**
23
     * @var callable
24
     */
25
    private $callback;
26
27
    /**
28
     * @see LibFs::rmDir
29
     *
30
     * @param string $string
31
     *
32
     * @return DestructibleString
33
     */
34 1
    public static function rmDir($string)
35
    {
36 1
        return new self(
37 1
            $string,
38 1
            'Ktomk\Pipelines\LibFs::rmDir'
39
        );
40
    }
41
42 1
    public static function rm($string)
43
    {
44 1
        return new self(
45 1
            $string,
46 1
            'Ktomk\Pipelines\LibFs::rm'
47
        );
48
    }
49
50
    /**
51
     * DestructibleString constructor.
52
     *
53
     * @param string $string
54
     * @param callable $callback
55
     */
56 3
    public function __construct($string, $callback)
57
    {
58 3
        $this->string = $string;
59 3
        $this->callback = $callback;
60 3
    }
61
62 3
    public function __destruct()
63
    {
64 3
        call_user_func($this->callback, $this->string);
65 3
    }
66
67 4
    public function __toString()
68
    {
69 4
        return $this->string;
70
    }
71
}
72