ChainedMethod   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 34
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A exposeDirectory() 0 12 4
A __construct() 0 3 1
1
<?php
2
3
namespace SilverStripe\VendorPlugin\Methods;
4
5
use RuntimeException;
6
7
/**
8
 * Attempt a list of methods until failure.
9
 * Note: Only treates RuntimeException as retryable, and will fail on all other error
10
 */
11
class ChainedMethod implements ExposeMethod
12
{
13
    /**
14
     * @var ExposeMethod[]
15
     */
16
    protected $failovers = [];
17
18
    /**
19
     * @param ExposeMethod[] ...$failovers List of failovers
20
     */
21
    public function __construct(...$failovers)
22
    {
23
        $this->failovers = $failovers;
24
    }
25
26
    /**
27
     * Exposes the directory with the given paths
28
     *
29
     * @param string $source Full filesystem path to file source
30
     * @param string $target Full filesystem path to the target directory
31
     * @throws RuntimeException If could not be exposed
32
     */
33
    public function exposeDirectory($source, $target)
34
    {
35
        $lastException = null;
36
        foreach ($this->failovers as $failover) {
37
            try {
38
                $failover->exposeDirectory($source, $target);
39
                return; // Return on first success
40
            } catch (RuntimeException $lastException) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
41
            }
42
        }
43
        if ($lastException) {
44
            throw $lastException;
45
        }
46
    }
47
}
48