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

DestructibleString   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

5 Methods

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