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

DestructibleString   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 33
ccs 13
cts 13
cp 1
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __destruct() 0 3 1
A __toString() 0 3 1
A __construct() 0 4 1
A rmDir() 0 5 1
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