Passed
Push — master ( bba5a4...181b61 )
by Tom
03:44
created

DestructibleString::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
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 2
    public function __construct($string, $callback)
28
    {
29 2
        $this->string = $string;
30 2
        $this->callback = $callback;
31 2
    }
32
33 2
    public function __destruct()
34
    {
35 2
        call_user_func($this->callback, $this->string);
36 2
    }
37
38 3
    public function __toString()
39
    {
40 3
        return $this->string;
41
    }
42
43 1
    public static function rmDir($string)
44
    {
45 1
        return new self(
46 1
            $string,
47 1
            'Ktomk\Pipelines\LibFs::rmDir'
48
        );
49
    }
50
}
51