InfoCommands::info()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 9.488
c 0
b 0
f 0
cc 4
nc 6
nop 2
1
<?php
2
3
namespace VersionTool\Cli;
4
5
use VersionTool\VersionTool;
6
use Consolidation\OutputFormatters\StructuredData\RowsOfFields;
7
8
class InfoCommands extends \Robo\Tasks
9
{
10
    /**
11
     * Determine the application type and version of the specified
12
     * framework or frameworks.
13
     *
14
     * @command info
15
     * @field-labels
16
     *   application: Application
17
     *   version: Version
18
     *   path: Path
19
     * @default-fields application,version
20
     * @return \Consolidation\OutputFormatters\StructuredData\RowsOfFields
21
     */
22
    public function info(array $paths, $options = ['format' => 'tsv'])
0 ignored issues
show
Unused Code introduced by
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
23
    {
24
        if (empty($paths)) {
25
            $paths[] = getcwd();
26
        }
27
28
        $version_tool = new VersionTool();
29
30
        $result = [];
31
        foreach ($paths as $path) {
32
            $info = $version_tool->info($path);
33
34
            if (!$info) {
35
                throw new \Exception('Could not identify any application at path ' . $path);
36
            }
37
38
            $data = [
39
                'application' => $info->application(),
40
                'version' => $info->version(),
41
                'project-root' => $info->projectRoot(),
42
                'document-root' => $info->documentRoot(),
43
            ];
44
            $result[] = $data;
45
        }
46
47
        return new RowsOfFields($result);
48
    }
49
}
50