CsvExporter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 43
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A export() 0 15 2
1
<?php
2
/**
3
 * ZfDebugModule. WebUI and Console commands for debugging ZF2 apps.
4
 *
5
 * @license http://www.opensource.org/licenses/mit-license.html MIT License
6
 * @copyright 2016 Vítor Brandão <[email protected]>
7
 */
8
9
namespace Noiselabs\ZfDebugModule\Util\Routing;
10
11
use DateTime;
12
use Noiselabs\ZfDebugModule\Package;
13
14
class CsvExporter
15
{
16
    /**
17
     * @var RouteCollection
18
     */
19
    private $routeCollection;
20
21
    /**
22
     * @var string
23
     */
24
    private $outputDir;
25
26
    /**
27
     * CsvExporter constructor.
28
     *
29
     * @param RouteCollection $routeCollection
30
     * @param string          $outputDir
31
     */
32 2
    public function __construct(RouteCollection $routeCollection, $outputDir)
33
    {
34 2
        $this->routeCollection = $routeCollection;
35 2
        $this->outputDir = rtrim($outputDir, '/');
36 2
    }
37
38
    /**
39
     * @return string
40
     */
41 2
    public function export()
42
    {
43 2
        $datetime = DateTime::createFromFormat('U.u', microtime(true));
44 2
        $fileName = sprintf('%s/%s_routes_%s.csv', $this->outputDir, Package::NAME, $datetime->format('Ymd-His.u'));
45
46 2
        $fp = fopen($fileName, 'w');
47 2
        fputcsv($fp, ['Route name', 'URL', 'Controller', 'Action']);
48 2
        foreach ($this->routeCollection->getRoutes() as $route) {
49
            /* @var Route $route */
50 2
            fputcsv($fp, [$route->getName(), $route->getUrl(), $route->getController(), $route->getAction()]);
51
        }
52 2
        fclose($fp);
53
54 2
        return $fileName;
55
    }
56
}
57