Passed
Push — master ( 77a8ea...8a6a58 )
by Andrii
10:48
created

OutputDir   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 13
c 1
b 0
f 0
dl 0
loc 54
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getOutputPath() 0 3 1
A getOutputDir() 0 3 1
A findOutputDir() 0 9 2
A setOutputDir() 0 4 2
A path() 0 3 1
1
<?php
2
/**
3
 * Composer plugin for config assembling
4
 *
5
 * @link      https://github.com/hiqdev/composer-config-plugin
6
 * @package   composer-config-plugin
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2016-2018, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\composer\config;
12
13
/**
14
 * Output Dir class.
15
 *
16
 * @author Andrii Vasyliev <[email protected]>
17
 */
18
class OutputDir
19
{
20
    /**
21
     * @var string path to output assembled configs
22
     */
23
    protected $dir;
24
25
    public function __construct($outputDir = null)
26
    {
27
        $this->setOutputDir($outputDir);
28
29
    }
30
31
    public function setOutputDir($outputDir)
32
    {
33
        var_dump(__METHOD__, $outputDir);die;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
Security Debugging Code introduced by
var_dump(__METHOD__, $outputDir) looks like debug code. Are you sure you do not want to remove it?
Loading history...
34
        $this->outputDir = $outputDir ?: static::findOutputDir();
0 ignored issues
show
Unused Code introduced by
$this->outputDir = $outp...static::findOutputDir() is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
35
    }
36
37
    public function getOutputDir(): string
38
    {
39
        return $this->outputDir;
40
    }
41
42
    /**
43
     * Returns default output dir.
44
     * @param string $vendor path to vendor dir
45
     * @return string
46
     */
47
    public static function findOutputDir($vendor = null)
48
    {
49
        if ($vendor) {
50
            $dir = $vendor . '/hiqdev/' . basename(dirname(__DIR__));
51
        } else {
52
            $dir = \dirname(__DIR__);
53
        }
54
55
        return $dir . static::OUTPUT_DIR_SUFFIX;
0 ignored issues
show
Bug introduced by
The constant hiqdev\composer\config\O...tDir::OUTPUT_DIR_SUFFIX was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
56
    }
57
58
    /**
59
     * Returns full path to assembled config file.
60
     * @param string $filename name of config
61
     * @param string $vendor path to vendor dir
62
     * @return string absolute path
63
     */
64
    public static function path($filename, $vendor = null)
65
    {
66
        return static::findOutputDir($vendor) . DIRECTORY_SEPARATOR . $filename . '.php';
67
    }
68
69
    public function getOutputPath($name)
70
    {
71
        return $this->outputDir . DIRECTORY_SEPARATOR . $name . '.php';
72
    }
73
}
74