ForFileProxy   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 10
c 0
b 0
f 0
ccs 6
cts 6
cp 1
wmc 3
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A generate() 0 6 2
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * This file is part of phpDocumentor.
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @author    Mike van Riel <[email protected]>
11
 * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
12
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
13
 * @link      http://phpdoc.org
14
 */
15
16
namespace phpDocumentor\Transformer\Router;
17
18
use phpDocumentor\Descriptor\DescriptorAbstract;
19
20
/**
21
 * Proxies a generated Routing Rule to generate physical filenames.
22
 *
23
 * By default a RoutingRule will generate a relative path on a webserver. This causes
24
 * issues between operating systems since Linux uses / and Windows \ as a directory
25
 * separator.
26
 *
27
 * To make sure that the correct file is generated can this proxy be used to generate
28
 * a filename instead of a webserver path.
29
 */
30
class ForFileProxy
31
{
32
    /** @var Rule $rule Contains the Routing Rule that is wrapped by this proxy */
33
    protected $rule;
34
35
    /**
36
     * Registers the Routing Rule that needs to be translated with this proxy.
37
     */
38 1
    public function __construct(Rule $rule)
39
    {
40 1
        $this->rule = $rule;
41 1
    }
42
43
    /**
44
     * Generates an URL for the given node.
45
     *
46
     * @param string|DescriptorAbstract $node               The node for which to generate an URL.
47
     * @param string                    $directorySeparator Which directory separator should be used to generate the
48
     *     paths with, defaults to the default separator for the current O/S.
49
     *
50
     * @return string|false a well-formed relative or absolute URL, or false if no URL could be generated.
51
     */
52 2
    public function generate($node, $directorySeparator = DIRECTORY_SEPARATOR)
53
    {
54 2
        $webserverPath = $this->rule->generate($node);
55
56 2
        return $webserverPath === false ? false : str_replace('/', $directorySeparator, $webserverPath);
57
    }
58
}
59